示例#1
0
        public IMatch Match(string myString)
        {
            var authority = new Sequance(new Optional(new Sequance(new Userinfo(),
                                                                   new Character('@'))), new Host(), new Optional(new Port()));

            return(authority.Match(myString));
        }
示例#2
0
        public IMatch Match(string myString)
        {
            IPattern method = new Choice(new Text("OPTIONS"), new Text("GET"), new Text("HEAD"), new Text("POST"),
                                         new Text("PUT"), new Text("DELETE"), new Text("TRACE"), new Text("CONNECT"));
            IPattern requestLine = new Sequance(method, new Text("HTTP/1.1\r"));

            return(requestLine.Match(myString));
        }
示例#3
0
        public IMatch Match(string myString)
        {
            var uri = new Sequance(new Optional(new Scheme()), new Optional(new Text("//")), new Optional(new Authority()), new Path(),
                                   new Optional(new Sequance(new Character('?'), new Querry())),
                                   new Optional(new Sequance(new Character('#'), new Fragment())));

            return(uri.Match(myString));
        }
示例#4
0
        public IMatch Match(string myString)
        {
            var digit      = new Range('0', '9');
            var maxPort    = new Sequance(new Range('6', '6'), new Range('5', '5'), new Range('0', '5'), new Range('0', '3'), new Range('0', '5'));
            var maxPortTwo = new Sequance(new Range('0', '6'), new Range('0', '4'), new Many(digit, 1, 4));
            var port       = new Sequance(new Character(':'), new Choice(maxPort, maxPortTwo, new Many(digit, 1, 4)));

            return(port.Match(myString));
        }
示例#5
0
        public IMatch Match(string scheme)
        {
            var alpha          = new Choice(new Range('a', 'z'), new Range('A', 'Z'));
            var schemeContent  = new Sequance(alpha, new OneOrMore(new Choice(alpha, new Range('0', '9'), new Any("+-."))));
            var schemeEndChar  = new Character(':');
            var schemeComplete = new Sequance(schemeContent, schemeEndChar);

            return(schemeComplete.Match(scheme));
        }
示例#6
0
        public void ForabcdForabShouldReturncdForTrue()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            IMatch actual = ab.Match("abcd");

            Assert.Equal("cd", actual.RemainingText());
        }
示例#7
0
        public IMatch Match(string myString)
        {
            Choice   alpha      = new Choice(new Range('a', 'z'), new Range('A', 'Z'));
            Range    digit      = new Range('0', '9');
            Choice   unreserved = new Choice(alpha, digit, new Any("-._~"));
            Any      subDelims  = new Any("!$&'()*+,;=");
            Sequance usserInfo  = new Sequance(unreserved, new Many(new Choice(unreserved, subDelims)), new Character(':'));

            return(usserInfo.Match(myString));
        }
示例#8
0
        public void ForNullShouldReturnfalse()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            IMatch actual = ab.Match(null);

            Assert.False(actual.Succes());
        }
示例#9
0
        public void ForNullShouldReturnNull()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            IMatch actual = ab.Match(null);

            Assert.Null(actual.RemainingText());
        }
示例#10
0
        public void ForabcdForabShouldReturnTrue()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            IMatch actual = ab.Match("abcd");

            Assert.True(actual.Succes());
        }
示例#11
0
        public void ForEmptyStringShouldReturnEmptyString()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            IMatch actual = ab.Match("");

            Assert.Equal("", actual.RemainingText());
        }
示例#12
0
        public void ForEmptyStringShouldReturnFalse()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            IMatch actual = ab.Match("");

            Assert.False(actual.Succes());
        }
示例#13
0
        public void ForStringdefForabShouldReturndefWhenFalse()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            IMatch actual = ab.Match("def");

            Assert.Equal("def", actual.RemainingText());
        }
示例#14
0
        public void TestMatch_RemainingText()
        {
            var digit = new Sequance(
                new Character('0'),
                new Character('1'),
                new Range('A', 'E')
                );
            var answear = digit.Match("01AF");

            Assert.Equal("F", answear.RemainingText());
        }
示例#15
0
        public void For_def_For_a_b_Should_Return_False()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b')
                );

            IMatch actual = ab.Match("def");

            Assert.False(actual.Succes());
        }
示例#16
0
        public void For_String_def_For_a_b_Should_Return_def_When_False()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b')
                );

            IMatch actual = ab.Match("def");

            Assert.Equal("def", actual.RemainingText());
        }
