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

« back to all changes in this revision

Viewing changes to parboiled-java/src/test/java/org/parboiled/ParserInheritanceTest.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;
 
18
 
 
19
import org.parboiled.annotations.BuildParseTree;
 
20
import org.parboiled.test.TestNgParboiledTest;
 
21
import org.testng.annotations.Test;
 
22
 
 
23
public class ParserInheritanceTest extends TestNgParboiledTest<Object> {
 
24
 
 
25
    public static class Actions extends BaseActions<Object> {
 
26
        public boolean dummyAction() {
 
27
            return true;
 
28
        }
 
29
    }
 
30
 
 
31
    @BuildParseTree
 
32
    public static class ParentParser extends BaseParser<Object> {
 
33
        public Actions actions = new Actions();
 
34
 
 
35
        public Rule Abcd() {
 
36
            return Sequence("ab", "cd", actions.dummyAction());
 
37
        }
 
38
 
 
39
    }
 
40
 
 
41
    public static class DerivedParser extends ParentParser {
 
42
        public Rule Abcds() {
 
43
            return Sequence(OneOrMore(Abcd()), actions.dummyAction());
 
44
        }
 
45
    }
 
46
 
 
47
    @Test
 
48
    public void test() {
 
49
        ParentParser parentParser = Parboiled.createParser(ParentParser.class);
 
50
        test(parentParser.Abcd(), "abcd")
 
51
                .hasNoErrors()
 
52
                .hasParseTree("" +
 
53
                        "[Abcd] 'abcd'\n" +
 
54
                        "  [\"ab\"] 'ab'\n" +
 
55
                        "  [\"cd\"] 'cd'\n");
 
56
 
 
57
        DerivedParser derivedParser = Parboiled.createParser(DerivedParser.class);
 
58
        Rule rule = derivedParser.Abcds();
 
59
        test(rule, "abcdabcd")
 
60
                .hasNoErrors()
 
61
                .hasParseTree("" +
 
62
                        "[Abcds] 'abcdabcd'\n" +
 
63
                        "  [OneOrMore] 'abcdabcd'\n" +
 
64
                        "    [Abcd] 'abcd'\n" +
 
65
                        "      [\"ab\"] 'ab'\n" +
 
66
                        "      [\"cd\"] 'cd'\n" +
 
67
                        "    [Abcd] 'abcd'\n" +
 
68
                        "      [\"ab\"] 'ab'\n" +
 
69
                        "      [\"cd\"] 'cd'\n");
 
70
    }
 
71
 
 
72
}
 
 
b'\\ No newline at end of file'