Ejemplo n.º 1
0
        public void WmExe(int expected, string pattern, string text, int sourceLineNumber)
        {
            var success = WildMatch.IsMatch(pattern, text, WildMatchFlags.PathName
                                            | WildMatchFlags.CaseFold,
                                            out var matched);

            const string message = "{0}; source line #{1}";

            switch (expected)
            {
            case WM_MATCH:
                Assert.True(success, message, nameof(success), sourceLineNumber);
                Assert.True(matched, message, nameof(matched), sourceLineNumber);
                break;

            case WM_NOMATCH:
                Assert.True(success, message, nameof(success), sourceLineNumber);
                Assert.False(matched, message, nameof(matched), sourceLineNumber);
                break;

            default:
                Assert.False(success, message, nameof(success), sourceLineNumber);
                break;
            }
        }
Ejemplo n.º 2
0
        public void Compare_Wildmatch_Output_With_C_Function()
        {
            var tests = File.ReadAllLines(_basePath + @"\tests.txt")
                        .Where(l => !l.StartsWith("#") && !string.IsNullOrWhiteSpace(l))
                        .Select(l => l.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
                        .Select(l => new Test {
                Text = l[2], Pattern = l[3]
            })
                        .ToList();

            tests.ForEach(t => {
                Console.WriteLine(string.Format("{0} {1}", t.Text, t.Pattern));
                var referenceResult = ReferenceMatchPattern(t.Pattern, t.Text, false);
                var testResult      = WildMatch.IsMatch(t.Pattern, t.Text, MatchFlags.PATHNAME);
                Assert.AreEqual(referenceResult, testResult);
            });
        }
Ejemplo n.º 3
0
        public void Handle_Unclosed_Character_Class()
        {
            var match = WildMatch.IsMatch("abc.t[:x]t", "abc.txt", MatchFlags.NONE);

            Assert.IsTrue(match == WildMatch.MATCH);
        }
Ejemplo n.º 4
0
        public void Match_Escaped_Character_Range()
        {
            var match = WildMatch.IsMatch("abc.t[\\[x]t", "abc.t[t", MatchFlags.NONE);

            Assert.IsTrue(match == WildMatch.MATCH);
        }
Ejemplo n.º 5
0
        public void Abort_Unclosed_Character_Range_Escaped()
        {
            var match = WildMatch.IsMatch("abc.t[\\", "abc.txt", MatchFlags.NONE);

            Assert.IsTrue(match == WildMatch.ABORT_ALL);
        }
Ejemplo n.º 6
0
        public void Single_Star_No_PATHNAME_Set_Match_Slash()
        {
            var match = WildMatch.IsMatch("ab/**", "ab/cd/ef", MatchFlags.NONE);

            Assert.IsTrue(match == WildMatch.MATCH);
        }
Ejemplo n.º 7
0
        public void Single_Star_Dont_Match_Path_Without_Slash()
        {
            var match = WildMatch.IsMatch("ab/*/ef", "ab/cdef", MatchFlags.PATHNAME);

            Assert.IsTrue(match == WildMatch.NOMATCH);
        }
Ejemplo n.º 8
0
        public void Single_Star_Match_Path_Within_Slashes()
        {
            var match = WildMatch.IsMatch("ab/*/ef", "ab/cd/ef", MatchFlags.PATHNAME);

            Assert.IsTrue(match == WildMatch.MATCH);
        }
Ejemplo n.º 9
0
        public void Dont_Match_Slash_With_Question_Mark_Wildcard()
        {
            var match = WildMatch.IsMatch("ab?c", "ab/c", MatchFlags.NONE);

            Assert.IsTrue(match == WildMatch.NOMATCH);
        }
Ejemplo n.º 10
0
        public void No_PATHNAME_Match_Slash_With_Single_Star()
        {
            var match = WildMatch.IsMatch("ab*c", "ab/c", MatchFlags.NONE);

            Assert.IsTrue(match == WildMatch.MATCH);
        }