Beispiel #1
0
        public void MuplipleTextMatch()
        {
            var a = new Many(new Character('a'));

            Assert.True(a.Match("aaaabcd").Success());
            Assert.Equal("bcd", a.Match("aaaabcd").RemainingText());
        }
Beispiel #2
0
        public void IsInRange()
        {
            var digits = new Many(new Json.Range('0', '9'));

            Assert.True(digits.Match("12345ab123").Success());
            Assert.Equal("ab123", digits.Match("12345ab123").RemainingText());
        }
        public void TextMatchesManyTextPattern()
        {
            Many pattern = new Many(new Text("abc"));

            Assert.True(pattern.Match("abcabcd").Success());
            Assert.True(pattern.Match("abcabcd").RemainingText() == "d");
        }
Beispiel #4
0
        public void TextEmptyReturnTrue()
        {
            var a = new Many(new Character('a'));

            Assert.True(a.Match("").Success());
            Assert.Equal("", a.Match("").RemainingText());
        }
Beispiel #5
0
        public void TextNullReturnTrue()
        {
            var a = new Many(new Character('a'));

            Assert.True(a.Match(null).Success());
            Assert.Null(a.Match(null).RemainingText());;
        }
        public void NullMatchesManyDigitRange()
        {
            Many pattern = new Many(new Range('0', '9'));

            Assert.True(pattern.Match(null).Success());
            Assert.True(pattern.Match(null).RemainingText() == null);
        }
        public void FirstCharMatchesManyDigitsPattern()
        {
            Many pattern = new Many(new Range('0', '9'));

            Assert.True(pattern.Match("ab").Success());
            Assert.True(pattern.Match("ab").RemainingText() == "ab");
        }
        public void NullMatchesManyCharPattern()
        {
            Many pattern = new Many(new Character('a'));

            Assert.True(pattern.Match(null).Success());
            Assert.True(pattern.Match(null).RemainingText() == null);
        }
        public void FirstNumberMatchManyDigitsPattern()
        {
            Many pattern = new Many(new Range('0', '9'));

            Assert.True(pattern.Match("12345ab123").Success());
            Assert.True(pattern.Match("12345ab123").RemainingText() == "ab123");
        }
        public void EmptyStringDoesNotMatchCharacter()
        {
            Many pattern = new Many(new Character('a'));

            Assert.True(pattern.Match("").Success());
            Assert.True(pattern.Match("").RemainingText() == "");
        }
        public void EmptyMatchesManyCharacterPattern()
        {
            Many pattern = new Many(new Character('a'));

            Assert.True(pattern.Match("").Success());
            Assert.True(pattern.Match("").RemainingText()?.Length == 0);
        }
Beispiel #12
0
        public void ReturnsTrueAndTextForNoMatchesRange()
        {
            var digits = new Many(new Range('0', '9'));

            Assert.True(digits.Match("ab").Success());
            Assert.Equal("ab", digits.Match("ab").RemainingText());
        }
        public void FirstCharacterMatchesManyCharPattern()
        {
            Many pattern = new Many(new Character('a'));

            Assert.True(pattern.Match("abc").Success());
            Assert.True(pattern.Match("abc").RemainingText() == "bc");
        }
Beispiel #14
0
        public void ReturnsTrueAndRemainingForMatches()
        {
            var digits = new Many(new Range('0', '9'));

            Assert.True(digits.Match("12345ab123").Success());
            Assert.Equal("ab123", digits.Match("12345ab123").RemainingText());
        }
Beispiel #15
0
        public void ReturnsFalseAndEmptyForEmptyString()
        {
            var a = new Many(
                new Character('a'));

            Assert.True(a.Match("").Success());
            Assert.Equal("", a.Match("").RemainingText());
        }
Beispiel #16
0
        public void ReturnsTrueEndTextForNoMatches()
        {
            var a = new Many(
                new Character('a'));

            Assert.True(a.Match("bc").Success());
            Assert.Equal("bc", a.Match("bc").RemainingText());
        }
