Ejemplo n.º 1
0
 public void FailGracefullyOnSequence()
 {
     var sequence = Parse.Char('a').XDelimitedBy(Parse.Char(','));
     AssertParser.FailsWith(sequence, "a,a,b", result =>
     {
         Assert.Contains(string.Format(TRS.UnexpectedToken, "b"), result.Message);
         Assert.Contains("a", result.Expectations);
     });
 }
Ejemplo n.º 2
0
        public void CanSpecifyParsersUsingQueryComprehensions()
        {
            var p = from a in Parse.Char('a').Once()
                    from bs in Parse.Char('b').Many()
                    from cs in Parse.Char('c').AtLeastOnce()
                    select a.Concat(bs).Concat(cs);

            AssertParser.SucceedsWithAll(p, "abbbc");
        }
Ejemplo n.º 3
0
        public void WithXMany_WhenLastElementFails_FailureReportedAtLastElement()
        {
            var ab = from a in Parse.Char('a')
                     from b in Parse.Char('b')
                     select "ab";

            var p = ab.XMany().End();

            AssertParser.FailsAt(p, "ababaf", 5);
        }
Ejemplo n.º 4
0
 public void CanParseSeceralLines()
 {
     AssertParser.SucceedsWith(
         AssemblerParser.Assembler,
         @"      ;multiline sample
                 label:  
                 mov   a  ,  b;",
         lines => Assert.Equal(
             new[]
     {
         new AssemblerLine(null, null, null, "multiline sample"),
         new AssemblerLine("label", null, null, null),
         new AssemblerLine(null, "mov", new[] { "a", "b" }, "")
     },
             lines));
 }
Ejemplo n.º 5
0
 public void ReturningValue_DoesNotAdvanceInput()
 {
     var p = Parse.Return(1);
     AssertParser.SucceedsWith(p, "abc", n => Assert.Equal(1, n));
 }
Ejemplo n.º 6
0
 public void ConcatenatingParsers_ConcatenatesResults()
 {
     var p = Parse.Char('a').Once().Then(a =>
         Parse.Char('b').Once().Select(b => a.Concat(b)));
     AssertParser.SucceedsWithAll(p, "ab");
 }
Ejemplo n.º 7
0
 public void Parser_OfAtLeastOneChar_AcceptsManyChars()
 {
     AssertParser.SucceedsWithAll(Parse.Char('a').AtLeastOnce(), "aaa");
 }
Ejemplo n.º 8
0
 public void Parser_OfAtLeastOneChar_DoesNotAcceptEmptyInput()
 {
     AssertParser.Fails(Parse.Char('a').AtLeastOnce(), "");
 }
Ejemplo n.º 9
0
 public void Parser_OfManyChars_AcceptsManyChars()
 {
     AssertParser.SucceedsWithAll(Parse.Char('a').Many(), "aaa");
 }
Ejemplo n.º 10
0
 public void CanParseLabel()
 {
     AssertParser.SucceedsWith(
         AssemblerParser.Assembler, "label:",
         lines => Assert.Equal(new AssemblerLine("label", null, null, null), lines.Single()));
 }
Ejemplo n.º 11
0
 public void IgnoreCaseParser()
 {
     var ab = Parse.IgnoreCase("ab").Text();
     AssertParser.SucceedsWith(ab, "Ab", m => Assert.Equal("Ab", m));
 }
Ejemplo n.º 12
0
 public void NotParserConsumesNoInputOnFailure()
 {
     var notAb = Parse.String("ab").Text().Not();
     AssertParser.FailsAt(notAb, "abc", 0);
 }
Ejemplo n.º 13
0
 public void XAtLeastOnceParser_WhenFirstElementFails_FailureReportedAtFirstElement()
 {
     var ab = Parse.String("ab").Text();
     var p = ab.XAtLeastOnce().End();
     AssertParser.FailsAt(p, "d", 0);
 }
Ejemplo n.º 14
0
 public void Parser_OfChar_DoesNotAcceptNonMatchingChar()
 {
     AssertParser.FailsAt(Parse.Char('a').Once(), "b", 0);
 }
Ejemplo n.º 15
0
 public void XOptionalParserFailsOnPartialMatch()
 {
     var optAbc = Parse.String("abc").Text().XOptional();
     AssertParser.FailsAt(optAbc, "abd", 2);
     AssertParser.FailsAt(optAbc, "aa", 1);
 }
Ejemplo n.º 16
0
 public void Parser_OfChar_AcceptsOnlyOneChar()
 {
     AssertParser.SucceedsWithOne(Parse.Char('a').Once(), "aaa", 'a');
 }
Ejemplo n.º 17
0
 public void ExceptStopsConsumingInputWhenExclusionParsed()
 {
     var exceptAa = Parse.AnyChar.Except(Parse.String("aa")).Many().Text();
     AssertParser.SucceedsWith(exceptAa, "abcaab", r => Assert.Equal("abc", r));
 }
Ejemplo n.º 18
0
 public void CanParseEmpty()
 {
     AssertParser.SucceedsWith(AssemblerParser.Assembler, string.Empty, Assert.Empty);
 }
Ejemplo n.º 19
0
 public void CanParseCommentWithSpaces()
 {
     AssertParser.SucceedsWith(AssemblerParser.Assembler,
                               "  ; comment ",
                               lines => Assert.Equal(new AssemblerLine(null, null, null, " comment "), lines.Single()));
 }
Ejemplo n.º 20
0
 public void WhenFirstOptionSucceedsButConsumesNothing_SecondOptionTried()
 {
     var p = Parse.Char('a').Many().XOr(Parse.Char('b').Many());
     AssertParser.SucceedsWithAll(p, "bbb");
 }
Ejemplo n.º 21
0
 public void Parser_OfManyChars_AcceptsEmptyInput()
 {
     AssertParser.SucceedsWithAll(Parse.Char('a').Many(), "");
 }
Ejemplo n.º 22
0
 public void ParsesString_AsSequenceOfChars()
 {
     var p = Parse.String("abc");
     AssertParser.SucceedsWithAll(p, "abc");
 }