From dea7c768d420b6979cafc00eaf94edda232aa189 Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Tue, 20 Jan 2015 10:43:43 +0000 Subject: [PATCH] Test for recovery over-consumption --- .../org/antlr/v4/test/rt/gen/Generator.java | 8 +++++++ .../SingleSetInsertionConsumption.st | 3 +++ .../SingleTokenDeletionConsumption.st | 3 +++ .../v4/test/rt/java/TestParserErrors.java | 22 +++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/SingleSetInsertionConsumption.st create mode 100644 tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/SingleTokenDeletionConsumption.st diff --git a/tool/test/org/antlr/v4/test/rt/gen/Generator.java b/tool/test/org/antlr/v4/test/rt/gen/Generator.java index e4a7076e0..c0f65a3de 100644 --- a/tool/test/org/antlr/v4/test/rt/gen/Generator.java +++ b/tool/test/org/antlr/v4/test/rt/gen/Generator.java @@ -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='',<2>,1:1]\n", diff --git a/tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/SingleSetInsertionConsumption.st b/tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/SingleSetInsertionConsumption.st new file mode 100644 index 000000000..8f42ffb5b --- /dev/null +++ b/tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/SingleSetInsertionConsumption.st @@ -0,0 +1,3 @@ +grammar ; +set: ('b'|'c') ; +a: 'a' set 'd' {System.out.println($set.stop);} ; \ No newline at end of file diff --git a/tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/SingleTokenDeletionConsumption.st b/tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/SingleTokenDeletionConsumption.st new file mode 100644 index 000000000..8f42ffb5b --- /dev/null +++ b/tool/test/org/antlr/v4/test/rt/gen/grammars/ParserErrors/SingleTokenDeletionConsumption.st @@ -0,0 +1,3 @@ +grammar ; +set: ('b'|'c') ; +a: 'a' set 'd' {System.out.println($set.stop);} ; \ No newline at end of file diff --git a/tool/test/org/antlr/v4/test/rt/java/TestParserErrors.java b/tool/test/org/antlr/v4/test/rt/java/TestParserErrors.java index 7f376d8f3..0587e5e2e 100644 --- a/tool/test/org/antlr/v4/test/rt/java/TestParserErrors.java +++ b/tool/test/org/antlr/v4/test/rt/java/TestParserErrors.java @@ -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 {