Skip to content

Commit

Permalink
Merge pull request #3 from antlr/add-warnings-in-generated-tests
Browse files Browse the repository at this point in the history
add edit warnings
  • Loading branch information
ericvergnaud committed Nov 23, 2014
2 parents fe4b102 + a0e2006 commit 5c389e5
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tool/test/org/antlr/v4/test/rt/csharp/CSharp.test.stg
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Test<file.name> extends BaseTest {
>>

LexerTestMethod(test) ::= <<
/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void test<test.name>() throws Exception {
<test.slaveGrammars:{ grammar |
Expand Down Expand Up @@ -46,6 +47,7 @@ CompositeLexerTestMethod(test) ::= <<


ParserTestMethod(test) ::= <<
/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void test<test.name>() throws Exception {
<test.slaveGrammars:{ grammar |
Expand Down Expand Up @@ -75,6 +77,7 @@ CompositeParserTestMethod(test) ::= <<
>>

AbstractParserTestMethod(test) ::= <<
/* this file and method are generated, any edit will be overwritten by the next generation */
String test<test.name>(String input) throws Exception {
String grammar = <test.grammar.lines:{ line | "<line>};separator="\\n\" +\n", wrap, anchor>";
return execParser("<test.grammar.grammarName>.g4", grammar, "<test.grammar.grammarName>Parser", "<test.grammar.grammarName>Lexer", "<test.startRule>", input, <test.debug>);
Expand All @@ -83,6 +86,7 @@ String test<test.name>(String input) throws Exception {
>>

ConcreteParserTestMethod(test) ::= <<
/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void test<test.name>() throws Exception {
String found = test<test.baseName>("<test.input>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class TestCompositeLexers extends BaseTest {

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testLexerDelegatorInvokesDelegateRule() throws Exception {
String slave_S = "lexer grammar S;\n" +
Expand All @@ -27,6 +28,7 @@ public void testLexerDelegatorInvokesDelegateRule() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testLexerDelegatorRuleOverridesDelegate() throws Exception {
String slave_S = "lexer grammar S;\n" +
Expand Down
15 changes: 15 additions & 0 deletions tool/test/org/antlr/v4/test/rt/csharp/TestCompositeParsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public class TestCompositeParsers extends BaseTest {

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testDelegatorInvokesDelegateRule() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -24,6 +25,7 @@ public void testDelegatorInvokesDelegateRule() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testBringInLiteralsFromDelegate() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -40,6 +42,7 @@ public void testBringInLiteralsFromDelegate() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testDelegatorInvokesDelegateRuleWithArgs() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -57,6 +60,7 @@ public void testDelegatorInvokesDelegateRuleWithArgs() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testDelegatorInvokesDelegateRuleWithReturnStruct() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -74,6 +78,7 @@ public void testDelegatorInvokesDelegateRuleWithReturnStruct() throws Exception
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testDelegatorAccessesDelegateMembers() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -93,6 +98,7 @@ public void testDelegatorAccessesDelegateMembers() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testDelegatorInvokesFirstVersionOfDelegateRule() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -116,6 +122,7 @@ public void testDelegatorInvokesFirstVersionOfDelegateRule() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testDelegatesSeeSameTokenType() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand Down Expand Up @@ -163,6 +170,7 @@ public void testDelegatesSeeSameTokenType() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testCombinedImportsCombined() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -186,6 +194,7 @@ public void testCombinedImportsCombined() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testDelegatorRuleOverridesDelegate() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -203,6 +212,7 @@ public void testDelegatorRuleOverridesDelegate() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testDelegatorRuleOverridesLookaheadInDelegate() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -225,6 +235,7 @@ public void testDelegatorRuleOverridesLookaheadInDelegate() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testDelegatorRuleOverridesDelegates() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -249,6 +260,7 @@ public void testDelegatorRuleOverridesDelegates() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testKeywordVSIDOrder() throws Exception {
String slave_S = "lexer grammar S;\n" +
Expand All @@ -266,6 +278,7 @@ public void testKeywordVSIDOrder() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testImportedRuleWithAction() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -283,6 +296,7 @@ public void testImportedRuleWithAction() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testImportedGrammarWithEmptyOptions() throws Exception {
String slave_S = "parser grammar S;\n" +
Expand All @@ -301,6 +315,7 @@ public void testImportedGrammarWithEmptyOptions() throws Exception {
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testImportLexerWithOnlyFragmentRules() throws Exception {
String slave_S = "lexer grammar S;\n" +
Expand Down
18 changes: 18 additions & 0 deletions tool/test/org/antlr/v4/test/rt/csharp/TestFullContextParsing.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class TestFullContextParsing extends BaseTest {

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testAmbigYieldsCtxSensitiveDFA() throws Exception {
String grammar = "grammar T;\n" +
Expand All @@ -16,6 +17,7 @@ public void testAmbigYieldsCtxSensitiveDFA() throws Exception {
assertEquals("line 1:0 reportAttemptingFullContext d=0 (s), input='abc'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
String testCtxSensitiveDFA(String input) throws Exception {
String grammar = "grammar T;\n" +
"s @after {this.DumpDFA();}\n" +
Expand All @@ -29,20 +31,23 @@ String testCtxSensitiveDFA(String input) throws Exception {
return execParser("T.g4", grammar, "TParser", "TLexer", "s", input, true);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testCtxSensitiveDFA_1() throws Exception {
String found = testCtxSensitiveDFA("$ 34 abc");
assertEquals("Decision 1:\ns0-INT->s1\ns1-ID->:s2^=>1\n", found);
assertEquals("line 1:5 reportAttemptingFullContext d=1 (e), input='34abc'\nline 1:2 reportContextSensitivity d=1 (e), input='34'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testCtxSensitiveDFA_2() throws Exception {
String found = testCtxSensitiveDFA("@ 34 abc");
assertEquals("Decision 1:\ns0-INT->s1\ns1-ID->:s2^=>1\n", found);
assertEquals("line 1:5 reportAttemptingFullContext d=1 (e), input='34abc'\nline 1:5 reportContextSensitivity d=1 (e), input='34abc'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testCtxSensitiveDFATwoDiffInput() throws Exception {
String grammar = "grammar T;\n" +
Expand All @@ -59,6 +64,7 @@ public void testCtxSensitiveDFATwoDiffInput() throws Exception {
assertEquals("line 1:5 reportAttemptingFullContext d=2 (e), input='34abc'\nline 1:2 reportContextSensitivity d=2 (e), input='34'\nline 1:14 reportAttemptingFullContext d=2 (e), input='34abc'\nline 1:14 reportContextSensitivity d=2 (e), input='34abc'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testSLLSeesEOFInLLGrammar() throws Exception {
String grammar = "grammar T;\n" +
Expand All @@ -75,6 +81,7 @@ public void testSLLSeesEOFInLLGrammar() throws Exception {
assertEquals("line 1:3 reportAttemptingFullContext d=0 (e), input='34abc'\nline 1:0 reportContextSensitivity d=0 (e), input='34'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
String testFullContextIF_THEN_ELSEParse(String input) throws Exception {
String grammar = "grammar T;\n" +
"s \n" +
Expand All @@ -89,48 +96,55 @@ String testFullContextIF_THEN_ELSEParse(String input) throws Exception {
return execParser("T.g4", grammar, "TParser", "TLexer", "s", input, true);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testFullContextIF_THEN_ELSEParse_1() throws Exception {
String found = testFullContextIF_THEN_ELSEParse("{ if x then return }");
assertEquals("Decision 1:\ns0-'}'->:s1=>2\n", found);
assertNull(this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testFullContextIF_THEN_ELSEParse_2() throws Exception {
String found = testFullContextIF_THEN_ELSEParse("{ if x then return else foo }");
assertEquals("Decision 1:\ns0-'else'->:s1^=>1\n", found);
assertEquals("line 1:19 reportAttemptingFullContext d=1 (stat), input='else'\nline 1:19 reportContextSensitivity d=1 (stat), input='else'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testFullContextIF_THEN_ELSEParse_3() throws Exception {
String found = testFullContextIF_THEN_ELSEParse("{ if x then if y then return else foo }");
assertEquals("Decision 1:\ns0-'}'->:s2=>2\ns0-'else'->:s1^=>1\n", found);
assertEquals("line 1:29 reportAttemptingFullContext d=1 (stat), input='else'\nline 1:38 reportAmbiguity d=1 (stat): ambigAlts={1, 2}, input='elsefoo}'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testFullContextIF_THEN_ELSEParse_4() throws Exception {
String found = testFullContextIF_THEN_ELSEParse("{ if x then if y then return else foo else bar }");
assertEquals("Decision 1:\ns0-'else'->:s1^=>1\n", found);
assertEquals("line 1:29 reportAttemptingFullContext d=1 (stat), input='else'\nline 1:38 reportContextSensitivity d=1 (stat), input='elsefooelse'\nline 1:38 reportAttemptingFullContext d=1 (stat), input='else'\nline 1:38 reportContextSensitivity d=1 (stat), input='else'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testFullContextIF_THEN_ELSEParse_5() throws Exception {
String found = testFullContextIF_THEN_ELSEParse("{ if x then return else foo\nif x then if y then return else foo }");
assertEquals("Decision 1:\ns0-'}'->:s2=>2\ns0-'else'->:s1^=>1\n", found);
assertEquals("line 1:19 reportAttemptingFullContext d=1 (stat), input='else'\nline 1:19 reportContextSensitivity d=1 (stat), input='else'\nline 2:27 reportAttemptingFullContext d=1 (stat), input='else'\nline 2:36 reportAmbiguity d=1 (stat): ambigAlts={1, 2}, input='elsefoo}'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testFullContextIF_THEN_ELSEParse_6() throws Exception {
String found = testFullContextIF_THEN_ELSEParse("{ if x then return else foo\nif x then if y then return else foo }");
assertEquals("Decision 1:\ns0-'}'->:s2=>2\ns0-'else'->:s1^=>1\n", found);
assertEquals("line 1:19 reportAttemptingFullContext d=1 (stat), input='else'\nline 1:19 reportContextSensitivity d=1 (stat), input='else'\nline 2:27 reportAttemptingFullContext d=1 (stat), input='else'\nline 2:36 reportAmbiguity d=1 (stat): ambigAlts={1, 2}, input='elsefoo}'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testLoopsSimulateTailRecursion() throws Exception {
String grammar = "grammar T;\n" +
Expand All @@ -153,6 +167,7 @@ public void testLoopsSimulateTailRecursion() throws Exception {
assertEquals("line 1:3 reportAttemptingFullContext d=3 (expr_primary), input='a(i)'\nline 1:7 reportAmbiguity d=3 (expr_primary): ambigAlts={2, 3}, input='a(i)<-x'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testAmbiguityNoLoop() throws Exception {
String grammar = "grammar T;\n" +
Expand All @@ -172,6 +187,7 @@ public void testAmbiguityNoLoop() throws Exception {
assertEquals("line 1:2 reportAttemptingFullContext d=0 (prog), input='a@'\nline 1:2 reportAmbiguity d=0 (prog): ambigAlts={1, 2}, input='a@'\nline 1:2 reportAttemptingFullContext d=1 (expr), input='a@'\nline 1:2 reportContextSensitivity d=1 (expr), input='a@'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
String testExprAmbiguity(String input) throws Exception {
String grammar = "grammar T;\n" +
"s\n" +
Expand All @@ -189,13 +205,15 @@ String testExprAmbiguity(String input) throws Exception {
return execParser("T.g4", grammar, "TParser", "TLexer", "s", input, true);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testExprAmbiguity_1() throws Exception {
String found = testExprAmbiguity("a+b");
assertEquals("(expr a + (expr b))\n", found);
assertEquals("line 1:1 reportAttemptingFullContext d=1 (expr), input='+'\nline 1:2 reportContextSensitivity d=1 (expr), input='+b'\n", this.stderrDuringParse);
}

/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void testExprAmbiguity_2() throws Exception {
String found = testExprAmbiguity("a+b*c");
Expand Down
Loading

0 comments on commit 5c389e5

Please sign in to comment.