示例#1
0
        public void Test_Escaped_Character_Pattern(EscapeCharacter.EscapeCharacterType type, string expected)
        {
            var pattern = new RegExpPattern()
                          .Character(type);

            pattern.ToString().Should().Be(expected);
        }
示例#2
0
        public void Test_IsMatch_36()
        {
            const string EXPECTED = @"^(\(?\d{3}\)?[\s-])?\d{3}-\d{4}$";

            var pattern = new RegExpPattern()
                          .AtStartOfStringOrLine()
                          .ZeroOrOneOf(
                false, true,
                p => p.ZeroOrOneOf(
                    false, false,
                    p2 => p2.Character('('))
                .Time(3, p2 => p2.AnyOneDigit())
                .ZeroOrOneOf(
                    false, false,
                    p2 => p2.Character(')'))
                .AnyCharacter(
                    RegExpEscapeCharacter.Build(EscapeCharacter.EscapeCharacterType.WhiteSpace),
                    RegExpCharacter.Build('-')))
                          .Time(3, p => p.AnyOneDigit())
                          .Text("-")
                          .Time(4, p => p.AnyOneDigit())
                          .AtEndOfStringOrLine();

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#3
0
        public void Test_Word_Boundary_Auto_Pattern()
        {
            const string EXPECTED = @"\bare\b";

            var pattern = new RegExpPattern()
                          .WithWordBoundary(p => p.Text("are"));

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#4
0
        public void Test_Simple_Character_Pattern()
        {
            const string EXPECTED = "1";

            var pattern = new RegExpPattern()
                          .Text("1");

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#5
0
        public void Test_Unicode_Character_Pattern()
        {
            const string EXPECTED = @"\u0064";

            var pattern = new RegExpPattern()
                          .Character('d', true);

            pattern.ToString().Should().Be(EXPECTED);
        }
        public void Test_TimeAtLeast_Pattern()
        {
            const string EXPECTED = "A{3,}";

            var pattern = new RegExpPattern()
                          .TimeAtLeast(3, p => p.Text("A"));

            pattern.ToString().Should().Be(EXPECTED);
        }
        public void Test_One_Or_More_Test_Pattern()
        {
            const string EXPECTED = "s+";

            var pattern = new RegExpPattern()
                          .OneOrMoreOf(false, false, p => p.Text("s"));

            pattern.ToString().Should().Be(EXPECTED);
        }
        public void Test_Time_From_To_Pattern()
        {
            const string EXPECTED = "A{1,3}";

            var pattern = new RegExpPattern()
                          .Time(1, 3, p => p.Text("A"));

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#9
0
        public void Test_Negative_LookAhead_Pattern()
        {
            const string EXPECTED = "a(?!b)";

            var pattern = new RegExpPattern()
                          .OnlyIfAheadIsNot(p => p.Text("b"), p => p.Text("a"));

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#10
0
        public void Test_Non_Word_Boundary_Auto_Pattern()
        {
            const string EXPECTED = @"\Bgame\B";

            var pattern = new RegExpPattern()
                          .WithNonWordBoundary(p => p.Text("game"));

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#11
0
        public void Test_Escaped_Special_Character_Pattern(string special)
        {
            var expected = @"\" + special;

            var pattern = new RegExpPattern()
                          .Text(special);

            pattern.ToString().Should().Be(expected);
        }
示例#12
0
        public void Test_Word_Of_None_Pattern(WordCharacter.WordCharacterType wordType, string value)
        {
            var expected = @"\P{" + value + "}";

            var pattern = new RegExpPattern()
                          .WordCharacterOtherThan(wordType);

            pattern.ToString().Should().Be(expected);
        }
示例#13
0
        public void Test_Wild_Char_Pattern()
        {
            const string EXPECTED = ".";

            var pattern = new RegExpPattern()
                          .AnyCharacter();

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#14
0
        public void Test_Non_Word_Of_Pattern()
        {
            const string EXPECTED = @"\W";

            var pattern = new RegExpPattern()
                          .AnyNonWordCharacter();

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#15
0
        public void Test_Any_Of_One_Character_Pattern()
        {
            const string EXPECTED = "[ae]";

            var pattern = new RegExpPattern()
                          .AnyCharacter("ae");

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#16
0
        public void Test_Negative_Any_Of_One_Character_Pattern()
        {
            const string EXPECTED = "[^aei]";

            var pattern = new RegExpPattern()
                          .AnyCharacterOtherThan("aei");

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#17
0
        public void Test_Range_Pattern()
        {
            const string EXPECTED = "[A-Z]";

            var pattern = new RegExpPattern()
                          .CharacterRange('A', 'Z');

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#18
0
        public void Test_Range_With_Range_Exception_Pattern()
        {
            const string EXPECTED = "[A-Z-[M-P]]";

            var pattern = new RegExpPattern()
                          .CharacterRange('A', 'Z', 'M', 'P');

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#19
0
        public void Test_Digit_Pattern()
        {
            const string EXPECTED = @"\d";

            var pattern = new RegExpPattern()
                          .AnyOneDigit();

            pattern.ToString().Should().Be(EXPECTED);
        }
        public void Test_Zero_Or_One_Text_Pattern()
        {
            const string EXPECTED = "s?";

            var pattern = new RegExpPattern()
                          .ZeroOrOneOf(false, false, p => p.Text("s"));

            pattern.ToString().Should().Be(EXPECTED);
        }
        public void Test_Zero_Or_More_Grouped_Text_Pattern()
        {
            const string EXPECTED = "(s)*";

            var pattern = new RegExpPattern()
                          .ZeroOrMoreOf(false, true, p => p.Text("s"));

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#22
0
        public void Test_Negative_LookBehind_Pattern()
        {
            const string EXPECTED = "(?<!c)a";

            var pattern = new RegExpPattern()
                          .OnlyIfBehindIsNot(p => p.Text("c"), p => p.Text("a"));

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#23
0
        public void Test_Repeat_Pattern()
        {
            const string EXPECTED = "6?6?6?";

            var pattern = new RegExpPattern()
                          .Repeat(3, r => r.Text("6?", false));

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#24
0
        public void Test_Matching_Where_Previous_Match_Ended_Pattern()
        {
            const string EXPECTED = @"\G";

            var pattern = new RegExpPattern()
                          .ByOnlyMatchingWherePreviousMatchEnded();

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#25
0
        public void Test_Simple_Text_Pattern()
        {
            const string EXPECTED = "winter";

            var pattern = new RegExpPattern()
                          .Text("winter");

            pattern.ToString().Should().Be(EXPECTED);
        }
        public void Test_Zero_Or_More_As_Few_As_Possible_Text_Pattern()
        {
            const string EXPECTED = "s*?";

            var pattern = new RegExpPattern()
                          .ZeroOrMoreOf(true, false, p => p.Text("s"));

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#27
0
        public void Test_IsMatch_31()
        {
            const string EXPECTED = @"^.+";

            var pattern = new RegExpPattern()
                          .AtStartOfStringOrLine()
                          .OneOrMoreOf(false, false, p => p.AnyCharacter());

            pattern.ToString().Should().Be(EXPECTED);
        }
        public void Test_Zero_Or_More_As_Few_As_Possible_Character_Pattern()
        {
            const string EXPECTED = "a*?b";

            var pattern = new RegExpPattern()
                          .ZeroOrMoreOf(true, false, p => p.Text("a"))
                          .Text("b");

            pattern.ToString().Should().Be(EXPECTED);
        }
示例#29
0
        public void Test_IsMatch_33()
        {
            const string EXPECTED = @"(\w)\1";

            var pattern = new RegExpPattern()
                          .GroupOf(true, p => p.AnyWordCharacter())
                          .ValueFromGroup(1);

            pattern.ToString().Should().Be(EXPECTED);
        }
        public void Test_Zero_Or_One_Character_Pattern()
        {
            const string EXPECTED = "a?b";

            var pattern = new RegExpPattern()
                          .ZeroOrOneOf(false, false, p => p.Text("a"))
                          .Text("b");

            pattern.ToString().Should().Be(EXPECTED);
        }