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()); }
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()); }
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); }
public void ReturnsTrueWhenDigitsInputIsCorrect(string pattern, string remainingText) { Assert.True(digits.Match(pattern).Success()); Assert.Equal(remainingText, digits.Match(pattern).RemainingText()); }