Test for recovery over-consumption

This commit is contained in:
Michael Peyton Jones 2015-01-20 10:43:43 +00:00
parent 9ae25db028
commit dea7c768d4
4 changed files with 36 additions and 0 deletions

View File

@ -585,6 +585,10 @@ public class Generator {
"aab",
"",
"line 1:1 extraneous input 'a' expecting {'b', 'c'}\n");
file.addParserTest(input, "SingleTokenDeletionConsumption", "T", "a",
"aabd",
"[@2,2:2='b',<1>,1:2]\n",
"line 1:1 extraneous input 'a' expecting {'b', 'c'}\n");
file.addParserTest(input, "SingleTokenInsertion", "T", "a",
"ac",
"",
@ -597,6 +601,10 @@ public class Generator {
"ad",
"",
"line 1:1 missing {'b', 'c'} at 'd'\n");
file.addParserTest(input, "SingleSetInsertionConsumption", "T", "a",
"ad",
"[@0,0:0='a',<3>,1:0]\n",
"line 1:1 missing {'b', 'c'} at 'd'\n");
file.addParserTest(input, "ConjuringUpTokenFromSet", "T", "a",
"ad",
"conjured=[@-1,-1:-1='<missing 'b'>',<2>,1:1]\n",

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
set: ('b'|'c') ;
a: 'a' set 'd' {System.out.println($set.stop);} ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
set: ('b'|'c') ;
a: 'a' set 'd' {System.out.println($set.stop);} ;

View File

@ -35,6 +35,17 @@ public class TestParserErrors extends BaseTest {
assertEquals("line 1:1 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);
}
/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testSingleTokenDeletionConsumption() throws Exception {
String grammar = "grammar T;\n" +
"set: ('b'|'c') ;\n" +
"a: 'a' set 'd' {System.out.println($set.stop);} ;";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aabd", false);
assertEquals("[@2,2:2='b',<1>,1:2]\n", found);
assertEquals("line 1:1 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);
}
/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testSingleTokenInsertion() throws Exception {
@ -65,6 +76,17 @@ public class TestParserErrors extends BaseTest {
assertEquals("line 1:1 missing {'b', 'c'} at 'd'\n", this.stderrDuringParse);
}
/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testSingleSetInsertionConsumption() throws Exception {
String grammar = "grammar T;\n" +
"set: ('b'|'c') ;\n" +
"a: 'a' set 'd' {System.out.println($set.stop);} ;";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ad", false);
assertEquals("[@0,0:0='a',<3>,1:0]\n", found);
assertEquals("line 1:1 missing {'b', 'c'} at 'd'\n", this.stderrDuringParse);
}
/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testConjuringUpTokenFromSet() throws Exception {