示例#1
0
 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$"));
 }
示例#2
0
        public void DotsShouldBeLiterals()
        {
            Glob glob = new Glob("*.cs");

            Assert.IsTrue(glob.IsMatch("someFile.cs"));
            Assert.IsFalse(glob.IsMatch("notmatchedcs"));
        }
示例#3
0
 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"));
 }
示例#4
0
 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"));
 }
示例#5
0
 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"));
 }
示例#6
0
 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"));
 }
示例#7
0
 public void ShouldMatchExactlyWhenNoWildcards()
 {
     Glob glob = new Glob("MyClass");
     Assert.IsTrue(glob.IsMatch("MyClass"));
     Assert.IsFalse(glob.IsMatch("MyClass2"));
     Assert.IsFalse(glob.IsMatch("ReallyMyClass"));
 }
示例#8
0
 public void ShouldMatchWithTrailingWildcard()
 {
     Glob glob = new Glob("MyClass*");
     Assert.IsTrue(glob.IsMatch("MyClass"));
     Assert.IsTrue(glob.IsMatch("MyClassAndMore2"));
     Assert.IsFalse(glob.IsMatch("ReallyMyClass"));
 }
示例#9
0
 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"));
 }
示例#10
0
 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"));
 }
示例#11
0
 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"));
 }
示例#12
0
        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"));
        }
示例#13
0
        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"));
        }
示例#14
0
        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"));
        }
示例#15
0
        public void VerifyGlobEscape()
        {
            Glob g = Glob.Parse(@"\[[\[\ \]]");

            Assert.True(g.IsMatch("[ "));
            Assert.True(g.IsMatch("[]"));
            Assert.True(g.IsMatch("[["));
            Assert.False(g.IsMatch("]"));
        }
示例#16
0
        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"));
        }
示例#17
0
        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"));
        }
示例#18
0
        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"));
        }
示例#19
0
        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"));
        }
示例#20
0
        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"));
        }
示例#21
0
        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"));
        }
示例#22
0
        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"));
        }
示例#23
0
        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"));
        }
示例#24
0
        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"));
        }
示例#25
0
        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"));
        }
示例#26
0
        /// <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);
        }
示例#27
0
        public void TestInputWithSpace()
        {
            var pattern       = "Microsoft Visual Studio/2017";
            var expectedMatch = @"Microsoft Visual Studio\2017";

            Assert.True(Glob.IsMatch(pattern, expectedMatch));
        }
示例#28
0
        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"));
        }
示例#29
0
        public void ShouldNotMatchLiteralSet()
        {
            const string globPattern = @"{ab,cd}";
            var          glob        = new Glob(globPattern, GlobOptions.CaseInsensitive);

            Assert.False(glob.IsMatch("dc"));
        }
示例#30
0
        public void TestEscapeSequenceWithSpaces()
        {
            var pattern       = @"Generated\ Files/";
            var expectedMatch = "Generated Files";

            Assert.True(Glob.IsMatch(pattern, expectedMatch));
        }
示例#31
0
        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);
        }
示例#33
0
        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));
                }
            }
        }
示例#34
0
 static bool ShouldUnpack(string path)
 {
     if (sUnpackFilterGlob == null)
     {
         return(true);
     }
     return(sUnpackFilterGlob.IsMatch(path));
 }
示例#35
0
        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//**/*"));
        }
示例#36
0
 public bool IsMatchedBy(string expected)
 {
     return
         (Glob.IsMatch(expected, _inclusionPattern) &&
          _exclusionPattern.Select(
              exclusion => !Glob.IsMatch(expected, exclusion))
          .OrElse(() => true));
 }
示例#37
0
        public void IsMatchCaseInsensitive(string pattern, params string[] testStrings)
        {
            var glob = new Glob(pattern);

            foreach (string testString in testStrings)
            {
                Assert.IsTrue(glob.IsMatch(testString));
            }
        }
示例#38
0
        [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));
            }
        }
示例#39
0
        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));
            }
        }
示例#40
0
        /// <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));
        }
示例#41
0
 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})");
     }
 }
示例#42
0
        // 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));
                }
            }
        }
示例#43
0
 public void ShouldMatchNothingWithEmptyPattern()
 {
     Glob glob = new Glob(string.Empty);
     Assert.IsFalse(glob.IsMatch("a"));
 }
示例#44
0
        private IEnumerable<string> GetRegexForGlobPattern(string pattern)
        {
            var glob = new Glob(pattern, GlobOptions.Compiled);

            return filenames.Where(filename => glob.IsMatch(filename));
        }
示例#45
0
 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"));
 }
示例#46
0
 public void ShouldBeCaseSensitiveByDefault()
 {
     Glob glob = new Glob("MyClass");
     Assert.IsFalse(glob.IsMatch("myclass"));
 }
示例#47
0
        public void ShouldMatchWithCaseInsensitiveFlag()
        {
            Glob glob = new Glob("MyClass", false);

            Assert.IsTrue(glob.IsMatch("myclass"));
        }
示例#48
0
 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"));
 }
示例#49
0
 public void CanMatchSingleFile()
 {
     var glob = new Glob("*file.txt");
     Assert.True(glob.IsMatch("bigfile.txt"));
     Assert.True(glob.IsMatch("smallfile.txt"));
 }