~ubuntu-branches/ubuntu/wily/parboiled/wily-proposed

« back to all changes in this revision

Viewing changes to examples-java/src/test/java/org/parboiled/examples/calculators/TracingParseRunnerTest.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2014-11-10 21:10:42 UTC
  • Revision ID: package-import@ubuntu.com-20141110211042-wcmfz25icr5ituj5
Tags: upstream-1.1.6
ImportĀ upstreamĀ versionĀ 1.1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009-2011 Mathias Doenitz
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 * http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
package org.parboiled.examples.calculators;
 
18
 
 
19
import org.parboiled.Parboiled;
 
20
import org.parboiled.common.StringBuilderSink;
 
21
import org.parboiled.support.ParsingResult;
 
22
import org.testng.annotations.Test;
 
23
import org.parboiled.parserunners.TracingParseRunner;
 
24
 
 
25
import static org.parboiled.common.Predicates.*;
 
26
import static org.parboiled.errors.ErrorUtils.printParseErrors;
 
27
import static org.parboiled.support.Filters.rules;
 
28
import static org.parboiled.support.Filters.rulesBelow;
 
29
import static org.testng.Assert.assertEquals;
 
30
 
 
31
public class TracingParseRunnerTest {
 
32
 
 
33
    @Test
 
34
    public void testTracingParseRunner() {
 
35
        CalculatorParser1 parser = Parboiled.createParser(CalculatorParser1.class);
 
36
 
 
37
        StringBuilderSink log = new StringBuilderSink();
 
38
        TracingParseRunner<Integer> runner = new TracingParseRunner<Integer>(parser.InputLine())
 
39
                .withFilter(and(rules(parser.Number(), parser.Parens()), not(rulesBelow(parser.Digits()))))
 
40
                .withLog(log);
 
41
        ParsingResult<Integer> result = runner.run("2*(4+5");
 
42
 
 
43
        assertEquals(printParseErrors(result), "" +
 
44
                "Unexpected end of input, expected Digit, '*', '/', '+', '-' or ')' (line 1, pos 7):\n" +
 
45
                "2*(4+5\n" +
 
46
                "      ^\n");
 
47
 
 
48
        assertEquals(log.toString(), "Starting new parsing run\n" +
 
49
                "InputLine/Expression/Term/Factor/Number/Digits, matched, cursor at 1:2 after \"2\"\n" +
 
50
                "..(4)../Number/Number_Action1, matched, cursor at 1:2 after \"2\"\n" +
 
51
                "..(4)../Number, matched, cursor at 1:2 after \"2\"\n" +
 
52
                "..(2)../Term/ZeroOrMore/FirstOf/Sequence/Factor/Number/Digits, failed, cursor at 1:3 after \"2*\"\n" +
 
53
                "..(7)../Number, failed, cursor at 1:3 after \"2*\"\n" +
 
54
                "..(6)../Factor/Parens/'(', matched, cursor at 1:4 after \"2*(\"\n" +
 
55
                "..(7)../Parens/Expression/Term/Factor/Number/Digits, matched, cursor at 1:5 after \"2*(4\"\n" +
 
56
                "..(11)../Number/Number_Action1, matched, cursor at 1:5 after \"2*(4\"\n" +
 
57
                "..(11)../Number, matched, cursor at 1:5 after \"2*(4\"\n" +
 
58
                "..(10)../Factor, matched, cursor at 1:5 after \"2*(4\"\n" +
 
59
                "..(9)../Term/ZeroOrMore/FirstOf/Sequence/'*', failed, cursor at 1:5 after \"2*(4\"\n" +
 
60
                "..(12)../Sequence, failed, cursor at 1:5 after \"2*(4\"\n" +
 
61
                "..(11)../FirstOf/Sequence/'/', failed, cursor at 1:5 after \"2*(4\"\n" +
 
62
                "..(12)../Sequence, failed, cursor at 1:5 after \"2*(4\"\n" +
 
63
                "..(11)../FirstOf, failed, cursor at 1:5 after \"2*(4\"\n" +
 
64
                "..(10)../ZeroOrMore, matched, cursor at 1:5 after \"2*(4\"\n" +
 
65
                "..(9)../Term, matched, cursor at 1:5 after \"2*(4\"\n" +
 
66
                "..(8)../Expression/ZeroOrMore/FirstOf/Sequence/'+', matched, cursor at 1:6 after \"2*(4+\"\n" +
 
67
                "..(11)../Sequence/Term/Factor/Number/Digits, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
68
                "..(14)../Number/Number_Action1, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
69
                "..(14)../Number, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
70
                "..(13)../Factor, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
71
                "..(12)../Term/ZeroOrMore/FirstOf/Sequence/'*', failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
72
                "..(15)../Sequence, failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
73
                "..(14)../FirstOf/Sequence/'/', failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
74
                "..(15)../Sequence, failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
75
                "..(14)../FirstOf, failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
76
                "..(13)../ZeroOrMore, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
77
                "..(12)../Term, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
78
                "..(11)../Sequence/Expression_Action1, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
79
                "..(11)../Sequence, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
80
                "..(10)../FirstOf, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
81
                "..(9)../ZeroOrMore/FirstOf/Sequence/'+', failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
82
                "..(11)../Sequence, failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
83
                "..(10)../FirstOf/Sequence/'-', failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
84
                "..(11)../Sequence, failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
85
                "..(10)../FirstOf, failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
86
                "..(9)../ZeroOrMore, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
87
                "..(8)../Expression, matched, cursor at 1:7 after \"2*(4+5\"\n" +
 
88
                "..(7)../Parens/')', failed, cursor at 1:7 after \"2*(4+5\"\n" +
 
89
                "..(7)../Parens, failed, cursor at 1:7 after \"2*(4+5\"\n");
 
90
    }
 
91
}
 
 
b'\\ No newline at end of file'