1 /*
2  * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
3  * Use of this file is governed by the BSD 3-clause license that
4  * can be found in the LICENSE.txt file in the project root.
5  */
6 package org.antlr.v4.test.tool;
7 
8 import org.antlr.v4.tool.ErrorType;
9 import org.junit.Before;
10 import org.junit.Test;
11 
12 /** Test errors with the set stuff in lexer and parser */
13 public class TestErrorSets extends BaseJavaToolTest {
14 	protected boolean debug = false;
15 
16 	@Before
17 	@Override
testSetUp()18 	public void testSetUp() throws Exception {
19 		super.testSetUp();
20 	}
21 
22 	/** Public default constructor used by TestRig */
TestErrorSets()23 	public TestErrorSets() {
24 	}
25 
testNotCharSetWithRuleRef()26 	@Test public void testNotCharSetWithRuleRef() throws Exception {
27 		// might be a useful feature to add someday
28 		String[] pair = new String[] {
29 			"grammar T;\n" +
30 			"a : A {System.out.println($A.text);} ;\n" +
31 			"A : ~('a'|B) ;\n" +
32 			"B : 'b' ;\n",
33 			"error(" + ErrorType.UNSUPPORTED_REFERENCE_IN_LEXER_SET.code + "): T.g4:3:10: rule reference B is not currently supported in a set\n"
34 		};
35 		super.testErrors(pair, true);
36 	}
37 
testNotCharSetWithString()38 	@Test public void testNotCharSetWithString() throws Exception {
39 		// might be a useful feature to add someday
40 		String[] pair = new String[] {
41 			"grammar T;\n" +
42 			"a : A {System.out.println($A.text);} ;\n" +
43 			"A : ~('a'|'aa') ;\n" +
44 			"B : 'b' ;\n",
45 			"error(" + ErrorType.INVALID_LITERAL_IN_LEXER_SET.code + "): T.g4:3:10: multi-character literals are not allowed in lexer sets: 'aa'\n"
46 		};
47 		super.testErrors(pair, true);
48 	}
49 
50 
51 }
52