Skip to content

Commit

Permalink
Merge branch 'release/6.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
augustoproiete committed Feb 21, 2023
2 parents 7962e55 + ead9d86 commit 66cfcdb
Show file tree
Hide file tree
Showing 7 changed files with 528 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-18.04, macos-latest]
os: [windows-2022, ubuntu-20.04, macos-12]

env:
AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

strategy:
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-cake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
dependabot-cake:
runs-on: ubuntu-18.04 # linux, because this is a docker-action
runs-on: ubuntu-20.04 # linux, because this is a docker-action
steps:
- name: check/update cake dependencies
uses: nils-org/dependabot-cake-action@v1
2 changes: 1 addition & 1 deletion .github/workflows/publishDocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:

jobs:
cake:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

steps:
- name: checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
draft-stable:
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

steps:
- name: Checkout the requested branch
Expand Down
110 changes: 110 additions & 0 deletions src/Cake.FileHelpers.Tests/FileHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Cake.Xamarin.Tests.Fakes;
using Cake.Core.IO;
using Xunit;
using System.Text;

namespace Cake.FileHelpers.Tests
{
Expand Down Expand Up @@ -82,6 +83,17 @@ public void FindTextInFiles()
Assert.Single (monkeyFiles);
}

[Fact]
public void FindTextInFilesWithUTF8Encoding()
{
SetupFilesUTF8();

var files = context.CakeContext.FindTextInFiles("./testdata/*-utf8.txt", Encoding.UTF8, "Monkey🐒");

Assert.NotNull(files);
Assert.Single(files);
}

[Fact]
public void FindRegexInFiles()
{
Expand All @@ -93,6 +105,16 @@ public void FindRegexInFiles()
Assert.Single (files);
}

[Fact]
public void FindRegexInFilesWithUTF8Encoding()
{
SetupFilesUTF8();

var files = context.CakeContext.FindRegexInFiles("./testdata/*-utf8.txt", Encoding.UTF8, @"\s{1}Monkey🐒\s{1,}");

Assert.NotNull(files);
Assert.Single(files);
}

[Fact]
public void ReplaceTextInFiles()
Expand All @@ -110,6 +132,23 @@ public void ReplaceTextInFiles()
}
}

[Fact]
public void ReplaceTextInFilesWithUTF8Encoding()
{
SetupFilesUTF8();

var files = context.CakeContext.ReplaceTextInFiles("./testdata/*.txt", Encoding.UTF8, "Monkey🐒", "Tamarin");

Assert.NotNull(files);
Assert.Single(files);

foreach (var f in files)
{
var contents = context.CakeContext.FileReadText(f, Encoding.UTF8);
Assert.Equal(string.Format(PATTERN_FILE_BASE_VALUE, "Tamarin"), contents);
}
}

[Fact]
public void ReplaceRegexInFiles()
{
Expand All @@ -126,9 +165,29 @@ public void ReplaceRegexInFiles()
}
}

[Fact]
public void ReplaceRegexInFilesWithUTF8Encoding()
{
SetupFilesUTF8();

var files = context.CakeContext.ReplaceRegexInFiles("./testdata/*-utf8.txt", Encoding.UTF8, @"\s{1}Monkey🐒\s{1,}", " Tamarin ");

Assert.NotNull(files);
Assert.Single(files);

foreach (var f in files)
{
var contents = context.CakeContext.FileReadText(f, Encoding.UTF8);
Assert.Equal(string.Format(PATTERN_FILE_BASE_VALUE, "Tamarin"), contents);
}
}

public const string GROUPS_FILE = "./testdata/Groups.txt";
public const string GROUPS_FILE_UTF8 = "./testdata/Groups-utf8.txt";
public const string GROUPS_FILE_CONTENT = "Hello World! This is A quick Test to Capture multiple Groups.";
public const string GROUPS_FILE_CONTENT_UTF8 = "🐒Hello 🐒World! 🐒This is A quick 🐒Test to 🐒Capture multiple 🐒Groups.";
public const string GROUPS_PATTERN = "([A-Z])(\\w+)";
public const string GROUPS_PATTERN_UTF8 = "(🐒[A-Z])(\\w+)";

[Fact]
public void FindRegexMatchesGroupsInFile()
Expand All @@ -144,6 +203,20 @@ public void FindRegexMatchesGroupsInFile()
Assert.Equal (3, g.Count);
}

[Fact]
public void FindRegexMatchesGroupsInFileWithUTF8Encoding()
{
context.CakeContext.FileWriteText(GROUPS_FILE_UTF8, GROUPS_FILE_CONTENT_UTF8);

var matchesGroups = context.CakeContext.FindRegexMatchesGroupsInFile(GROUPS_FILE_UTF8, GROUPS_PATTERN_UTF8, RegexOptions.None);

Assert.NotNull(matchesGroups);
Assert.Equal(6, matchesGroups.Count);

foreach (var g in matchesGroups)
Assert.Equal(3, g.Count);
}

[Fact]
public void FindRegexMatchGroupsInFile()
{
Expand All @@ -155,6 +228,18 @@ public void FindRegexMatchGroupsInFile()
Assert.Equal (3, matchGroups.Count);
}


[Fact]
public void FindRegexMatchGroupsInFileWithUTF8Encoding()
{
context.CakeContext.FileWriteText(GROUPS_FILE_UTF8, GROUPS_FILE_CONTENT_UTF8);

var matchGroups = context.CakeContext.FindRegexMatchGroupsInFile(GROUPS_FILE_UTF8, GROUPS_PATTERN_UTF8, RegexOptions.None);

Assert.NotNull(matchGroups);
Assert.Equal(3, matchGroups.Count);
}

[Fact]
public void FindRegexMatchGroupInFile()
{
Expand All @@ -168,6 +253,19 @@ public void FindRegexMatchGroupInFile()
Assert.Equal ("ello", matchGroup.Value);
}

[Fact]
public void FindRegexMatchGroupInFileWithUTF8Encoding()
{
context.CakeContext.FileWriteText(GROUPS_FILE_UTF8, GROUPS_FILE_CONTENT_UTF8);

var matchGroup = context.CakeContext.FindRegexMatchGroupInFile(GROUPS_FILE_UTF8, GROUPS_PATTERN_UTF8, 2, RegexOptions.None);
var invalidMatchGroup = context.CakeContext.FindRegexMatchGroupInFile(GROUPS_FILE_UTF8, GROUPS_PATTERN_UTF8, 8, RegexOptions.None);

Assert.NotNull(matchGroup);
Assert.Null(invalidMatchGroup);
Assert.Equal("ello", matchGroup.Value);
}

public const string PATTERN_FILE_BASE_VALUE = "The {0} makes great software.\nThis is not a surprise.";

void SetupFiles()
Expand All @@ -179,6 +277,18 @@ void SetupFiles()
string.Format (PATTERN_FILE_BASE_VALUE, i == 2 ? "Monkey" : "Ape"));
}
}

void SetupFilesUTF8()
{
// Setup files
for (int i = 1; i < 5; i++)
{
context.CakeContext.FileWriteText(
string.Format("./testdata/{0}-utf8.txt", i),
Encoding.UTF8,
string.Format(PATTERN_FILE_BASE_VALUE, i == 2 ? "Monkey🐒" : "Ape🦧"));
}
}
}
}

Loading

0 comments on commit 66cfcdb

Please sign in to comment.