Resolves #41. EOF cannot follow s. would need s' : s EOF ; for that. updating unit test TestParserExec.testOptional

This commit is contained in:
Terence Parr 2012-07-21 15:29:07 -07:00
parent 885f6530ad
commit 8c03dbacf8
1 changed files with 11 additions and 10 deletions

View File

@ -164,32 +164,33 @@ public class TestParserExec extends BaseTest {
/**
* This test is meant to detect regressions of bug antlr/antlr4#41.
* https://github.com/antlr/antlr4/issues/41
* Related to https://github.com/antlr/antlr4/issues/41. EOF is
* not viable after "if x" since EOF not viable after stat.
*/
@Test
public void testOptional() throws Exception {
String grammar =
"grammar T;\n" +
"s : a | 'x';\n" +
"a : 'a' s ('b' s)?;\n"
"stat : ifstat | 'x';\n" +
"ifstat : 'if' stat ('else' stat)?;\n" +
"WS : [ \\n\\t]+ -> skip ;"
;
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "x", false);
String found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "x", false);
assertEquals("", found);
assertNull(this.stderrDuringParse);
found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "axbx", false);
found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "if x else x", false);
assertEquals("", found);
assertNull(this.stderrDuringParse);
found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "ax", false);
found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "if x", false);
assertEquals("", found);
assertNull(this.stderrDuringParse);
assertEquals("line 1:4 no viable alternative at input '<EOF>'\n", this.stderrDuringParse);
found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "aaxbx", false);
found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "if if x else x", false);
assertEquals("", found);
assertNull(this.stderrDuringParse);
assertEquals("line 1:14 no viable alternative at input '<EOF>'\n", this.stderrDuringParse);
}
/**