コード例 #1
0
        public void TestMatch(MatchTestCase testCase)
        {
            var pattern = testCase.Pattern;
            var s       = testCase.Input;

            if (GoLangFileMatch.IsWindows)
            {
                if (pattern.IndexOf('\\') >= 0)
                {
                    // no escape allowed on windows.
                    return;
                }

                pattern = OS.NormalizePath(pattern);
                s       = OS.NormalizePath(s);
            }

            try
            {
                var matched = GoLangFileMatch.Match(pattern, s);
                if (testCase.ShouldThrowException)
                {
                    Assert.False(testCase.ShouldThrowException, "Exception was expected to be thrown but not thrown");
                }

                Assert.Equal(testCase.ShouldMatch, matched);
            }
            catch (ArgumentException)
            {
                if (!testCase.ShouldThrowException)
                {
                    throw;
                }
            }
        }
コード例 #2
0
        private static bool IsFileIgnored(IEnumerable <string> ignores, string path)
        {
            var matches = new List <string>();

            foreach (var ignore in ignores)
            {
                var goLangPattern = ignore.StartsWith("!") ? ignore.Substring(1) : ignore;
                if (GoLangFileMatch.Match(goLangPattern, path))
                {
                    matches.Add(ignore);
                }
            }

            if (matches.Count <= 0)
            {
                return(false);
            }

            var lastMatchingPattern = matches[matches.Count - 1];

            return(!lastMatchingPattern.StartsWith("!"));
        }