add unit test that reproduces issue #670

This commit is contained in:
Terence Parr 2015-01-12 13:00:15 -08:00
parent 0c2a693638
commit 64f6e196b2
1 changed files with 30 additions and 1 deletions

View File

@ -385,7 +385,8 @@ public class TestCompositeGrammars extends BaseTest {
/** /**
* This is a regression test for antlr/antlr4#670 "exception when importing * This is a regression test for antlr/antlr4#670 "exception when importing
* grammar". * grammar". I think this one always worked but I found that a different
* Java grammar caused an error and so I made the testImportLeftRecursiveGrammar() test below.
* https://github.com/antlr/antlr4/issues/670 * https://github.com/antlr/antlr4/issues/670
*/ */
// TODO: migrate to test framework // TODO: migrate to test framework
@ -403,4 +404,32 @@ public class TestCompositeGrammars extends BaseTest {
assertEquals("", found); assertEquals("", found);
assertNull(stderrDuringParse); assertNull(stderrDuringParse);
} }
/**
* This is a regression test for antlr/antlr4#670 "exception when importing
* grammar".
* https://github.com/antlr/antlr4/issues/670
*/
// TODO: migrate to test framework
@Test
public void testImportLeftRecursiveGrammar() throws Exception {
String slave =
"grammar Java;\n" +
"e : '(' e ')'\n" +
" | e '=' e\n" +
" | ID\n" +
" ;\n" +
"ID : [a-z]+ ;\n";
String master =
"grammar T;\n" +
"import Java;\n" +
"s : e ;\n";
System.out.println("dir "+tmpdir);
mkdir(tmpdir);
writeFile(tmpdir, "Java.g4", slave);
String found = execParser("T.g4", master, "TParser", "TLexer", "s", "a=b", debug);
assertEquals("", found);
assertNull(stderrDuringParse);
}
} }