예제 #1
0
        public void ReturnFalseWhenTest2InCorrect()
        {
            var whitespaces = new Many(new Any(" \r\n\t"));
            var result      = whitespaces.Match(" \r\t");

            Assert.True(result.Success());
            Assert.Equal("", result.RemainingText());
        }
예제 #2
0
        public void ReturnFalseWhenTest1InCorrect()
        {
            var sequence = new Many(
                new Sequence(
                    new Character('a'),
                    new Character('b'),
                    new Character('c')
                    )
                );

            var result = (SpecialError)sequence.Match("abcabcabx");

            //
            // RT = ABX
            Assert.Equal(8, result.Position());
            Assert.Equal("abx", result.RemainingText());
        }
예제 #3
0
파일: List.cs 프로젝트: thisisalin/JSON
        public IMatch Match(string text)
        {
            IMatch match = element.Match(text);

            if (match.Success())
            {
                int positionError = text == null
                    ? 0
                    : text.Length - match.RemainingText().Length;

                match = many.Match(match.RemainingText());
                SpecialError specialError = (SpecialError)match;

                return(new SpecialError(positionError + specialError.Position(), specialError.RemainingText()));
            }
            if (match is Error error)
            {
                return(new SpecialError(error.Position(), text));
            }
            return(match);
        }
예제 #4
0
 public void ReturnsTrueWhenDigitsInputIsCorrect(string pattern, string remainingText)
 {
     Assert.True(digits.Match(pattern).Success());
     Assert.Equal(remainingText, digits.Match(pattern).RemainingText());
 }