public void CanIncludeBacktrackErrors() { var deepBacktrack = ErrorMessage.Backtrack(new Position(3, 4), ErrorMessageList.Empty .With(ErrorMessage.Expected("A")) .With(ErrorMessage.Expected("B"))); var shallowBacktrack = ErrorMessage.Backtrack(new Position(2, 3), ErrorMessageList.Empty .With(ErrorMessage.Expected("C")) .With(ErrorMessage.Expected("D")) .With(deepBacktrack)); var unrelatedBacktrack = ErrorMessage.Backtrack(new Position(1, 2), ErrorMessageList.Empty .With(ErrorMessage.Expected("E")) .With(ErrorMessage.Expected("F"))); ErrorMessageList.Empty .With(deepBacktrack) .ToString().ShouldBe("[(3, 4): A or B expected]"); ErrorMessageList.Empty .With(shallowBacktrack) .ToString().ShouldBe("[(2, 3): C or D expected [(3, 4): A or B expected]]"); ErrorMessageList.Empty .With(ErrorMessage.Expected("G")) .With(ErrorMessage.Expected("H")) .With(shallowBacktrack) .With(unrelatedBacktrack) .ToString().ShouldBe("G or H expected [(1, 2): E or F expected] [(2, 3): C or D expected [(3, 4): A or B expected]]"); }
public void CanIndicateErrorsWhichCausedBacktracking() { var position = new Position(3, 4); ErrorMessageList errors = ErrorMessageList.Empty .With(ErrorMessage.Expected("a")) .With(ErrorMessage.Expected("b")); var error = (BacktrackErrorMessage)ErrorMessage.Backtrack(position, errors); error.Position.ShouldBe(position); error.Errors.ShouldBe(errors); error.ToString().ShouldBe("(3, 4): a or b expected"); }