Exemple #1
0
 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");
 }
Exemple #2
0
 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");
 }
Exemple #3
0
        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.");
        }
Exemple #5
0
 public void CanIncludeUnknownErrors()
 {
     ErrorMessageList.Empty
     .With(ErrorMessage.Unknown())
     .ToString().ShouldBe("Parse error.");
 }
        public void CanIndicateGenericErrors()
        {
            var error = ErrorMessage.Unknown();

            error.ToString().ShouldBe("Parse error.");
        }
Exemple #7
0
 public void ReportsErrorState()
 {
     new Error <object>(x, ErrorMessage.Unknown()).Success.ShouldBeFalse();
 }
Exemple #8
0
 public void HasRemainingUnparsedTokens()
 {
     new Error <object>(x, ErrorMessage.Unknown()).UnparsedTokens.ShouldBe(x);
     new Error <object>(endOfInput, ErrorMessage.Unknown()).UnparsedTokens.ShouldBe(endOfInput);
 }
Exemple #9
0
        public void ThrowsWhenAttemptingToGetParsedValue()
        {
            Func <object> inspectParsedValue = () => new Error <object>(x, ErrorMessage.Unknown()).Value;

            inspectParsedValue.ShouldThrow <MemberAccessException>("(1, 1): Parse error.");
        }
Exemple #10
0
 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");
 }