public void DollarSignsAndCaretsAreLiterals() { Glob glob = new Glob("abc$def^*"); Assert.IsTrue(glob.IsMatch("abc$def^")); Assert.IsTrue(glob.IsMatch("abc$def^Stuff")); Assert.IsFalse(glob.IsMatch("abc$")); }
public void DotsShouldBeLiterals() { Glob glob = new Glob("*.cs"); Assert.IsTrue(glob.IsMatch("someFile.cs")); Assert.IsFalse(glob.IsMatch("notmatchedcs")); }
public void ShouldMatchWithLeadingWildcard() { Glob glob = new Glob("*Class"); Assert.IsTrue(glob.IsMatch("MyClass")); Assert.IsTrue(glob.IsMatch("My.other.Class")); Assert.IsFalse(glob.IsMatch("MyClassAndMore2")); }
public void CanMatchSingleFileOnExtension() { var glob = new Glob("folder/*.txt"); Assert.True(glob.IsMatch("folder/bigfile.txt")); Assert.True(glob.IsMatch("folder/smallfile.txt")); Assert.False(glob.IsMatch("folder/smallfile.txt.min")); }
public void CanMatchSingleFileWithAnyNameOrExtension() { var glob = new Glob("folder/*.*"); Assert.True(glob.IsMatch("folder/bigfile.txt")); Assert.True(glob.IsMatch("folder/smallfile.txt")); Assert.True(glob.IsMatch("folder/smallfile.txt.min")); }
public void BracketsShouldMatchSingleCharacters() { Glob glob = new Glob("Test[0-9][0-9]"); Assert.IsTrue(glob.IsMatch("Test01")); Assert.IsTrue(glob.IsMatch("Test54")); Assert.IsFalse(glob.IsMatch("Test200")); }
public void ShouldMatchExactlyWhenNoWildcards() { Glob glob = new Glob("MyClass"); Assert.IsTrue(glob.IsMatch("MyClass")); Assert.IsFalse(glob.IsMatch("MyClass2")); Assert.IsFalse(glob.IsMatch("ReallyMyClass")); }
public void ShouldMatchWithTrailingWildcard() { Glob glob = new Glob("MyClass*"); Assert.IsTrue(glob.IsMatch("MyClass")); Assert.IsTrue(glob.IsMatch("MyClassAndMore2")); Assert.IsFalse(glob.IsMatch("ReallyMyClass")); }
public void CanMatchSingleFileUsingNumberRange() { var glob = new Glob("*file[1-9].txt"); Assert.True(glob.IsMatch("bigfile1.txt")); Assert.True(glob.IsMatch("smallfile8.txt")); Assert.False(glob.IsMatch("smallfile0.txt")); Assert.False(glob.IsMatch("smallfilea.txt")); }
public void CanMatchSingleFileUsingCharRange() { var glob = new Glob("*fil[e-z].txt"); Assert.True(glob.IsMatch("bigfile.txt")); Assert.True(glob.IsMatch("smallfilf.txt")); Assert.False(glob.IsMatch("smallfila.txt")); Assert.False(glob.IsMatch("smallfilez.txt")); }
public void CanMatchSingleFileUsingCharList() { var glob = new Glob("*file[abc].txt"); Assert.True(glob.IsMatch("bigfilea.txt")); Assert.True(glob.IsMatch("smallfileb.txt")); Assert.False(glob.IsMatch("smallfiled.txt")); Assert.False(glob.IsMatch("smallfileaa.txt")); }
public void QuestionMarksShouldMatchSingleCharacters() { Glob glob = new Glob("one??two"); Assert.IsTrue(glob.IsMatch("one00two")); Assert.IsTrue(glob.IsMatch("oneWEtwo")); Assert.IsFalse(glob.IsMatch("oneTooManytwo")); Assert.IsTrue(glob.IsMatch("one??two")); }
public void ShouldNotMatchCaseInsensitiveInSegment() { const string globPattern = @"taco"; var glob = new Glob(globPattern); Assert.False(glob.IsMatch("Taco")); Assert.False(glob.IsMatch("tAco")); Assert.False(glob.IsMatch("taCO")); }
public void QuestionMarksShouldMatchSingleCharacters() { Glob glob = new Glob("foo??bar"); Assert.IsTrue(glob.IsMatch("foo00bar")); Assert.IsTrue(glob.IsMatch("fooWEbar")); Assert.IsFalse(glob.IsMatch("fooTooManybar")); Assert.IsTrue(glob.IsMatch("foo??bar")); }
public void VerifyGlobEscape() { Glob g = Glob.Parse(@"\[[\[\ \]]"); Assert.True(g.IsMatch("[ ")); Assert.True(g.IsMatch("[]")); Assert.True(g.IsMatch("[[")); Assert.False(g.IsMatch("]")); }
public void ShouldNotMatchCaseInsensitiveInCharacterSet() { const string globPattern = @"[a-z]"; var glob = new Glob(globPattern); Assert.False(glob.IsMatch("A")); Assert.False(glob.IsMatch("B")); Assert.False(glob.IsMatch("Z")); }
public void VerifyGlobExactPathSpanning() { Glob g = Glob.Parse("a/**/b"); Assert.True(g.IsMatch("a/b")); Assert.True(g.IsMatch("a/x/b")); Assert.True(g.IsMatch("a/x/y/b")); Assert.False(g.IsMatch("z/a/x/y/b")); Assert.False(g.IsMatch("z/a/b")); }
public void Glob_AnotherWildcardMatch() { var glob = new Glob("**/AssemblyInfo.cs"); Assert.IsTrue(glob.IsMatch("./AssemblyInfo.cs")); Assert.IsTrue(glob.IsMatch("./Source/Bumpy/Properties/AssemblyInfo.cs")); Assert.IsFalse(glob.IsMatch("./FooAssemblyInfo.cs")); Assert.IsFalse(glob.IsMatch("./AssemblyInfo.cs.backup")); }
public void Glob_PreciseMatch() { var glob = new Glob("AssemblyInfo.cs"); Assert.IsTrue(glob.IsMatch("AssemblyInfo.cs")); Assert.IsTrue(glob.IsMatch("./Source/Bumpy/Properties/AssemblyInfo.cs")); Assert.IsTrue(glob.IsMatch("./FooAssemblyInfo.cs")); Assert.IsFalse(glob.IsMatch("./AssemblyInfo.cs.backup")); }
public void VerifyGlobCharacterGroups() { Glob g = Glob.Parse("f[Oo]o"); Assert.True(g.IsMatch("foo")); Assert.True(g.IsMatch("fOo")); Assert.True(g.IsMatch("a/foo")); Assert.True(g.IsMatch("z/a/x/y/fOo")); Assert.False(g.IsMatch("z/a/x/y/fOO")); }
public void Glob_WildcardMatch() { var glob = new Glob("**/Bumpy/**/AssemblyInfo.cs"); Assert.IsTrue(glob.IsMatch("./Source/Bumpy/Properties/AssemblyInfo.cs")); Assert.IsTrue(glob.IsMatch("./Bumpy/Properties/AssemblyInfo.cs")); Assert.IsTrue(glob.IsMatch("./Bumpy/AssemblyInfo.cs")); Assert.IsFalse(glob.IsMatch("./Source/Bumpy.Test/Properties/AssemblyInfo.cs")); Assert.IsFalse(glob.IsMatch("./Bumpy.Test/Properties/AssemblyInfo.cs")); }
/// <summary> /// Check to see if the given method matches the name and signature. /// </summary> /// <param name="member">Member to check.</param> /// <returns>True if match, false if not.</returns> public bool Matches(MethodBase member) { Guard.ArgumentNotNull(member, "member"); if (!_methodNamePattern.IsMatch(member.Name)) { return(false); } ParameterInfo[] parameters = member.GetParameters(); if (parameters.Length != _parameterRules.Count) { return(false); } for (int i = 0; i < parameters.Length; ++i) { if (!_parameterRules[i].Matches(parameters[i].ParameterType)) { return(false); } } return(true); }
public void TestInputWithSpace() { var pattern = "Microsoft Visual Studio/2017"; var expectedMatch = @"Microsoft Visual Studio\2017"; Assert.True(Glob.IsMatch(pattern, expectedMatch)); }
public void CanMatchParensAndEqual() { // Issue https://github.com/kthompson/glob/issues/57 var glob = new Glob(@"a\abc(v=ws.10).md", GlobOptions.CaseInsensitive); Assert.True(glob.IsMatch(@"a\abc(v=ws.10).md")); }
public void ShouldNotMatchLiteralSet() { const string globPattern = @"{ab,cd}"; var glob = new Glob(globPattern, GlobOptions.CaseInsensitive); Assert.False(glob.IsMatch("dc")); }
public void TestEscapeSequenceWithSpaces() { var pattern = @"Generated\ Files/"; var expectedMatch = "Generated Files"; Assert.True(Glob.IsMatch(pattern, expectedMatch)); }
public void CanMatchDirectoryWildcardInTopLevelDirectory() { const string globPattern = @"/**/somefile"; var glob = new Glob(globPattern); Assert.True(glob.IsMatch("/somefile")); }
private bool IsFilterRuleValidationPassed(FileSystemInfo sysInfo, out String hitFilterRule) { String relativePath = sysInfo.FullName.Replace(FolderFilterRuleObj.TargetFolderPath, "").Trim(); //exclude unwanted files foreach (String filter in FolderFilterRuleObj.ExcludeFilterRules) { bool match = Glob.IsMatch(relativePath, filter); if (match) { hitFilterRule = filter; return(false); } } //include wanted files foreach (String filter in FolderFilterRuleObj.IncludeFilterRules) { bool match = Glob.IsMatch(relativePath, filter); if (match) { hitFilterRule = filter; return(true); } } hitFilterRule = String.Empty; return(false); }
public void FullPathOptionTests(string pattern, string matches, string nonMatches = null) { var glob = new Glob(pattern, GlobOptions.MatchFullPath); foreach (var expectedMatch in matches.Split(' ')) { Assert.True(glob.IsMatch(expectedMatch)); } if (nonMatches != null) { foreach (var expectedMatch in nonMatches.Split(' ')) { Assert.False(glob.IsMatch(expectedMatch)); } } }
static bool ShouldUnpack(string path) { if (sUnpackFilterGlob == null) { return(true); } return(sUnpackFilterGlob.IsMatch(path)); }
public void Test() { Assert.IsTrue(Glob.IsMatch("som/folder/bin/SomeFoo.txt", "**/bin/**/*")); Assert.IsTrue(Glob.IsMatch("GitMind\\Dependencies\\Autofac.dllt", "GitMind/Dependencies/**/*")); //Assert.IsTrue(Glob.IsMatch("som/folder/bin/SomeFoo.txt", "**/[Dd]ebug//**/*")); }
public bool IsMatchedBy(string expected) { return (Glob.IsMatch(expected, _inclusionPattern) && _exclusionPattern.Select( exclusion => !Glob.IsMatch(expected, exclusion)) .OrElse(() => true)); }
public void IsMatchCaseInsensitive(string pattern, params string[] testStrings) { var glob = new Glob(pattern); foreach (string testString in testStrings) { Assert.IsTrue(glob.IsMatch(testString)); } }
[TestCase("range/[a-b][C-D]", false, "range/ac", "range/Ad", "range/BD")] // Regression tests for https://github.com/dazinator/DotNet.Glob/issues/41 public void Does_Not_Match(string pattern, bool allowInvalidPathCharcters, params string[] testStrings) { var glob = new Glob(pattern); foreach (string testString in testStrings) { Assert.IsFalse(glob.IsMatch(testString)); } }
public void CaseInsensitiveTests(string pattern, string matches) { var glob = new Glob(pattern, GlobOptions.CaseInsensitive); foreach (var expectedMatch in matches.Split(' ')) { Assert.True(glob.IsMatch(expectedMatch)); } }
/// <summary> /// 检查文件/夹路径是否与规则模式匹配 /// </summary> public bool IsMatch(string fullPath) { if (fullPath.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(fullPath)); } var path = fullPath.NormalizedPath() .RemovePreFix(_stringComparison, BasePath) .TrimEnd('/'); if (path.IsNullOrEmpty()) { return(false); } // 如果 OriginalPattern 是以反斜杠(/)开头(PatternMeanings.StartsWithOfPath), // 意味着要匹配的路径必须跟第一个通配符之前的字符串匹配 if (_meanings.HasFlag(PatternMeanings.StartsWithOfPath)) { var firstWildcardIndex = _analyzedPattern.IndexOfAny(_globWildcards); var prePattern = firstWildcardIndex != -1 ? _analyzedPattern.Left(firstWildcardIndex) : _analyzedPattern; if (!path.StartsWith(prePattern, _stringComparison)) { return(false); } } /* 如果到目前为止,我们还不能通过简单的字符串匹配来确定结果, 那么只能其它方式解析 Glob 表达式了。这里使用的是:DotNet.Glob [https://github.com/dazinator/DotNet.Glob] */ // 如果 _analyzedPattern 不再包含任何斜杠,意味着它可以匹配任何路径段 // 如:'*.jpg' 可以匹配 'a.jpg', 'a/b.jpg', 'a/b/c.jpg' // 所以,path 中的每个斜杠前的字符串都应该尝试匹配一下 if (!_analyzedPattern.Contains("/") && path.Contains("/")) { return(path.Split('/').Any(segment => _glob.IsMatch(segment))); } // 其它情况直接解析 return(_glob.IsMatch(path)); }
public void NonMatchingRange_WildCardMatchesDirectorySeparator(string pattern, char[] nonMatchingChars) { for (int i = 0; i < 255; i++) { var c = (char)i; bool shouldMatch = Array.IndexOf(nonMatchingChars, c) < 0; Assert.True(shouldMatch == Glob.IsMatch(pattern, c.ToString(), ignoreCase: false, matchWildCardWithDirectorySeparator: true), $"character: '{(i != 0 ? c.ToString() : "\\0")}' (0x{i:X2})"); } }
// Escape sequences //[InlineData(@"\[a-d\]", "[a-d]", @"b c \ [ ]")] //[InlineData(@"\{ab,bc\}", "{ab,bc}", @"ab bc")] //[InlineData(@"hat\?", "hat?", "hata hatb")] //[InlineData(@"hat\*", "hat*", "hata hatb hat hat/taco hata/taco")] public void TestGlobExpressions(string pattern, string positiveMatch, string negativeMatch = null) { var glob = new Glob(pattern); if (positiveMatch != null) { foreach (var match in positiveMatch.Split(' ')) { Assert.True(glob.IsMatch(match)); } } if (negativeMatch != null) { foreach (var match in negativeMatch.Split(' ')) { Assert.False(glob.IsMatch(match)); } } }
public void ShouldMatchNothingWithEmptyPattern() { Glob glob = new Glob(string.Empty); Assert.IsFalse(glob.IsMatch("a")); }
private IEnumerable<string> GetRegexForGlobPattern(string pattern) { var glob = new Glob(pattern, GlobOptions.Compiled); return filenames.Where(filename => glob.IsMatch(filename)); }
public void CanParseSimpleFilename() { var glob = new Glob("*.txt"); Assert.True(glob.IsMatch("file.txt")); Assert.False(glob.IsMatch("file.zip")); Assert.True(glob.IsMatch(@"c:\windows\file.txt")); }
public void ShouldBeCaseSensitiveByDefault() { Glob glob = new Glob("MyClass"); Assert.IsFalse(glob.IsMatch("myclass")); }
public void ShouldMatchWithCaseInsensitiveFlag() { Glob glob = new Glob("MyClass", false); Assert.IsTrue(glob.IsMatch("myclass")); }
public void CanParseDots() { var glob = new Glob("/some/dir/folder/foo.*"); Assert.True(glob.IsMatch("/some/dir/folder/foo.txt")); Assert.True(glob.IsMatch("/some/dir/folder/foo.csv")); }
public void CanMatchSingleFile() { var glob = new Glob("*file.txt"); Assert.True(glob.IsMatch("bigfile.txt")); Assert.True(glob.IsMatch("smallfile.txt")); }