Beispiel #17
0
        public void StringAsParamReturnsCorectFormatForString()
        {
            var seqence = new Sequence(new Character('a'), new Character('b'));
            var digits  = new Many(seqence);

            Assert.Equal("ac", digits.Match("ababac").RemainingText());
        }
Beispiel #18
0
        public void ForIPatternCharaAndStringabcShouldReturnTrue()
        {
            var    a      = new Many(new Character('a'));
            IMatch actual = a.Match("abc");

            Assert.True(actual.Succes());
        }
Beispiel #19
0
        public void ForIPatternRange09AndString12345ab123ShouldReturnab123()
        {
            var    digits = new Many(new Range('0', '9'));
            IMatch actual = digits.Match("12345ab123");

            Assert.Equal("ab123", actual.RemainingText());
        }
Beispiel #20
0
        public void For_IPattern_Char_a_And_String_bc_Should_Return_String_bc()
        {
            var    a      = new Many(new Character('a'));
            IMatch actual = a.Match("bc");

            Assert.Equal("bc", actual.RemainingText());
        }
Beispiel #21
0
        public void Should_Return__Correct_String_Hexadecimal_Sequence()
        {
            var hex = new Choice(
                new Range('0', '9'),
                new Range('a', 'f'),
                new Range('A', 'F')
                );

            var hexSeq = new Sequence(
                new Character('u'),
                new Sequence(
                    hex,
                    hex,
                    hex,
                    hex
                    )
                );
            var pattern = new Many(
                new Sequence(hexSeq)
                );

            var match = pattern.Match("u1234u1234u12Zabc");

            Assert.Equal("u12Zabc", match.RemainingText());
            Assert.True(match.Success());
        }
Beispiel #22
0
        public void For_IPattern_Char_a_And_String_EmptyString_Should_Return_True()
        {
            var    a      = new Many(new Character('a'));
            IMatch actual = a.Match(string.Empty);

            Assert.True(actual.Succes());
        }
Beispiel #23
0
        public void ForIPatternRange09AndStringabShouldReturnTrue()
        {
            var    digits = new Many(new Range('0', '9'));
            IMatch actual = digits.Match("ab");

            Assert.True(actual.Succes());
        }
Beispiel #24
0
        public void StringAsParamReturnsTrueForString()
        {
            var seqence = new Sequence(new Character('a'), new Character('b'));
            var digits  = new Many(seqence);

            Assert.True(digits.Match("ababc").Success());
        }
Beispiel #25
0
        public void For_IPattern_Range_0_9_And_String_12345ab123_Should_Return_True()
        {
            var    digits = new Many(new Range('0', '9'));
            IMatch actual = digits.Match("12345ab123");

            Assert.True(actual.Succes());
        }
Beispiel #26
0
        public void For_IPattern_Char_a_And_String_EmptyString_Should_Return_String_EmptyString()
        {
            var    a      = new Many(new Character('a'));
            IMatch actual = a.Match(string.Empty);

            Assert.Equal(string.Empty, actual.RemainingText());
        }
Beispiel #27
0
        public void ForIPatternCharaAndStringEmptyStringShouldReturnStringEmptyString()
        {
            var    a      = new Many(new Character('a'));
            IMatch actual = a.Match(string.Empty);

            Assert.Equal(string.Empty, actual.RemainingText());
        }
Beispiel #28
0
        public void For_IPattern_Range_0_9_And_String_12345ab123_Should_Return_ab123()
        {
            var    digits = new Many(new Range('0', '9'));
            IMatch actual = digits.Match("12345ab123");

            Assert.Equal("ab123", actual.RemainingText());
        }
Beispiel #29
0
        public void ForIPatternCharaAndStringbcShouldReturnStringbc()
        {
            var    a      = new Many(new Character('a'));
            IMatch actual = a.Match("bc");

            Assert.Equal("bc", actual.RemainingText());
        }
Beispiel #30
0
        public IMatch Match(string text)
        {
            IMatch match = element.Match(text);

            return(match.Success()
                ? list.Match(match.RemainingText())
                : new SuccessMatch(match.RemainingText()));
        }