示例#17
0
        public void ForaxStringabcCharactershoudReturnFalseAndax()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            var abc = new Sequance(
                ab,
                new Character('c'));

            IMatch actual = abc.Match("ax");

            Assert.Equal("ax", actual.RemainingText());
        }
示例#18
0
        public void For_ax_String_abc_Character_shoud_Return_False_And_ax()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            var abc = new Sequance(
                ab,
                new Character('c'));

            IMatch actual = abc.Match("ax");

            Assert.Equal("ax", actual.RemainingText());
        }
示例#19
0
        public void For_ax_String_abc_Character_shoud_Return_False()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            var abc = new Sequance(
                ab,
                new Character('c'));

            IMatch actual = abc.Match("ax");

            Assert.False(actual.Succes());
        }
示例#20
0
        public void ForaxStringabcCharactershoudReturnFalse()
        {
            var ab = new Sequance(
                new Character('a'),
                new Character('b'));

            var abc = new Sequance(
                ab,
                new Character('c'));

            IMatch actual = abc.Match("ax");

            Assert.False(actual.Succes());
        }
示例#21
0
        public void TestSequanceOfCharSuccess(string text, string remaining)
        {
            var ab = new Sequance(
                new Charact('a'),
                new Charact('b')
                );

            var abc = new Sequance(
                ab,
                new Charact('c')
                );


            var match = abc.Match(text);

            Assert.True(match.Success());
            Assert.Equal(remaining, match.RemainingText());
        }
示例#22
0
        public void For_Null_Hex_Should_Return_Null()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F'));

            var hexSeq = new Sequance(
                new Character('u'),
                new Sequance(
                    hex,
                    hex,
                    hex,
                    hex));

            IMatch actual = hexSeq.Match(null);

            Assert.Null(actual.RemainingText());
        }
示例#23
0
        public void For_abc_Should_Return_abc()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F'));

            var hexSeq = new Sequance(
                new Character('u'),
                new Sequance(
                    hex,
                    hex,
                    hex,
                    hex));

            IMatch actual = hexSeq.Match("abc");

            Assert.Equal("abc", actual.RemainingText());
        }
示例#24
0
        public void For_abc_Should_Return_false()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F'));

            var hexSeq = new Sequance(
                new Character('u'),
                new Sequance(
                    hex,
                    hex,
                    hex,
                    hex));

            IMatch actual = hexSeq.Match("abc");

            Assert.False(actual.Succes());
        }
示例#25
0
        public void For_uB005_ab_Should_Return_true()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F'));

            var hexSeq = new Sequance(
                new Character('u'),
                new Sequance(
                    hex,
                    hex,
                    hex,
                    hex));

            IMatch actual = hexSeq.Match("uB005 ab");

            Assert.True(actual.Succes());
        }
示例#26
0
        public void ForuabcdefShouldReturntrue()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F'));

            var hexSeq = new Sequance(
                new Character('u'),
                new Sequance(
                    hex,
                    hex,
                    hex,
                    hex));

            IMatch actual = hexSeq.Match("uabcdef");

            Assert.True(actual.Succes());
        }
示例#27
0
        public void For_u1234_Should_Return_Empty_String()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F'));

            var hexSeq = new Sequance(
                new Character('u'),
                new Sequance(
                    hex,
                    hex,
                    hex,
                    hex));

            IMatch actual = hexSeq.Match("u1234");

            Assert.Equal(string.Empty, actual.RemainingText());
        }
示例#28
0
        public void TestSequanceWhenIsFalseAndHaveRemainingText()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F')
                );

            var hexSeq = new Sequance(
                new Character('u'),
                new Sequance(
                    hex,
                    hex,
                    hex,
                    hex
                    )
                );
            var answear = hexSeq.Match("abc");

            Assert.False(answear.Success());
        }
示例#29
0
        public void TestSequanceWhenHaveManyCombinations()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F')
                );

            var hexSeq = new Sequance(
                new Character('u'),
                new Sequance(
                    hex,
                    hex,
                    hex,
                    hex
                    )
                );
            var answear = hexSeq.Match("u1234");

            Assert.True(answear.Success());
        }
示例#30
0
        public void TestSequanceFail(string text, string remaining)
        {
            var hex = new Choices(
                new Ranges('0', '9'),
                new Ranges('a', 'f'),
                new Ranges('A', 'F')
                );

            var hexSeq = new Sequance(
                new Charact('u'),
                new Sequance(
                    hex,
                    hex,
                    hex,
                    hex
                    )
                );


            var match = hexSeq.Match(text);

            Assert.False(match.Success());
            Assert.Equal(remaining, match.RemainingText());
        }