public void OmitsUnknownErrorsWhenAdditionalErrorsExist() { ErrorMessageList.Empty .With(ErrorMessage.Expected("A")) .With(ErrorMessage.Expected("B")) .With(ErrorMessage.Unknown()) .With(ErrorMessage.Expected("C")) .ToString().ShouldBe("A, B or C expected"); }
public void OmitsDuplicateExpectationsFromExpectationLists() { ErrorMessageList.Empty .With(ErrorMessage.Expected("A")) .With(ErrorMessage.Expected("A")) .With(ErrorMessage.Expected("B")) .With(ErrorMessage.Expected("C")) .With(ErrorMessage.Unknown()) .With(ErrorMessage.Expected("C")) .With(ErrorMessage.Expected("C")) .With(ErrorMessage.Expected("A")) .ToString().ShouldBe("A, B or C expected"); }
public void CanMergeTwoLists() { var first = ErrorMessageList.Empty .With(ErrorMessage.Expected("A")) .With(ErrorMessage.Expected("B")) .With(ErrorMessage.Unknown()) .With(ErrorMessage.Expected("C")); var second = ErrorMessageList.Empty .With(ErrorMessage.Expected("D")) .With(ErrorMessage.Expected("B")) .With(ErrorMessage.Unknown()) .With(ErrorMessage.Expected("E")); first.Merge(second) .ToString().ShouldBe("A, B, C, D or E expected"); }
public void CreatesParsersFromLambdas() { var succeeds = new LambdaParser <string>(tokens => new Parsed <string>("AA", tokens.Advance().Advance())); succeeds.PartiallyParses(new CharLexer().Tokenize("AABB")).LeavingUnparsedTokens("B", "B").WithValue("AA"); var fails = new LambdaParser <string>(tokens => new Error <string>(tokens, ErrorMessage.Unknown())); fails.FailsToParse(new CharLexer().Tokenize("AABB")).LeavingUnparsedTokens("A", "A", "B", "B").WithMessage("(1, 1): Parse error."); }
public void CanIncludeUnknownErrors() { ErrorMessageList.Empty .With(ErrorMessage.Unknown()) .ToString().ShouldBe("Parse error."); }
public void CanIndicateGenericErrors() { var error = ErrorMessage.Unknown(); error.ToString().ShouldBe("Parse error."); }
public void ReportsErrorState() { new Error <object>(x, ErrorMessage.Unknown()).Success.ShouldBeFalse(); }
public void HasRemainingUnparsedTokens() { new Error <object>(x, ErrorMessage.Unknown()).UnparsedTokens.ShouldBe(x); new Error <object>(endOfInput, ErrorMessage.Unknown()).UnparsedTokens.ShouldBe(endOfInput); }
public void ThrowsWhenAttemptingToGetParsedValue() { Func <object> inspectParsedValue = () => new Error <object>(x, ErrorMessage.Unknown()).Value; inspectParsedValue.ShouldThrow <MemberAccessException>("(1, 1): Parse error."); }
public void CanIndicateErrorsAtTheCurrentPosition() { new Error <object>(endOfInput, ErrorMessage.Unknown()).ErrorMessages.ToString().ShouldBe("Parse error."); new Error <object>(endOfInput, ErrorMessage.Expected("statement")).ErrorMessages.ToString().ShouldBe("statement expected"); }