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

« back to all changes in this revision

Viewing changes to parboiled-java/src/test/java/org/parboiled/transform/ErrorDetectionTest.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.transform;
 
18
 
 
19
import org.parboiled.BaseParser;
 
20
import org.parboiled.Rule;
 
21
import org.parboiled.common.ImmutableList;
 
22
import org.testng.annotations.Test;
 
23
 
 
24
import java.util.List;
 
25
 
 
26
import static org.testng.Assert.assertEquals;
 
27
import static org.testng.Assert.fail;
 
28
 
 
29
@SuppressWarnings({"InstantiatingObjectToGetClassObject"})
 
30
public class ErrorDetectionTest extends TransformationTest {
 
31
 
 
32
    private final List<RuleMethodProcessor> processors = ImmutableList.of(
 
33
            new UnusedLabelsRemover(),
 
34
            new ReturnInstructionUnifier(),
 
35
            new InstructionGraphCreator(),
 
36
            new ImplicitActionsConverter(),
 
37
            new InstructionGroupCreator(),
 
38
            new InstructionGroupPreparer(),
 
39
            new ActionClassGenerator(true),
 
40
            new RuleMethodRewriter()
 
41
    );
 
42
 
 
43
    @Test
 
44
    public synchronized void testRuleWithActionAccessingPrivateField() throws Exception {
 
45
        setup(new BaseParser<Object>() {
 
46
            private int privateInt = 5;
 
47
 
 
48
            public Rule RuleWithActionAccessingPrivateField() {
 
49
                return Sequence('a', privateInt == 0);
 
50
            }
 
51
        }.getClass());
 
52
 
 
53
        try {
 
54
            processMethod("RuleWithActionAccessingPrivateField", processors);
 
55
            fail();
 
56
        } catch (Exception e) {
 
57
            assertEquals(e.getMessage(),
 
58
                    "Rule method 'RuleWithActionAccessingPrivateField' contains an illegal access to private field 'privateInt'.\n" +
 
59
                            "Mark the field protected or package-private if you want to prevent public access!");
 
60
        }
 
61
    }
 
62
 
 
63
    @Test
 
64
    public synchronized void testRuleWithActionAccessingPrivateMethod() throws Exception {
 
65
        setup(new BaseParser<Object>() {
 
66
            public Rule RuleWithActionAccessingPrivateMethod() {
 
67
                return Sequence('a', privateAction());
 
68
            }
 
69
 
 
70
            private boolean privateAction() {
 
71
                return true;
 
72
            }
 
73
        }.getClass());
 
74
 
 
75
        try {
 
76
            processMethod("RuleWithActionAccessingPrivateMethod", processors);
 
77
            fail();
 
78
        } catch (Exception e) {
 
79
            assertEquals(e.getMessage(),
 
80
                    "Rule method 'RuleWithActionAccessingPrivateMethod' contains an illegal call to private method 'privateAction'.\n" +
 
81
                            "Mark 'privateAction' protected or package-private if you want to prevent public access!");
 
82
        }
 
83
    }
 
84
 
 
85
}