Add regression test for #561 (token named ATN breaks reference to ATN.INVALID_ALT_NUMBER)

This commit is contained in:
Sam Harwell 2014-05-24 13:14:08 -05:00
parent 4ae0161f1a
commit e0937a6322
1 changed files with 21 additions and 0 deletions

View File

@ -441,4 +441,25 @@ public class TestParserExec extends BaseTest {
assertEquals("", found);
assertNull(stderrDuringParse);
}
/**
* This is a regression test for antlr/antlr4#561 "Issue with parser
* generation in 4.2.2"
* https://github.com/antlr/antlr4/issues/561
*/
@Test public void testReferenceToATN() throws Exception {
String grammar =
"grammar T;\n" +
"a : (ID|ATN)* ATN? {System.out.println($text);} ;\n" +
"ID : 'a'..'z'+ ;\n" +
"ATN : '0'..'9'+;\n" +
"WS : (' '|'\\n') -> skip ;\n";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"", false);
assertEquals("\n", found);
found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
"a 34 c", false);
assertEquals("a34c\n", found);
}
}