diff --git a/src/DotNet.Glob.Benchmarks/project.json b/src/DotNet.Glob.Benchmarks/project.json index a2e211c..93ba30a 100644 --- a/src/DotNet.Glob.Benchmarks/project.json +++ b/src/DotNet.Glob.Benchmarks/project.json @@ -7,8 +7,8 @@ "dependencies": { "NETStandard.Library": "1.6.1", "DotNet.Glob": "1.0.0-*", - "Glob": "0.3.1", - "BenchmarkDotNet": "0.10.1" + "Glob": "0.3.2", + "BenchmarkDotNet": "0.10.3" }, "frameworks": { "netcoreapp1.1": { diff --git a/src/DotNet.Glob.Tests/GlobTests.cs b/src/DotNet.Glob.Tests/GlobTests.cs index 9797bd7..53f7372 100644 --- a/src/DotNet.Glob.Tests/GlobTests.cs +++ b/src/DotNet.Glob.Tests/GlobTests.cs @@ -45,25 +45,20 @@ public void Does_Not_Match(string pattern, params string[] testStrings) [InlineData("/**/file.*", "/file.txt")] [InlineData("**/file.*", "/file.txt")] [InlineData("/*file.txt", "/file.txt")] - public void Can_IsMatch(string pattern, params string[] testStrings) + [InlineData("C:\\THIS_IS_A_DIR\\*", "C:\\THIS_IS_A_DIR\\somefile")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/20 + [InlineData("/DIR1/*/*", "/DIR1/DIR2/file.txt")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/21 + [InlineData("~/*~3", "~/abc123~3")] // Regression Test for https://github.com/dazinator/DotNet.Glob/pull/15 + public void IsMatch(string pattern, params string[] testStrings) { var glob = Glob.Parse(pattern); foreach (var testString in testStrings) { var match = glob.IsMatch(testString); - Assert.True(match); + Assert.True(match); + } } - - [Fact] - public void To_String_Returns_Pattern() - { - var pattern = "p?th/*a[bcd]b[e-g]/**/a[1-4][!wxyz][!a-c][!1-3].*"; - var glob = Glob.Parse(pattern); - var resultPattern = glob.ToString(); - Assert.Equal(pattern, resultPattern); - } - + [Theory] [InlineData("literal", "literal")] [InlineData("a/literal", "a/literal")] @@ -78,47 +73,36 @@ public void To_String_Returns_Pattern() [InlineData("path/**/somefile.txt", "path/foo/bar/baz/somefile.txt")] [InlineData("p?th/*a[bcd]b[e-g]a[1-4][!wxyz][!a-c][!1-3].*", "pGth/yGKNY6acbea3rm8.")] [InlineData("/**/file.*", "/folder/file.csv")] - //[InlineData("/**/file.*", "/file.txt")] - //[InlineData("**/file.*", "/file.txt")] - //[InlineData("/**/file.*", "/file.txt")] - //[InlineData("/**/f~le.*", "/f~le.txt")] - public void Glob_IsMatch(string pattern, params string[] testStrings) + [InlineData("/**/file.*", "/file.txt")] + [InlineData("/**/file.*", "/file.txt")] + [InlineData("**/file.*", "/file.txt")] + [InlineData("/*file.txt", "/file.txt")] + [InlineData("C:\\THIS_IS_A_DIR\\*", "C:\\THIS_IS_A_DIR\\somefile")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/20 + [InlineData("/DIR1/*/*", "/DIR1/DIR2/file.txt")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/21 + [InlineData("~/*~3", "~/abc123~3")] // Regression Test for https://github.com/dazinator/DotNet.Glob/pull/15 + public void Match(string pattern, params string[] testStrings) { - // This is a different glob library, I am seeing if it matches the same patterns as my library. - // The tests above commented out show it has some limitations, that I have addressed in this library. - var glob = new global::Glob.Glob(pattern); + var glob = Glob.Parse(pattern); foreach (var testString in testStrings) { - var match = glob.IsMatch(testString); - Assert.True(match); + var match = glob.Match(testString); + Assert.True(match.Success); } } - - /// - /// Regression Test for https://github.com/dazinator/DotNet.Glob/pull/15 - /// [Fact] - public void BugFix_Can_Read_Tilde() + public void To_String_Returns_Pattern() { - // This is a different glob library, I am seeing if it matches the same patterns as my library. - // The three tests above commented out show it currently has some limitations, that this library doesn't. - var glob = Glob.Parse("~/*~3"); - var isMatch = glob.IsMatch("~/abc123~3"); - Assert.True(isMatch); - } + var pattern = "p?th/*a[bcd]b[e-g]/**/a[1-4][!wxyz][!a-c][!1-3].*"; + var glob = Glob.Parse(pattern); + var resultPattern = glob.ToString(); + Assert.Equal(pattern, resultPattern); + } - /// - /// Regression Test for https://github.com/dazinator/DotNet.Glob/pull/15 - /// - [Fact] - public void BugFix_Issue_20_Can_Read_Colon_And_Underscore() - { - // This is a different glob library, I am seeing if it matches the same patterns as my library. - // The three tests above commented out show it currently has some limitations, that this library doesn't. - var glob = Glob.Parse("C:\\THIS_IS_A_DIR\\*"); - var isMatch = glob.IsMatch("C:\\THIS_IS_A_DIR\\somefile"); - Assert.True(isMatch); - } + + + + + } } diff --git a/src/DotNet.Glob.Tests/OtherGlobLibraryTests.cs b/src/DotNet.Glob.Tests/OtherGlobLibraryTests.cs new file mode 100644 index 0000000..e653bb7 --- /dev/null +++ b/src/DotNet.Glob.Tests/OtherGlobLibraryTests.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace DotNet.Globbing.Tests +{ + public class OtherGlobLibraryTests + { + + [Theory] + [InlineData("literal", "literal")] + [InlineData("a/literal", "a/literal")] + [InlineData("path/*atstand", "path/fooatstand")] + [InlineData("path/hats*nd", "path/hatsforstand")] + [InlineData("path/?atstand", "path/hatstand")] + [InlineData("path/?atstand?", "path/hatstands")] + [InlineData("p?th/*a[bcd]", "pAth/fooooac")] + [InlineData("p?th/*a[bcd]b[e-g]a[1-4]", "pAth/fooooacbfa2")] + [InlineData("p?th/*a[bcd]b[e-g]a[1-4][!wxyz]", "pAth/fooooacbfa2v")] + [InlineData("p?th/*a[bcd]b[e-g]a[1-4][!wxyz][!a-c][!1-3].*", "pAth/fooooacbfa2vd4.txt")] + [InlineData("path/**/somefile.txt", "path/foo/bar/baz/somefile.txt")] + [InlineData("p?th/*a[bcd]b[e-g]a[1-4][!wxyz][!a-c][!1-3].*", "pGth/yGKNY6acbea3rm8.")] + [InlineData("/**/file.*", "/folder/file.csv")] + //[InlineData("/**/file.*", "/file.txt")] + //[InlineData("**/file.*", "/file.txt")] + //[InlineData("/**/file.*", "/file.txt")] + //[InlineData("/**/f~le.*", "/f~le.txt")] + public void Glob_IsMatch(string pattern, params string[] testStrings) + { + // This is a different glob library, I am seeing if it matches the same patterns as my library. + // The tests above commented out show it has some limitations, that I have addressed in this library. + var glob = new global::Glob.Glob(pattern); + foreach (var testString in testStrings) + { + var match = glob.IsMatch(testString); + Assert.True(match); + } + } + } +} diff --git a/src/DotNet.Glob.Tests/project.json b/src/DotNet.Glob.Tests/project.json index 257b093..731f812 100644 --- a/src/DotNet.Glob.Tests/project.json +++ b/src/DotNet.Glob.Tests/project.json @@ -5,9 +5,9 @@ "dependencies": { "NETStandard.Library": "1.6.0", "dotnet-test-xunit": "2.2.0-*", - "xunit": "2.2.0-beta4-build3444", + "xunit": "2.2.0", "DotNet.Glob": "1.0.0-*", - "Glob": "0.3.1" + "Glob": "0.3.2" }, "frameworks": { "netcoreapp1.0": { diff --git a/src/DotNet.Glob/Evaluation/GlobTokenMatchAnalysisEvaluator.cs b/src/DotNet.Glob/Evaluation/GlobTokenMatchAnalysisEvaluator.cs index 112d35b..3486c7f 100644 --- a/src/DotNet.Glob/Evaluation/GlobTokenMatchAnalysisEvaluator.cs +++ b/src/DotNet.Glob/Evaluation/GlobTokenMatchAnalysisEvaluator.cs @@ -180,7 +180,7 @@ public void Visit(WildcardToken token) var bestMatchText = new StringBuilder(endOfSegmentPos); IList bestMatches = null; // the most tokens that were matched. - for (int i = 0; i < endOfSegmentPos; i++) + for (int i = 0; i <= endOfSegmentPos; i++) { var matchInfo = nestedEval.Evaluate(remainingText); if (matchInfo.Success) diff --git a/src/DotNet.Glob/Evaluation/WildcardTokenEvaluator.cs b/src/DotNet.Glob/Evaluation/WildcardTokenEvaluator.cs index b870333..1ad6526 100644 --- a/src/DotNet.Glob/Evaluation/WildcardTokenEvaluator.cs +++ b/src/DotNet.Glob/Evaluation/WildcardTokenEvaluator.cs @@ -80,10 +80,7 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition) for (int i = currentPosition; i <= maxPos; i++) { var currentChar = allChars[i]; - if (currentChar == '/' || currentChar == '\\') - { - return false; - } + //int newSubPosition; @@ -92,6 +89,11 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition) { return true; } + + if (currentChar == '/' || currentChar == '\\') + { + return false; + } } return false; diff --git a/src/DotNet.Glob/project.json b/src/DotNet.Glob/project.json index 7cb81aa..0ee0748 100644 --- a/src/DotNet.Glob/project.json +++ b/src/DotNet.Glob/project.json @@ -45,7 +45,7 @@ }, "net46": { "dependencies": { - "System.IO": "4.0.10.0", + "System.IO": "4.0.10", "System.Runtime.Extensions": "4.3.0" } }