summaryrefslogtreecommitdiff
path: root/tool-testsuite/test
diff options
context:
space:
mode:
Diffstat (limited to 'tool-testsuite/test')
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/BaseJavaToolTest.java51
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/InterpreterTreeTextProvider.java6
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/JavaUnicodeInputStream.java30
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/ParserInterpreterForTesting.java30
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/PositionAdjustingLexer.g44
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestASTStructure.java30
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestATNConstruction.java423
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestATNDeserialization.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestATNInterpreter.java48
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestATNLexerInterpreter.java44
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestATNParserPrediction.java54
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestATNSerialization.java41
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestActionSplitter.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestActionTranslation.java150
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestAmbigParseTrees.java8
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestAttributeChecks.java48
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestBasicSemanticErrors.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestBufferedTokenStream.java39
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestCodeGeneration.java42
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestCommonTokenStream.java36
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestCompositeGrammars.java185
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestDollarParser.java18
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestErrorSets.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestFastQueue.java30
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestGrammarParserInterpreter.java34
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestGraphNodes.java106
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestIntervalSet.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestLeftRecursionToolIssues.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestLexerActions.java17
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestLookaheadTrees.java8
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestParseTreeMatcher.java16
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestParserExec.java55
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestParserInterpreter.java41
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestParserProfiler.java41
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestPerformance.java50
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestScopeParsing.java134
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java174
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestTokenPositionOptions.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestTokenStreamRewriter.java909
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestTokenTypeAssignment.java33
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java132
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestTopologicalSort.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedCharStream.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedTokenStream.java40
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestVocabulary.java39
-rw-r--r--tool-testsuite/test/org/antlr/v4/test/tool/TestXPath.java16
46 files changed, 1050 insertions, 2472 deletions
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/BaseJavaToolTest.java b/tool-testsuite/test/org/antlr/v4/test/tool/BaseJavaToolTest.java
new file mode 100644
index 0000000..d13af2d
--- /dev/null
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/BaseJavaToolTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+package org.antlr.v4.test.tool;
+
+import org.antlr.v4.Tool;
+import org.antlr.v4.test.runtime.BaseRuntimeTest;
+import org.antlr.v4.test.runtime.ErrorQueue;
+import org.antlr.v4.test.runtime.java.BaseJavaTest;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+
+public class BaseJavaToolTest extends BaseJavaTest {
+ public void testErrors(String[] pairs, boolean printTree) {
+ for (int i = 0; i < pairs.length; i+=2) {
+ String grammarStr = pairs[i];
+ String expect = pairs[i+1];
+
+ String[] lines = grammarStr.split("\n");
+ String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
+ ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, null, fileName, grammarStr, false); // use default language target in case test overrides
+
+ String actual = equeue.toString(true);
+ actual = actual.replace(tmpdir + File.separator, "");
+// System.err.println(actual);
+ String msg = grammarStr;
+ msg = msg.replace("\n","\\n");
+ msg = msg.replace("\r","\\r");
+ msg = msg.replace("\t","\\t");
+
+ assertEquals("error in: "+msg,expect,actual);
+ }
+ }
+
+ public String getFilenameFromFirstLineOfGrammar(String line) {
+ String fileName = "A" + Tool.GRAMMAR_EXTENSION;
+ int grIndex = line.lastIndexOf("grammar");
+ int semi = line.lastIndexOf(';');
+ if ( grIndex>=0 && semi>=0 ) {
+ int space = line.indexOf(' ', grIndex);
+ fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
+ }
+ if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "A" + Tool.GRAMMAR_EXTENSION;
+ return fileName;
+ }
+}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/InterpreterTreeTextProvider.java b/tool-testsuite/test/org/antlr/v4/test/tool/InterpreterTreeTextProvider.java
index bff84ae..d973939 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/InterpreterTreeTextProvider.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/InterpreterTreeTextProvider.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
package org.antlr.v4.test.tool;
import org.antlr.v4.gui.TreeTextProvider;
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/JavaUnicodeInputStream.java b/tool-testsuite/test/org/antlr/v4/test/tool/JavaUnicodeInputStream.java
index d51d000..cdbf9c3 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/JavaUnicodeInputStream.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/JavaUnicodeInputStream.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2013 Terence Parr
- * Copyright (c) 2013 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/ParserInterpreterForTesting.java b/tool-testsuite/test/org/antlr/v4/test/tool/ParserInterpreterForTesting.java
index 9fe58a1..2f5ac4d 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/ParserInterpreterForTesting.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/ParserInterpreterForTesting.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/PositionAdjustingLexer.g4 b/tool-testsuite/test/org/antlr/v4/test/tool/PositionAdjustingLexer.g4
index 4d52dfc..4d1522f 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/PositionAdjustingLexer.g4
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/PositionAdjustingLexer.g4
@@ -1,7 +1,7 @@
/*
* [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
+ * Copyright (c) 2012-2016 Terence Parr
+ * Copyright (c) 2012-2016 Sam Harwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestASTStructure.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestASTStructure.java
index d081fe8..7211efd 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestASTStructure.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestASTStructure.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNConstruction.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNConstruction.java
index 08648f5..5764175 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNConstruction.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNConstruction.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -36,14 +12,14 @@ import org.antlr.v4.automata.ParserATNFactory;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNState;
-import org.antlr.v4.test.runtime.java.BaseTest;
-import org.antlr.v4.test.runtime.java.ErrorQueue;
+import org.antlr.v4.test.runtime.ErrorQueue;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
import org.antlr.v4.tool.ast.GrammarAST;
import org.antlr.v4.tool.ast.GrammarRootAST;
import org.antlr.v4.tool.ast.RuleAST;
+import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
@@ -54,7 +30,13 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-public class TestATNConstruction extends BaseTest {
+public class TestATNConstruction extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test
public void testA() throws Exception {
Grammar g = new Grammar(
@@ -358,6 +340,20 @@ public class TestATNConstruction extends BaseTest {
"RuleStop_a_1-EOF->s9\n";
checkRuleATN(g, "a", expecting);
}
+ @Test public void testEmptyOrEmpty() throws Exception {
+ Grammar g = new Grammar(
+ "parser grammar P;\n"+
+ "a : | ;");
+ String expecting =
+ "RuleStart_a_0->BlockStart_4\n"+
+ "BlockStart_4->s2\n"+
+ "BlockStart_4->s3\n"+
+ "s2->BlockEnd_5\n"+
+ "s3->BlockEnd_5\n"+
+ "BlockEnd_5->RuleStop_a_1\n"+
+ "RuleStop_a_1-EOF->s6\n";
+ checkRuleATN(g, "a", expecting);
+ }
@Test public void testAStar() throws Exception {
Grammar g = new Grammar(
"parser grammar P;\n"+
@@ -464,6 +460,65 @@ public class TestATNConstruction extends BaseTest {
assertTrue(!threwException);
}
+ /** Test for https://github.com/antlr/antlr4/issues/1369
+ * Repeated edges:
+
+ RuleStop_e_3->BlockEnd_26
+ RuleStop_e_3->BlockEnd_26
+ RuleStop_e_3->BlockEnd_26
+
+ * @throws Exception
+ */
+ @Test public void testForRepeatedTransitionsToStopState() throws Exception {
+ String gstr =
+ "grammar T;\n"+
+ "\t s : e EOF;\n"+
+ "\t e :<assoc=right> e '*' e\n"+
+ "\t |<assoc=right> e '+' e\n"+
+ "\t |<assoc=right> e '?' e ':' e\n"+
+ "\t |<assoc=right> e '=' e\n"+
+ "\t | ID\n"+
+ "\t ;\n"+
+ "\t ID : 'a'..'z'+ ;\n"+
+ "\t WS : (' '|'\\n') -> skip ;";
+ Grammar g = new Grammar(gstr);
+ String expecting =
+ "RuleStart_e_2->s7\n"+
+ "s7-action_1:-1->s8\n"+
+ "s8-ID->s9\n"+
+ "s9->StarLoopEntry_27\n"+
+ "StarLoopEntry_27->StarBlockStart_25\n"+
+ "StarLoopEntry_27->s28\n"+
+ "StarBlockStart_25->s10\n"+
+ "StarBlockStart_25->s13\n"+
+ "StarBlockStart_25->s16\n"+
+ "StarBlockStart_25->s22\n"+
+ "s28->RuleStop_e_3\n"+
+ "s10-5 >= _p->s11\n"+
+ "s13-4 >= _p->s14\n"+
+ "s16-3 >= _p->s17\n"+
+ "s22-2 >= _p->s23\n"+
+ "RuleStop_e_3->s5\n"+
+ "RuleStop_e_3->BlockEnd_26\n"+
+ "RuleStop_e_3->s19\n"+
+ "RuleStop_e_3->s21\n"+
+ "s11-'*'->s12\n"+
+ "s14-'+'->s15\n"+
+ "s17-'?'->s18\n"+
+ "s23-'='->s24\n"+
+ "s12-e->RuleStart_e_2\n"+
+ "s15-e->RuleStart_e_2\n"+
+ "s18-e->RuleStart_e_2\n"+
+ "s24-e->RuleStart_e_2\n"+
+ "BlockEnd_26->StarLoopBack_29\n"+
+ "s19-':'->s20\n"+
+ "StarLoopBack_29->StarLoopEntry_27\n"+
+ "s20-e->RuleStart_e_2\n"+
+ "s21->BlockEnd_26\n";
+ checkRuleATN(g, "e", expecting);
+ }
+
+
/*
@Test public void testMultiplePredicates() throws Exception {
Grammar g = new Grammar(
@@ -610,311 +665,8 @@ public class TestATNConstruction extends BaseTest {
"RuleStop_a_1-EOF->s4\n";
checkRule(g, "a", expecting);
}
- // AUTO BACKTRACKING STUFF
- @Test public void testAutoBacktracking_RuleBlock() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : 'a'{;}|'b';"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s1->.s9\n" +
- ".s10-'b'->.s11\n" +
- ".s11->.s6\n" +
- ".s2-{synpred1_t}?->.s3\n" +
- ".s3-'a'->.s4\n" +
- ".s4-{}->.s5\n" +
- ".s5->.s6\n" +
- ".s6->:s7\n" +
- ".s9->.s10\n" +
- ":s7-EOF->.s8\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_RuleSetBlock() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : 'a'|'b';"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s2-'a'..'b'->.s3\n" +
- ".s3->:s4\n" +
- ":s4-EOF->.s5\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_SimpleBlock() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a'{;}|'b') ;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s10->.s11\n" +
- ".s11-'b'->.s12\n" +
- ".s12->.s7\n" +
- ".s2->.s10\n" +
- ".s2->.s3\n" +
- ".s3-{synpred1_t}?->.s4\n" +
- ".s4-'a'->.s5\n" +
- ".s5-{}->.s6\n" +
- ".s6->.s7\n" +
- ".s7->:s8\n" +
- ":s8-EOF->.s9\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_SetBlock() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a'|'b') ;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s2-'a'..'b'->.s3\n" +
- ".s3->:s4\n" +
- ":s4-EOF->.s5\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_StarBlock() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a'{;}|'b')* ;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s12->.s13\n" +
- ".s13-{synpred2_t}?->.s14\n" +
- ".s14-'b'->.s15\n" +
- ".s15->.s8\n" +
- ".s16->.s9\n" +
- ".s2->.s16\n" +
- ".s2->.s3\n" +
- ".s3->.s12\n" +
- ".s3->.s4\n" +
- ".s4-{synpred1_t}?->.s5\n" +
- ".s5-'a'->.s6\n" +
- ".s6-{}->.s7\n" +
- ".s7->.s8\n" +
- ".s8->.s3\n" +
- ".s8->.s9\n" +
- ".s9->:s10\n" +
- ":s10-EOF->.s11\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_StarSetBlock_IgnoresPreds() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a'|'b')* ;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s2->.s3\n" +
- ".s2->.s9\n" +
- ".s3->.s4\n" +
- ".s4-'a'..'b'->.s5\n" +
- ".s5->.s3\n" +
- ".s5->.s6\n" +
- ".s6->:s7\n" +
- ".s9->.s6\n" +
- ":s7-EOF->.s8\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_StarSetBlock() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a'|'b'{;})* ;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s11->.s12\n" +
- ".s12-{synpred2_t}?->.s13\n" +
- ".s13-'b'->.s14\n" +
- ".s14-{}->.s15\n" +
- ".s15->.s7\n" +
- ".s16->.s8\n" +
- ".s2->.s16\n" +
- ".s2->.s3\n" +
- ".s3->.s11\n" +
- ".s3->.s4\n" +
- ".s4-{synpred1_t}?->.s5\n" +
- ".s5-'a'->.s6\n" +
- ".s6->.s7\n" +
- ".s7->.s3\n" +
- ".s7->.s8\n" +
- ".s8->:s9\n" +
- ":s9-EOF->.s10\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_StarBlock1Alt() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a')* ;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s10->.s7\n" +
- ".s2->.s10\n" +
- ".s2->.s3\n" +
- ".s3->.s4\n" +
- ".s4-{synpred1_t}?->.s5\n" +
- ".s5-'a'->.s6\n" +
- ".s6->.s3\n" +
- ".s6->.s7\n" +
- ".s7->:s8\n" +
- ":s8-EOF->.s9\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_PlusBlock() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a'{;}|'b')+ ;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s12->.s13\n" +
- ".s13-{synpred2_t}?->.s14\n" +
- ".s14-'b'->.s15\n" +
- ".s15->.s8\n" +
- ".s2->.s3\n" +
- ".s3->.s12\n" +
- ".s3->.s4\n" +
- ".s4-{synpred1_t}?->.s5\n" +
- ".s5-'a'->.s6\n" +
- ".s6-{}->.s7\n" +
- ".s7->.s8\n" +
- ".s8->.s3\n" +
- ".s8->.s9\n" +
- ".s9->:s10\n" +
- ":s10-EOF->.s11\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_PlusSetBlock() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a'|'b'{;})+ ;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s11->.s12\n" +
- ".s12-{synpred2_t}?->.s13\n" +
- ".s13-'b'->.s14\n" +
- ".s14-{}->.s15\n" +
- ".s15->.s7\n" +
- ".s2->.s3\n" +
- ".s3->.s11\n" +
- ".s3->.s4\n" +
- ".s4-{synpred1_t}?->.s5\n" +
- ".s5-'a'->.s6\n" +
- ".s6->.s7\n" +
- ".s7->.s3\n" +
- ".s7->.s8\n" +
- ".s8->:s9\n" +
- ":s9-EOF->.s10\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_PlusBlock1Alt() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a')+ ;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s2->.s3\n" +
- ".s3->.s4\n" +
- ".s4-{synpred1_t}?->.s5\n" +
- ".s5-'a'->.s6\n" +
- ".s6->.s3\n" +
- ".s6->.s7\n" +
- ".s7->:s8\n" +
- ":s8-EOF->.s9\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_OptionalBlock2Alts() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a'{;}|'b')?;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s10->.s11\n" +
- ".s10->.s14\n" +
- ".s11-{synpred2_t}?->.s12\n" +
- ".s12-'b'->.s13\n" +
- ".s13->.s7\n" +
- ".s14->.s7\n" +
- ".s2->.s10\n" +
- ".s2->.s3\n" +
- ".s3-{synpred1_t}?->.s4\n" +
- ".s4-'a'->.s5\n" +
- ".s5-{}->.s6\n" +
- ".s6->.s7\n" +
- ".s7->:s8\n" +
- ":s8-EOF->.s9\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_OptionalBlock1Alt() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a')?;"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s2->.s3\n" +
- ".s2->.s9\n" +
- ".s3-{synpred1_t}?->.s4\n" +
- ".s4-'a'->.s5\n" +
- ".s5->.s6\n" +
- ".s6->:s7\n" +
- ".s9->.s6\n" +
- ":s7-EOF->.s8\n";
- checkRule(g, "a", expecting);
- }
- @Test public void testAutoBacktracking_ExistingPred() throws Exception {
- Grammar g = new Grammar(
- "grammar t;\n" +
- "options {backtrack=true;}\n"+
- "a : ('a')=> 'a' | 'b';"
- );
- String expecting =
- ".s0->.s1\n" +
- ".s1->.s2\n" +
- ".s1->.s8\n" +
- ".s10->.s5\n" +
- ".s2-{synpred1_t}?->.s3\n" +
- ".s3-'a'->.s4\n" +
- ".s4->.s5\n" +
- ".s5->:s6\n" +
- ".s8->.s9\n" +
- ".s9-'b'->.s10\n" +
- ":s6-EOF->.s7\n";
- checkRule(g, "a", expecting);
- }
-*/
+ */
+
@Test public void testDefaultMode() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar L;\n"+
@@ -934,6 +686,7 @@ public class TestATNConstruction extends BaseTest {
"s13->RuleStop_X_5\n";
checkTokensRule(g, "DEFAULT_MODE", expecting);
}
+
@Test public void testMode() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar L;\n"+
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNDeserialization.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNDeserialization.java
index a8ef3af..5f19024 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNDeserialization.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNDeserialization.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -34,16 +10,22 @@ import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.ATNSerializer;
import org.antlr.v4.runtime.misc.Utils;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
+import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
-public class TestATNDeserialization extends BaseTest {
+public class TestATNDeserialization extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testSimpleNoBlock() throws Exception {
Grammar g = new Grammar(
"parser grammar T;\n"+
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNInterpreter.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNInterpreter.java
index 2309a1c..14e82ae 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNInterpreter.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNInterpreter.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -39,11 +15,11 @@ import org.antlr.v4.runtime.atn.BlockStartState;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.IntegerList;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.DOTGenerator;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
import org.antlr.v4.tool.Rule;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -52,7 +28,13 @@ import static org.junit.Assert.assertEquals;
// NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH
// NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH
-public class TestATNInterpreter extends BaseTest {
+public class TestATNInterpreter extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testSimpleNoBlock() throws Exception {
LexerGrammar lg = new LexerGrammar(
"lexer grammar L;\n" +
@@ -384,7 +366,7 @@ public class TestATNInterpreter extends BaseTest {
ATN lexatn = createATN(lg, true);
LexerATNSimulator lexInterp = new LexerATNSimulator(lexatn,new DFA[] { new DFA(lexatn.modeToStartState.get(Lexer.DEFAULT_MODE)) },null);
IntegerList types = getTokenTypesViaATN(inputString, lexInterp);
- System.out.println(types);
+// System.out.println(types);
g.importVocab(lg);
@@ -392,7 +374,7 @@ public class TestATNInterpreter extends BaseTest {
ATN atn = f.createATN();
IntTokenStream input = new IntTokenStream(types);
- System.out.println("input="+input.types);
+// System.out.println("input="+input.types);
ParserInterpreterForTesting interp = new ParserInterpreterForTesting(g, input);
ATNState startState = atn.ruleToStartState[g.getRule("a").index];
if ( startState.transition(0).target instanceof BlockStartState ) {
@@ -400,9 +382,9 @@ public class TestATNInterpreter extends BaseTest {
}
DOTGenerator dot = new DOTGenerator(g);
- System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule("a").index]));
+// System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule("a").index]));
Rule r = g.getRule("e");
- if ( r!=null ) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
+// if ( r!=null ) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
int result = interp.matchATN(input, startState);
assertEquals(expected, result);
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNLexerInterpreter.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNLexerInterpreter.java
index aaf28c3..0324d39 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNLexerInterpreter.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNLexerInterpreter.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -35,9 +11,9 @@ import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNState;
import org.antlr.v4.runtime.misc.Utils;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.DOTGenerator;
import org.antlr.v4.tool.LexerGrammar;
+import org.junit.Before;
import org.junit.Test;
import java.util.List;
@@ -57,7 +33,13 @@ import static org.junit.Assert.assertEquals;
* want, but occasionally there are some quirks as you'll see from
* the tests below.
*/
-public class TestATNLexerInterpreter extends BaseTest {
+public class TestATNLexerInterpreter extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testLexerTwoRules() throws Exception {
LexerGrammar lg = new LexerGrammar(
"lexer grammar L;\n"+
@@ -314,12 +296,12 @@ public class TestATNLexerInterpreter extends BaseTest {
CharStream input = new ANTLRInputStream(inputString);
ATNState startState = atn.modeNameToStartState.get("DEFAULT_MODE");
DOTGenerator dot = new DOTGenerator(lg);
- System.out.println(dot.getDOT(startState, true));
+// System.out.println(dot.getDOT(startState, true));
List<String> tokenTypes = getTokenTypes(lg, atn, input);
String result = Utils.join(tokenTypes.iterator(), ", ");
- System.out.println(tokenTypes);
+// System.out.println(tokenTypes);
assertEquals(expecting, result);
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNParserPrediction.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNParserPrediction.java
index 5e5731c..3049fd8 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNParserPrediction.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNParserPrediction.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -41,12 +17,12 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.IntegerList;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.DOTGenerator;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LeftRecursiveRule;
import org.antlr.v4.tool.LexerGrammar;
import org.antlr.v4.tool.Rule;
+import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
@@ -58,7 +34,13 @@ import static org.junit.Assert.assertTrue;
// NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH
// NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH
-public class TestATNParserPrediction extends BaseTest {
+public class TestATNParserPrediction extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testAorB() throws Exception {
LexerGrammar lg = new LexerGrammar(
"lexer grammar L;\n" +
@@ -520,7 +502,7 @@ public class TestATNParserPrediction extends BaseTest {
LexerATNSimulator lexInterp =
new LexerATNSimulator(lexatn,new DFA[] { new DFA(lexatn.modeToStartState.get(Lexer.DEFAULT_MODE)) },new PredictionContextCache());
IntegerList types = getTokenTypesViaATN(inputString, lexInterp);
- System.out.println(types);
+// System.out.println(types);
semanticProcess(lg);
g.importVocab(lg);
@@ -532,15 +514,15 @@ public class TestATNParserPrediction extends BaseTest {
DOTGenerator dot = new DOTGenerator(g);
Rule r = g.getRule("a");
- if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
+// if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
r = g.getRule("b");
- if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
+// if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
r = g.getRule("e");
- if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
+// if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
r = g.getRule("ifstat");
- if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
+// if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
r = g.getRule("block");
- if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
+// if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
// Check ATN prediction
// ParserATNSimulator interp = new ParserATNSimulator(atn);
@@ -576,7 +558,7 @@ public class TestATNParserPrediction extends BaseTest {
for (int i=0; i<inputString.length; i++) {
// Check DFA
IntegerList types = getTokenTypesViaATN(inputString[i], lexInterp);
- System.out.println(types);
+// System.out.println(types);
TokenStream input = new IntTokenStream(types);
try {
interp.adaptivePredict(input, decision, ParserRuleContext.EMPTY);
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNSerialization.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNSerialization.java
index 2c1a2b0..5e2b57e 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestATNSerialization.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestATNSerialization.java
@@ -1,48 +1,30 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNSerializer;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.DOTGenerator;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
+import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
-public class TestATNSerialization extends BaseTest {
+public class TestATNSerialization extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testSimpleNoBlock() throws Exception {
Grammar g = new Grammar(
"parser grammar T;\n"+
@@ -127,7 +109,6 @@ public class TestATNSerialization extends BaseTest {
"3->1 EPSILON 0,0,0\n";
ATN atn = createATN(g, true);
DOTGenerator gen = new DOTGenerator(g);
- System.out.println(gen.getDOT(atn.ruleToStartState[0]));
String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
assertEquals(expecting, result);
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestActionSplitter.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestActionSplitter.java
index d8ad87c..391da8e 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestActionSplitter.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestActionSplitter.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -34,7 +10,7 @@ import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.Token;
import org.antlr.v4.parse.ActionSplitter;
import org.antlr.v4.semantics.BlankActionSplitterListener;
-import org.antlr.v4.test.runtime.java.BaseTest;
+import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
@@ -42,7 +18,13 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
-public class TestActionSplitter extends BaseTest {
+public class TestActionSplitter extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
static String[] exprs = {
"foo", "['foo'<" + ActionSplitter.TEXT + ">]",
"$x", "['$x'<" + ActionSplitter.ATTR + ">]",
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestActionTranslation.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestActionTranslation.java
index dfe1704..db73a81 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestActionTranslation.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestActionTranslation.java
@@ -1,42 +1,24 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.Grammar;
+import org.junit.Before;
import org.junit.Test;
/** */
@SuppressWarnings("unused")
-public class TestActionTranslation extends BaseTest {
+public class TestActionTranslation extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
String attributeTemplate =
"attributeTemplate(members,init,inline,finally,inline2) ::= <<\n" +
"parser grammar A;\n"+
@@ -169,6 +151,52 @@ public class TestActionTranslation extends BaseTest {
testActions(attributeTemplate, "inline", action, expected);
}
+ /** Added in response to https://github.com/antlr/antlr4/issues/1211 */
+ @Test public void testUnknownAttr() throws Exception {
+ String action = "$qqq.text";
+ String expected = ""; // was causing an exception
+ testActions(attributeTemplate, "inline", action, expected);
+ }
+
+ /**
+ * Regression test for issue #1295
+ * $e.v yields incorrect value 0 in "e returns [int v] : '1' {$v = 1;} | '(' e ')' {$v = $e.v;} ;"
+ * https://github.com/antlr/antlr4/issues/1295
+ */
+ @Test public void testRuleRefsRecursive() throws Exception {
+ String recursiveTemplate =
+ "recursiveTemplate(inline) ::= <<\n" +
+ "parser grammar A;\n"+
+ "e returns [int v]\n" +
+ " : INT {$v = $INT.int;}\n" +
+ " | '(' e ')' {\n" +
+ " #inline#<inline>#end-inline#\n" +
+ " }\n" +
+ " ;\n" +
+ ">>";
+ String leftRecursiveTemplate =
+ "recursiveTemplate(inline) ::= <<\n" +
+ "parser grammar A;\n"+
+ "e returns [int v]\n" +
+ " : a=e op=('*'|'/') b=e {$v = eval($a.v, $op.type, $b.v);}\n" +
+ " | INT {$v = $INT.int;}\n" +
+ " | '(' e ')' {\n" +
+ " #inline#<inline>#end-inline#\n" +
+ " }\n" +
+ " ;\n" +
+ ">>";
+ // ref to value returned from recursive call to rule
+ String action = "$v = $e.v;";
+ String expected = "((EContext)_localctx).v = ((EContext)_localctx).e.v;";
+ testActions(recursiveTemplate, "inline", action, expected);
+ testActions(leftRecursiveTemplate, "inline", action, expected);
+ // ref to predefined attribute obtained from recursive call to rule
+ action = "$v = $e.text.length();";
+ expected = "((EContext)_localctx).v = (((EContext)_localctx).e!=null?_input.getText(((EContext)_localctx).e.start,((EContext)_localctx).e.stop):null).length();";
+ testActions(recursiveTemplate, "inline", action, expected);
+ testActions(leftRecursiveTemplate, "inline", action, expected);
+ }
+
@Test public void testRefToTextAttributeForCurrentRule() throws Exception {
String action = "$ctx.text; $text";
@@ -190,67 +218,7 @@ public class TestActionTranslation extends BaseTest {
}
- @Test public void testDynamicRuleScopeRefInSubrule() throws Exception {
- String action = "$a::n;";
- }
- @Test public void testRuleScopeFromAnotherRule() throws Exception {
- String action = "$a::n;"; // must be qualified
- }
- @Test public void testFullyQualifiedRefToCurrentRuleParameter() throws Exception {
- String action = "$a.i;";
- }
- @Test public void testFullyQualifiedRefToCurrentRuleRetVal() throws Exception {
- String action = "$a.i;";
- }
- @Test public void testSetFullyQualifiedRefToCurrentRuleRetVal() throws Exception {
- String action = "$a.i = 1;";
- }
- @Test public void testIsolatedRefToCurrentRule() throws Exception {
- String action = "$a;";
- }
- @Test public void testIsolatedRefToRule() throws Exception {
- String action = "$x;";
- }
- @Test public void testFullyQualifiedRefToLabelInCurrentRule() throws Exception {
- String action = "$a.x;";
- }
- @Test public void testFullyQualifiedRefToListLabelInCurrentRule() throws Exception {
- String action = "$a.x;"; // must be qualified
- }
- @Test public void testFullyQualifiedRefToTemplateAttributeInCurrentRule() throws Exception {
- String action = "$a.st;"; // can be qualified
- }
- @Test public void testRuleRefWhenRuleHasScope() throws Exception {
- String action = "$b.start;";
- }
- @Test public void testDynamicScopeRefOkEvenThoughRuleRefExists() throws Exception {
- String action = "$b::n;";
- }
- @Test public void testRefToTemplateAttributeForCurrentRule() throws Exception {
- String action = "$st=null;";
- }
-
- @Test public void testRefToStartAttributeForCurrentRule() throws Exception {
- String action = "$start;";
- }
-
- @Test public void testTokenLabelFromMultipleAlts() throws Exception {
- String action = "$ID.text;"; // must be qualified
- }
- @Test public void testRuleLabelFromMultipleAlts() throws Exception {
- String action = "$b.text;"; // must be qualified
- }
- @Test public void testUnqualifiedRuleScopeAttribute() throws Exception {
- String action = "$n;"; // must be qualified
- }
- @Test public void testRuleAndTokenLabelTypeMismatch() throws Exception {
- }
- @Test public void testListAndTokenLabelTypeMismatch() throws Exception {
- }
- @Test public void testListAndRuleLabelTypeMismatch() throws Exception {
- }
- @Test public void testArgReturnValueMismatch() throws Exception {
- }
+/*
@Test public void testSimplePlusEqualLabel() throws Exception {
String action = "$ids.size();"; // must be qualified
}
@@ -431,6 +399,6 @@ public class TestActionTranslation extends BaseTest {
}
@Test public void testGenericsAsReturnValue() throws Exception {
}
-
+*/
// TODO: nonlocal $rule::x
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestAmbigParseTrees.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestAmbigParseTrees.java
index 992b116..546517e 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestAmbigParseTrees.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestAmbigParseTrees.java
@@ -1,5 +1,12 @@
+/*
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
package org.antlr.v4.test.tool;
+import org.antlr.v4.gui.Trees;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.LexerInterpreter;
@@ -14,7 +21,6 @@ import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.atn.RuleStartState;
import org.antlr.v4.runtime.atn.Transition;
import org.antlr.v4.runtime.tree.ParseTree;
-import org.antlr.v4.gui.Trees;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.GrammarParserInterpreter;
import org.antlr.v4.tool.LexerGrammar;
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestAttributeChecks.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestAttributeChecks.java
index cef7abd..33ca19b 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestAttributeChecks.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestAttributeChecks.java
@@ -1,43 +1,27 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
import org.antlr.runtime.RecognitionException;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.ErrorType;
+import org.junit.Before;
import org.junit.Test;
import org.stringtemplate.v4.ST;
+import org.stringtemplate.v4.STGroup;
+import org.stringtemplate.v4.misc.ErrorBuffer;
/** */
-public class TestAttributeChecks extends BaseTest {
+public class TestAttributeChecks extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
String attributeTemplate =
"parser grammar A;\n"+
"@members {<members>}\n" +
@@ -56,7 +40,7 @@ public class TestAttributeChecks extends BaseTest {
"c : ;\n";
String[] membersChecks = {
- "$a", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a\n",
+ "$a", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a\n",
"$a.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a.y\n",
};
@@ -265,7 +249,9 @@ public class TestAttributeChecks extends BaseTest {
for (int i = 0; i < pairs.length; i+=2) {
String action = pairs[i];
String expected = pairs[i+1];
- ST st = new ST(template);
+ STGroup g = new STGroup('<','>');
+ g.setListener(new ErrorBuffer()); // hush warnings
+ ST st = new ST(g, template);
st.add(location, action);
String grammar = st.render();
testErrors(new String[] {grammar, expected}, false);
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestBasicSemanticErrors.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestBasicSemanticErrors.java
index 807172f..661506d 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestBasicSemanticErrors.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestBasicSemanticErrors.java
@@ -1,41 +1,23 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.ErrorType;
+import org.junit.Before;
import org.junit.Test;
import org.stringtemplate.v4.ST;
-public class TestBasicSemanticErrors extends BaseTest {
+public class TestBasicSemanticErrors extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
static String[] U = {
// INPUT
"parser grammar U;\n" +
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestBufferedTokenStream.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestBufferedTokenStream.java
index fd85b43..d9cbab5 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestBufferedTokenStream.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestBufferedTokenStream.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -37,13 +13,18 @@ import org.antlr.v4.runtime.LexerInterpreter;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenSource;
import org.antlr.v4.runtime.TokenStream;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.LexerGrammar;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
-public class TestBufferedTokenStream extends BaseTest {
+public class TestBufferedTokenStream extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
protected TokenStream createTokenStream(TokenSource src) {
return new BufferedTokenStream(src);
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestCodeGeneration.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestCodeGeneration.java
index 766c775..7574c7c 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestCodeGeneration.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestCodeGeneration.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2014 Terence Parr
- * Copyright (c) 2014 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -35,10 +11,10 @@ import org.antlr.v4.automata.LexerATNFactory;
import org.antlr.v4.automata.ParserATNFactory;
import org.antlr.v4.codegen.CodeGenerator;
import org.antlr.v4.semantics.SemanticPipeline;
-import org.antlr.v4.test.runtime.java.BaseTest;
-import org.antlr.v4.test.runtime.java.ErrorQueue;
+import org.antlr.v4.test.runtime.ErrorQueue;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
+import org.junit.Before;
import org.junit.Test;
import org.stringtemplate.v4.AutoIndentWriter;
import org.stringtemplate.v4.InstanceScope;
@@ -56,7 +32,13 @@ import java.util.List;
import static org.junit.Assert.assertFalse;
-public class TestCodeGeneration extends BaseTest {
+public class TestCodeGeneration extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testArgDecl() throws Exception { // should use template not string
/*ErrorQueue equeue = */new ErrorQueue();
String g =
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestCommonTokenStream.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestCommonTokenStream.java
index 8257824..2453add 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestCommonTokenStream.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestCommonTokenStream.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -40,11 +16,17 @@ import org.antlr.v4.runtime.TokenFactory;
import org.antlr.v4.runtime.TokenSource;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.WritableToken;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestCommonTokenStream extends TestBufferedTokenStream {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
@Override
protected TokenStream createTokenStream(TokenSource src) {
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestCompositeGrammars.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestCompositeGrammars.java
index 02947ab..9b89b0e 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestCompositeGrammars.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestCompositeGrammars.java
@@ -1,41 +1,18 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
-import org.antlr.v4.test.runtime.java.ErrorQueue;
+import org.antlr.v4.test.runtime.BaseRuntimeTest;
+import org.antlr.v4.test.runtime.ErrorQueue;
import org.antlr.v4.tool.ANTLRMessage;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.GrammarSemanticsMessage;
+import org.junit.Before;
import org.junit.Test;
import java.io.File;
@@ -43,16 +20,22 @@ import java.io.File;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-public class TestCompositeGrammars extends BaseTest {
+public class TestCompositeGrammars extends BaseJavaToolTest {
protected boolean debug = false;
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testImportFileLocationInSubdir() throws Exception {
String slave =
"parser grammar S;\n" +
"a : B {System.out.println(\"S.a\");} ;\n";
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
String subdir = tmpdir + "/sub";
- mkdir(subdir);
+ BaseRuntimeTest.mkdir(subdir);
writeFile(subdir, "S.g4", slave);
String master =
"grammar M;\n" +
@@ -61,21 +44,77 @@ public class TestCompositeGrammars extends BaseTest {
"B : 'b' ;" + // defines B from inherited token space
"WS : (' '|'\\n') -> skip ;\n" ;
writeFile(tmpdir, "M.g4", master);
- ErrorQueue equeue = antlr("M.g4", false, "-lib", subdir);
- assertEquals(equeue.size(), 0);
+ ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-lib", subdir);
+ assertEquals(0, equeue.size());
+ }
+
+ // Test for https://github.com/antlr/antlr4/issues/1317
+ @Test public void testImportSelfLoop() throws Exception {
+ BaseRuntimeTest.mkdir(tmpdir);
+ String master =
+ "grammar M;\n" +
+ "import M;\n" +
+ "s : 'a' ;\n";
+ writeFile(tmpdir, "M.g4", master);
+ ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-lib", tmpdir);
+ assertEquals(0, equeue.size());
+ }
+
+ @Test public void testDelegatesSeeSameTokenType() throws Exception {
+ String slaveS =
+ "parser grammar S;\n"+
+ "tokens { A, B, C }\n"+
+ "x : A ;\n";
+ String slaveT =
+ "parser grammar T;\n"+
+ "tokens { C, B, A } // reverse order\n"+
+ "y : A ;\n";
+
+ BaseRuntimeTest.mkdir(tmpdir);
+ writeFile(tmpdir, "S.g4", slaveS);
+ writeFile(tmpdir, "T.g4", slaveT);
+
+ String master =
+ "// The lexer will create rules to match letters a, b, c.\n"+
+ "// The associated token types A, B, C must have the same value\n"+
+ "// and all import'd parsers. Since ANTLR regenerates all imports\n"+
+ "// for use with the delegator M, it can generate the same token type\n"+
+ "// mapping in each parser:\n"+
+ "// public static final int C=6;\n"+
+ "// public static final int EOF=-1;\n"+
+ "// public static final int B=5;\n"+
+ "// public static final int WS=7;\n"+
+ "// public static final int A=4;\n"+
+ "grammar M;\n"+
+ "import S,T;\n"+
+ "s : x y ; // matches AA, which should be 'aa'\n"+
+ "B : 'b' ; // another order: B, A, C\n"+
+ "A : 'a' ;\n"+
+ "C : 'c' ;\n"+
+ "WS : (' '|'\\n') -> skip ;\n";
+ writeFile(tmpdir, "M.g4", master);
+ ErrorQueue equeue = new ErrorQueue();
+ Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
+ String expectedTokenIDToTypeMap = "{EOF=-1, B=1, A=2, C=3, WS=4}";
+ String expectedStringLiteralToTypeMap = "{'a'=2, 'b'=1, 'c'=3}";
+ String expectedTypeToTokenList = "[B, A, C, WS]";
+ assertEquals(expectedTokenIDToTypeMap, g.tokenNameToTypeMap.toString());
+ assertEquals(expectedStringLiteralToTypeMap, sort(g.stringLiteralToTypeMap).toString());
+ assertEquals(expectedTypeToTokenList, realElements(g.typeToTokenList).toString());
+ assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
@Test public void testErrorInImportedGetsRightFilename() throws Exception {
String slave =
"parser grammar S;\n" +
"a : 'a' | c;\n";
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "S.g4", slave);
String master =
"grammar M;\n" +
"import S;\n";
writeFile(tmpdir, "M.g4", master);
- ErrorQueue equeue = antlr("M.g4", false, "-lib", tmpdir);
+ ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-lib", tmpdir);
ANTLRMessage msg = equeue.errors.get(0);
assertEquals(ErrorType.UNDEFINED_RULE_REF, msg.getErrorType());
assertEquals("c", msg.getArgs()[0]);
@@ -88,9 +127,9 @@ public class TestCompositeGrammars extends BaseTest {
String slave =
"parser grammar S;\n" +
"a : B {System.out.println(\"S.a\");} ;\n";
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
String outdir = tmpdir + "/out";
- mkdir(outdir);
+ BaseRuntimeTest.mkdir(outdir);
writeFile(outdir, "S.g4", slave);
String master =
"grammar M;\n" +
@@ -99,7 +138,7 @@ public class TestCompositeGrammars extends BaseTest {
"B : 'b' ;" + // defines B from inherited token space
"WS : (' '|'\\n') -> skip ;\n" ;
writeFile(tmpdir, "M.g4", master);
- ErrorQueue equeue = antlr("M.g4", false, "-o", outdir);
+ ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-o", outdir);
assertEquals(ErrorType.CANNOT_FIND_IMPORTED_GRAMMAR, equeue.errors.get(0).getErrorType());
}
@@ -107,9 +146,9 @@ public class TestCompositeGrammars extends BaseTest {
String slave =
"parser grammar S;\n" +
"a : B {System.out.println(\"S.a\");} ;\n";
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
String subdir = tmpdir + "/sub";
- mkdir(subdir);
+ BaseRuntimeTest.mkdir(subdir);
writeFile(subdir, "S.g4", slave);
String master =
"grammar M;\n" +
@@ -119,8 +158,8 @@ public class TestCompositeGrammars extends BaseTest {
"WS : (' '|'\\n') -> skip ;\n" ;
writeFile(tmpdir, "M.g4", master);
String outdir = tmpdir + "/out";
- mkdir(outdir);
- ErrorQueue equeue = antlr("M.g4", false, "-o", outdir, "-lib", subdir);
+ BaseRuntimeTest.mkdir(outdir);
+ ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-o", outdir, "-lib", subdir);
assertEquals(0, equeue.size());
}
@@ -128,9 +167,9 @@ public class TestCompositeGrammars extends BaseTest {
String slave =
"parser grammar S;\n" +
"a : B {System.out.println(\"S.a\");} ;\n";
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
String subdir = tmpdir + "/sub";
- mkdir(subdir);
+ BaseRuntimeTest.mkdir(subdir);
writeFile(subdir, "S.g4", slave);
String parser =
"parser grammar MParser;\n" +
@@ -144,10 +183,10 @@ public class TestCompositeGrammars extends BaseTest {
"WS : (' '|'\\n') -> skip ;\n" ;
writeFile(tmpdir, "MLexer.g4", lexer);
String outdir = tmpdir + "/out";
- mkdir(outdir);
- ErrorQueue equeue = antlr("MLexer.g4", false, "-o", outdir);
+ BaseRuntimeTest.mkdir(outdir);
+ ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "MLexer.g4", false, "-o", outdir);
assertEquals(0, equeue.size());
- equeue = antlr("MParser.g4", false, "-o", outdir, "-lib", subdir);
+ equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "MParser.g4", false, "-o", outdir, "-lib", subdir);
assertEquals(0, equeue.size());
}
@@ -158,7 +197,7 @@ public class TestCompositeGrammars extends BaseTest {
"options {tokenVocab=whatever;}\n" +
"tokens { A }\n" +
"x : A {System.out.println(\"S.x\");} ;\n";
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "S.g4", slave);
String master =
@@ -184,7 +223,7 @@ public class TestCompositeGrammars extends BaseTest {
String slave =
"parser grammar S;\n" +
"options {toke\n";
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "S.g4", slave);
String master =
@@ -204,13 +243,13 @@ public class TestCompositeGrammars extends BaseTest {
String slave =
"parser grammar T;\n" +
"a : T ;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "T.g4", slave);
String slave2 =
"parser grammar S;\n" +
"import T;\n" +
"a : S ;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "S.g4", slave2);
String master =
@@ -244,34 +283,34 @@ public class TestCompositeGrammars extends BaseTest {
"parser grammar T;\n" +
"tokens{T}\n" +
"x : T ;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "T.g4", slave);
slave =
"parser grammar S;\n" +
"import T;\n" +
"tokens{S}\n" +
"y : S ;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "S.g4", slave);
slave =
"parser grammar C;\n" +
"tokens{C}\n" +
"i : C ;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "C.g4", slave);
slave =
"parser grammar B;\n" +
"tokens{B}\n" +
"j : B ;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "B.g4", slave);
slave =
"parser grammar A;\n" +
"import B,C;\n" +
"tokens{A}\n" +
"k : A ;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "A.g4", slave);
String master =
@@ -305,13 +344,13 @@ public class TestCompositeGrammars extends BaseTest {
String slave =
"parser grammar T;\n" +
"x : T ;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "T.g4", slave);
String slave2 =
"parser grammar S;\n" + // A, B, C token type order
"import T;\n" +
"a : S ;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "S.g4", slave2);
String master =
@@ -343,27 +382,27 @@ public class TestCompositeGrammars extends BaseTest {
"T2: '2';\n" +
"T3: '3';\n" +
"T4: '4';\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "L.g4", gstr);
gstr =
"parser grammar G1;\n" +
"s: a | b;\n" +
"a: T1;\n" +
"b: T2;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "G1.g4", gstr);
gstr =
"parser grammar G2;\n" +
"import G1;\n" +
"a: T3;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "G2.g4", gstr);
String G3str =
"grammar G3;\n" +
"import G2;\n" +
"b: T4;\n" ;
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "G3.g4", G3str);
Grammar g = new Grammar(tmpdir+"/G3.g4", G3str, equeue);
@@ -390,7 +429,7 @@ public class TestCompositeGrammars extends BaseTest {
String slave =
"parser grammar S;\n" +
"a : B {System.out.print(\"S.a\");} ;\n";
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "S.g4", slave);
String master =
"grammar M;\n" +
@@ -399,7 +438,7 @@ public class TestCompositeGrammars extends BaseTest {
"s : a ;\n" +
"B : 'b' ;" + // defines B from inherited token space
"WS : (' '|'\\n') -> skip ;\n" ;
- ErrorQueue equeue = antlr("M.g4", master, false);
+ ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", master, false);
int expecting = 0; // should be ok
assertEquals(expecting, equeue.errors.size());
}
@@ -418,11 +457,11 @@ public class TestCompositeGrammars extends BaseTest {
"grammar NewJava;\n" +
"import Java;\n";
- System.out.println("dir "+tmpdir);
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "Java.g4", slave);
- String found = execParser("NewJava.g4", master, "NewJavaParser", "NewJavaLexer", "compilationUnit", "package Foo;", debug);
- assertEquals("", found);
+ String found = execParser("NewJava.g4", master, "NewJavaParser", "NewJavaLexer",
+ null, null, "compilationUnit", "package Foo;", debug);
+ assertEquals(null, found);
assertNull(stderrDuringParse);
}
@@ -446,11 +485,11 @@ public class TestCompositeGrammars extends BaseTest {
"import Java;\n" +
"s : e ;\n";
- System.out.println("dir "+tmpdir);
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "Java.g4", slave);
- String found = execParser("T.g4", master, "TParser", "TLexer", "s", "a=b", debug);
- assertEquals("", found);
+ String found = execParser("T.g4", master, "TParser", "TLexer",
+ null, null, "s", "a=b", debug);
+ assertEquals(null, found);
assertNull(stderrDuringParse);
}
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestDollarParser.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestDollarParser.java
index 9519f9d..03f0f0e 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestDollarParser.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestDollarParser.java
@@ -1,12 +1,23 @@
+/*
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
package org.antlr.v4.test.tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-public class TestDollarParser extends BaseTest {
+public class TestDollarParser extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
@Test
public void testSimpleCall() throws Exception {
@@ -14,7 +25,8 @@ public class TestDollarParser extends BaseTest {
"a : ID { System.out.println( $parser.getSourceName() ); }\n" +
" ;\n" +
"ID : 'a'..'z'+ ;\n";
- String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "x", true);
+ String found = execParser("T.g4", grammar, "TParser", "TLexer",
+ null, null, "a", "x", true);
assertTrue(found.indexOf(this.getClass().getSimpleName())>=0);
assertNull(this.stderrDuringParse);
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestErrorSets.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestErrorSets.java
index 7afa2b7..7071500 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestErrorSets.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestErrorSets.java
@@ -1,42 +1,24 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.ErrorType;
+import org.junit.Before;
import org.junit.Test;
/** Test errors with the set stuff in lexer and parser */
-public class TestErrorSets extends BaseTest {
+public class TestErrorSets extends BaseJavaToolTest {
protected boolean debug = false;
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
/** Public default constructor used by TestRig */
public TestErrorSets() {
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestFastQueue.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestFastQueue.java
index c28c8c7..926be09 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestFastQueue.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestFastQueue.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestGrammarParserInterpreter.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestGrammarParserInterpreter.java
index d2afde6..b15ed09 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestGrammarParserInterpreter.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestGrammarParserInterpreter.java
@@ -1,40 +1,16 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
+import org.antlr.v4.gui.Trees;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.InterpreterRuleContext;
import org.antlr.v4.runtime.LexerInterpreter;
import org.antlr.v4.runtime.tree.ParseTree;
-import org.antlr.v4.gui.Trees;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.GrammarParserInterpreter;
import org.antlr.v4.tool.LexerGrammar;
@@ -135,7 +111,7 @@ public class TestGrammarParserInterpreter {
ParseTree t = parser.parse(g.rules.get(startRule).index);
InterpreterTreeTextProvider nodeTextProvider = new InterpreterTreeTextProvider(g.getRuleNames());
String treeStr = Trees.toStringTree(t, nodeTextProvider);
- System.out.println("parse tree: "+treeStr);
+// System.out.println("parse tree: "+treeStr);
assertEquals(expectedParseTree, treeStr);
return (InterpreterRuleContext)t;
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestGraphNodes.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestGraphNodes.java
index 8081afc..fd7b781 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestGraphNodes.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestGraphNodes.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -61,7 +37,7 @@ public class TestGraphNodes {
PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY,
PredictionContext.EMPTY,
rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -74,7 +50,7 @@ public class TestGraphNodes {
PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY,
PredictionContext.EMPTY,
fullCtx(), null);
- System.out.println(toDOTString(r, fullCtx()));
+// System.out.println(toDOTString(r, fullCtx()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -85,7 +61,7 @@ public class TestGraphNodes {
@Test public void test_x_$() {
PredictionContext r = PredictionContext.merge(x(), PredictionContext.EMPTY, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -96,7 +72,7 @@ public class TestGraphNodes {
@Test public void test_x_$_fullctx() {
PredictionContext r = PredictionContext.merge(x(), PredictionContext.EMPTY, fullCtx(), null);
- System.out.println(toDOTString(r, fullCtx()));
+// System.out.println(toDOTString(r, fullCtx()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -109,7 +85,7 @@ public class TestGraphNodes {
@Test public void test_$_x() {
PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY, x(), rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -120,7 +96,7 @@ public class TestGraphNodes {
@Test public void test_$_x_fullctx() {
PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY, x(), fullCtx(), null);
- System.out.println(toDOTString(r, fullCtx()));
+// System.out.println(toDOTString(r, fullCtx()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -133,7 +109,7 @@ public class TestGraphNodes {
@Test public void test_a_a() {
PredictionContext r = PredictionContext.merge(a(), a(), rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -149,7 +125,7 @@ public class TestGraphNodes {
PredictionContext x = x();
PredictionContext a2 = createSingleton(x, 1);
PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -165,7 +141,7 @@ public class TestGraphNodes {
PredictionContext x = x();
PredictionContext a2 = createSingleton(x, 1);
PredictionContext r = PredictionContext.merge(a1, a2, fullCtx(), null);
- System.out.println(toDOTString(r, fullCtx()));
+// System.out.println(toDOTString(r, fullCtx()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -183,7 +159,7 @@ public class TestGraphNodes {
PredictionContext a1 = createSingleton(x, 1);
PredictionContext a2 = a();
PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -201,7 +177,7 @@ public class TestGraphNodes {
PredictionContext left = createSingleton(right, 8);
PredictionContext merged = PredictionContext.merge(left, right, false, null);
String actual = toDOTString(merged, false);
- System.out.println(actual);
+// System.out.println(actual);
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -219,7 +195,7 @@ public class TestGraphNodes {
PredictionContext a1 = createSingleton(x, 1);
PredictionContext a2 = a();
PredictionContext r = PredictionContext.merge(a1, a2, fullCtx(), null);
- System.out.println(toDOTString(r, fullCtx()));
+// System.out.println(toDOTString(r, fullCtx()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -234,7 +210,7 @@ public class TestGraphNodes {
@Test public void test_a_b() {
PredictionContext r = PredictionContext.merge(a(), b(), rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -251,7 +227,7 @@ public class TestGraphNodes {
PredictionContext a1 = createSingleton(x, 1);
PredictionContext a2 = createSingleton(x, 1);
PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -270,7 +246,7 @@ public class TestGraphNodes {
PredictionContext a1 = createSingleton(x1, 1);
PredictionContext a2 = createSingleton(x2, 1);
PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -291,7 +267,7 @@ public class TestGraphNodes {
PredictionContext a1 = createSingleton(b1, 1);
PredictionContext a2 = createSingleton(b2, 1);
PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -314,7 +290,7 @@ public class TestGraphNodes {
PredictionContext a1 = createSingleton(b, 1);
PredictionContext a2 = createSingleton(c, 1);
PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -335,7 +311,7 @@ public class TestGraphNodes {
PredictionContext a = createSingleton(x, 1);
PredictionContext b = createSingleton(x, 2);
PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -355,7 +331,7 @@ public class TestGraphNodes {
PredictionContext a = createSingleton(x1, 1);
PredictionContext b = createSingleton(x2, 2);
PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -373,7 +349,7 @@ public class TestGraphNodes {
PredictionContext a = createSingleton(x(), 1);
PredictionContext b = createSingleton(y(), 2);
PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -394,7 +370,7 @@ public class TestGraphNodes {
PredictionContext a = a();
PredictionContext b = createSingleton(x2, 2);
PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -413,7 +389,7 @@ public class TestGraphNodes {
PredictionContext a = a();
PredictionContext b = createSingleton(x2, 2);
PredictionContext r = PredictionContext.merge(a, b, fullCtx(), null);
- System.out.println(toDOTString(r, fullCtx()));
+// System.out.println(toDOTString(r, fullCtx()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -437,7 +413,7 @@ public class TestGraphNodes {
PredictionContext a = createSingleton(e, 1);
PredictionContext b = createSingleton(f, 2);
PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -461,7 +437,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(PredictionContext.EMPTY);
ArrayPredictionContext A2 = array(PredictionContext.EMPTY);
PredictionContext r = PredictionContext.merge(A1, A2, fullCtx(), null);
- System.out.println(toDOTString(r, fullCtx()));
+// System.out.println(toDOTString(r, fullCtx()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -477,7 +453,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a, b);
ArrayPredictionContext A2 = array(c);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -496,7 +472,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a1);
ArrayPredictionContext A2 = array(a2);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -514,7 +490,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a);
ArrayPredictionContext A2 = array(b, c);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -534,7 +510,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a, c);
ArrayPredictionContext A2 = array(b);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -551,7 +527,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a(), b());
ArrayPredictionContext A2 = array(a());
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -567,7 +543,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a(), b());
ArrayPredictionContext A2 = array(b());
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -585,7 +561,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a);
ArrayPredictionContext A2 = array(b);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -607,7 +583,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a1);
ArrayPredictionContext A2 = array(a2);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -627,7 +603,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a1, c());
ArrayPredictionContext A2 = array(a2, d());
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -651,7 +627,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a, b);
ArrayPredictionContext A2 = array(c, d);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -681,7 +657,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a, b1);
ArrayPredictionContext A2 = array(b2, d);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -708,7 +684,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a, b1);
ArrayPredictionContext A2 = array(b2, d);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -736,7 +712,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a, b1);
ArrayPredictionContext A2 = array(b2, d);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
@@ -761,7 +737,7 @@ public class TestGraphNodes {
ArrayPredictionContext A1 = array(a, b);
ArrayPredictionContext A2 = array(c, d);
PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
- System.out.println(toDOTString(r, rootIsWildcard()));
+// System.out.println(toDOTString(r, rootIsWildcard()));
String expecting =
"digraph G {\n" +
"rankdir=LR;\n" +
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestIntervalSet.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestIntervalSet.java
index c06362e..1d3157b 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestIntervalSet.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestIntervalSet.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -33,19 +9,25 @@ package org.antlr.v4.test.tool;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.IntervalSet;
-import org.antlr.v4.test.runtime.java.BaseTest;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-public class TestIntervalSet extends BaseTest {
+public class TestIntervalSet extends BaseJavaToolTest {
/** Public default constructor used by TestRig */
public TestIntervalSet() {
}
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testSingleElement() throws Exception {
IntervalSet s = IntervalSet.of(99);
String expecting = "99";
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestLeftRecursionToolIssues.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestLeftRecursionToolIssues.java
index 713dab8..1ac210c 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestLeftRecursionToolIssues.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestLeftRecursionToolIssues.java
@@ -1,43 +1,25 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.ErrorType;
+import org.junit.Before;
import org.junit.Test;
/** */
-public class TestLeftRecursionToolIssues extends BaseTest {
+public class TestLeftRecursionToolIssues extends BaseJavaToolTest {
protected boolean debug = false;
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testCheckForNonLeftRecursiveRule() throws Exception {
String grammar =
"grammar T;\n" +
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestLexerActions.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestLexerActions.java
index 1e8740d..526efed 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestLexerActions.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestLexerActions.java
@@ -1,11 +1,24 @@
+/*
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
package org.antlr.v4.test.tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
-public class TestLexerActions extends BaseTest {
+public class TestLexerActions extends BaseJavaToolTest {
+
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
// ----- ACTIONS --------------------------------------------------------
@Test public void testActionExecutedInDFA() throws Exception {
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestLookaheadTrees.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestLookaheadTrees.java
index 36c8163..3fdad47 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestLookaheadTrees.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestLookaheadTrees.java
@@ -1,5 +1,12 @@
+/*
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
package org.antlr.v4.test.tool;
+import org.antlr.v4.gui.Trees;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.LexerInterpreter;
@@ -7,7 +14,6 @@ import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.atn.DecisionInfo;
import org.antlr.v4.runtime.atn.LookaheadEventInfo;
import org.antlr.v4.runtime.tree.ParseTree;
-import org.antlr.v4.gui.Trees;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.GrammarParserInterpreter;
import org.antlr.v4.tool.LexerGrammar;
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestParseTreeMatcher.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestParseTreeMatcher.java
index 8f79005..a750880 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestParseTreeMatcher.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestParseTreeMatcher.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
package org.antlr.v4.test.tool;
import org.antlr.v4.runtime.CharStream;
@@ -12,7 +18,7 @@ import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.pattern.ParseTreeMatch;
import org.antlr.v4.runtime.tree.pattern.ParseTreePattern;
import org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher;
-import org.antlr.v4.test.runtime.java.BaseTest;
+import org.junit.Before;
import org.junit.Test;
import java.lang.reflect.Constructor;
@@ -24,7 +30,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-public class TestParseTreeMatcher extends BaseTest {
+public class TestParseTreeMatcher extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testChunking() throws Exception {
ParseTreePatternMatcher m = new ParseTreePatternMatcher(null, null);
assertEquals("[ID, ' = ', expr, ' ;']", m.split("<ID> = <expr> ;").toString());
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestParserExec.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestParserExec.java
index 3066d4c..fc9a62f 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestParserExec.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestParserExec.java
@@ -1,36 +1,12 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
+import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -69,8 +45,12 @@ import static org.junit.Assert.assertTrue;
* Nongreedy loops match as much input as possible while still allowing
* the remaining input to match.
*/
-public class TestParserExec extends BaseTest {
-
+public class TestParserExec extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
/**
* This is a regression test for antlr/antlr4#118.
@@ -86,7 +66,8 @@ public class TestParserExec extends BaseTest {
"ID : 'a'..'z'+ ;\n"+
"INT : '0'..'9'+ ;\n"+
"WS : (' '|'\\t'|'\\n')+ -> skip ;\n";
- String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
+ String result = execParser("T.g4", grammar, "TParser", "TLexer",
+ null, null, "s",
"abc 34", true);
String expecting =
"Decision 0:\n" +
@@ -105,8 +86,8 @@ public class TestParserExec extends BaseTest {
// TODO: port to test framework (can we simplify the Psl grammar?)
@Test public void testFailedPredicateExceptionState() throws Exception {
String grammar = load("Psl.g4", "UTF-8");
- String found = execParser("Psl.g4", grammar, "PslParser", "PslLexer", "floating_constant", " . 234", false);
- assertEquals("", found);
+ String found = execParser("Psl.g4", grammar, "PslParser", "PslLexer", null, null, "floating_constant", " . 234", false);
+ assertEquals(null, found);
assertEquals("line 1:6 rule floating_constant DEC:A floating-point constant cannot have internal white space\n", stderrDuringParse);
}
@@ -145,8 +126,9 @@ public class TestParserExec extends BaseTest {
"ModeTagsLexer");
assertTrue(success);
- String found = execParser("ModeTagsParser.g4", parserGrammar, "ModeTagsParser", "ModeTagsLexer", "file", "", false);
- assertEquals("", found);
+ String found = execParser("ModeTagsParser.g4", parserGrammar, "ModeTagsParser", "ModeTagsLexer",
+ null, null, "file", "", false);
+ assertEquals(null, found);
assertNull(stderrDuringParse);
}
@@ -173,7 +155,8 @@ public class TestParserExec extends BaseTest {
"WS : [ \\t\\n\\r]+ -> skip ; // toss out all whitespace\n";
String input = "2 9 10 3 1 2 3";
- String found = execParser("Data.g4", grammar, "DataParser", "DataLexer", "file", input, false);
+ String found = execParser("Data.g4", grammar, "DataParser", "DataLexer",
+ null, null, "file", input, false);
assertEquals("6\n", found);
assertNull(stderrDuringParse);
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestParserInterpreter.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestParserInterpreter.java
index 04abbcc..2a8952f 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestParserInterpreter.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestParserInterpreter.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2013 Terence Parr
- * Copyright (c) 2013 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -35,15 +11,21 @@ import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.LexerInterpreter;
import org.antlr.v4.runtime.ParserInterpreter;
import org.antlr.v4.runtime.tree.ParseTree;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
-public class TestParserInterpreter extends BaseTest {
+public class TestParserInterpreter extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testEmptyStartRule() throws Exception {
LexerGrammar lg = new LexerGrammar(
"lexer grammar L;\n" +
@@ -356,7 +338,6 @@ public class TestParserInterpreter extends BaseTest {
CommonTokenStream tokens = new CommonTokenStream(lexEngine);
ParserInterpreter parser = g.createParserInterpreter(tokens);
ParseTree t = parser.parse(g.rules.get(startRule).index);
- System.out.println("parse tree: "+t.toStringTree(parser));
assertEquals(expectedParseTree, t.toStringTree(parser));
return t;
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestParserProfiler.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestParserProfiler.java
index f1b0160..e18aa75 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestParserProfiler.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestParserProfiler.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2014 Terence Parr
- * Copyright (c) 2014 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -36,10 +12,10 @@ import org.antlr.v4.runtime.LexerInterpreter;
import org.antlr.v4.runtime.ParserInterpreter;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.atn.DecisionInfo;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
import org.antlr.v4.tool.Rule;
+import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -48,12 +24,13 @@ import java.util.Arrays;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("unused")
-public class TestParserProfiler extends BaseTest {
+public class TestParserProfiler extends BaseJavaToolTest {
LexerGrammar lg;
+ @Before
@Override
- public void setUp() throws Exception {
- super.setUp();
+ public void testSetUp() throws Exception {
+ super.testSetUp();
lg = new LexerGrammar(
"lexer grammar L;\n" +
"WS : [ \\r\\t\\n]+ -> channel(HIDDEN) ;\n" +
@@ -238,7 +215,7 @@ public class TestParserProfiler extends BaseTest {
"PLUS : '+' ;\n" +
"MULT : '*' ;\n";
- String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
+ String found = execParser("T.g4", grammar, "TParser", "TLexer", null, null, "s",
"xyz;abc;z.q", false, true);
String expecting =
"[{decision=0, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=6, SLL_ATNTransitions=4, " +
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestPerformance.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestPerformance.java
index 990cac6..70ee764 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestPerformance.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestPerformance.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -63,9 +39,10 @@ import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.antlr.v4.runtime.tree.TerminalNode;
-import org.antlr.v4.test.runtime.java.BaseTest;
-import org.antlr.v4.test.runtime.java.ErrorQueue;
+import org.antlr.v4.test.runtime.BaseRuntimeTest;
+import org.antlr.v4.test.runtime.ErrorQueue;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import java.io.File;
@@ -107,7 +84,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@SuppressWarnings("unused")
-public class TestPerformance extends BaseTest {
+public class TestPerformance extends BaseJavaToolTest {
/**
* Parse all java files under this package within the JDK_SOURCE_ROOT
* (environment variable or property defined on the Java command line).
@@ -408,6 +385,12 @@ public class TestPerformance extends BaseTest {
private final AtomicIntegerArray tokenCount = new AtomicIntegerArray(PASSES);
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test
@org.junit.Ignore
public void compileJdk() throws IOException, InterruptedException, ExecutionException {
@@ -699,7 +682,7 @@ public class TestPerformance extends BaseTest {
}
@Override
- protected void eraseTempDir() {
+ public void eraseTempDir() {
if (DELETE_TEMP_FILES) {
super.eraseTempDir();
}
@@ -1954,8 +1937,7 @@ public class TestPerformance extends BaseTest {
"\n" +
"rule_%d_%d : EOF;\n";
- System.out.println("dir "+tmpdir);
- mkdir(tmpdir);
+ BaseRuntimeTest.mkdir(tmpdir);
long startTime = System.nanoTime();
@@ -1970,7 +1952,7 @@ public class TestPerformance extends BaseTest {
}
}
- ErrorQueue equeue = antlr("Level_0_1.g4", false);
+ ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "Level_0_1.g4", false);
Assert.assertTrue(equeue.errors.isEmpty());
long endTime = System.nanoTime();
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestScopeParsing.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestScopeParsing.java
index 3bcfa06..6c8f589 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestScopeParsing.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestScopeParsing.java
@@ -1,68 +1,102 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
+import org.antlr.v4.misc.Utils;
import org.antlr.v4.parse.ScopeParser;
-import org.antlr.v4.test.runtime.java.BaseTest;
+import org.antlr.v4.tool.Attribute;
import org.antlr.v4.tool.Grammar;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
import static org.junit.Assert.assertEquals;
-public class TestScopeParsing extends BaseTest {
- String[] argPairs = {
- "", "{}",
- " ", "{}",
- "int i", "{i=int i}",
- "int[] i, int j[]", "{i=int[] i, j=int [] j}",
- "Map<A,B>[] i, int j[]", "{i=Map<A,B>[] i, j=int [] j}",
- "Map<A,List<B>>[] i", "{i=Map<A,List<B>>[] i}",
+@RunWith(Parameterized.class)
+public class TestScopeParsing extends BaseJavaToolTest {
+ static String[] argPairs = {
+ "", "",
+ " ", "",
+ "int i", "i:int",
+ "int[] i, int j[]", "i:int[], j:int []",
+ "Map<A,B>[] i, int j[]", "i:Map<A,B>[], j:int []",
+ "Map<A,List<B>>[] i", "i:Map<A,List<B>>[]",
"int i = 34+a[3], int j[] = new int[34]",
- "{i=int i= 34+a[3], j=int [] j= new int[34]}",
- "char *foo32[3] = {1,2,3}", "{3=char *foo32[] 3= {1,2,3}}",
- "String[] headers", "{headers=String[] headers}",
+ "i:int=34+a[3], j:int []=new int[34]",
+ "char *[3] foo = {1,2,3}", "foo:char *[3]={1,2,3}", // not valid C really, C is "type name" however so this is cool (this was broken in 4.5 anyway)
+ "String[] headers", "headers:String[]",
+
+ // C++
+ "std::vector<std::string> x", "x:std::vector<std::string>", // yuck. Don't choose :: as the : of a declaration
// python/ruby style
- "i", "{i=null i}",
- "i,j", "{i=null i, j=null j}",
- "i,j, k", "{i=null i, j=null j, k=null k}",
+ "i", "i",
+ "i,j", "i, j",
+ "i\t,j, k", "i, j, k",
+
+ // swift style
+ "x: int", "x:int",
+ "x :int", "x:int",
+ "x:int", "x:int",
+ "x:int=3", "x:int=3",
+ "r:Rectangle=Rectangle(fromLength: 6, fromBreadth: 12)", "r:Rectangle=Rectangle(fromLength: 6, fromBreadth: 12)",
+ "p:pointer to int", "p:pointer to int",
+ "a: array[3] of int", "a:array[3] of int",
+ "a \t:\tfunc(array[3] of int)", "a:func(array[3] of int)",
+ "x:int, y:float", "x:int, y:float",
+ "x:T?, f:func(array[3] of int), y:int", "x:T?, f:func(array[3] of int), y:int",
+
+ // go is postfix type notation like "x int" but must use either "int x" or "x:int" in [...] actions
+ "float64 x = 3", "x:float64=3",
+ "map[string]int x", "x:map[string]int",
};
- @Test public void testArgs() throws Exception {
- for (int i = 0; i < argPairs.length; i+=2) {
- String input = argPairs[i];
- String expected = argPairs[i+1];
- Grammar dummy = new Grammar("grammar T; a:'a';");
- String actual = ScopeParser.parseTypedArgList(null, input, dummy).attributes.toString();
- assertEquals(expected, actual);
- }
+ String input;
+ String output;
+
+ public TestScopeParsing(String input, String output) {
+ this.input = input;
+ this.output = output;
+ }
+
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
+ @Test
+ public void testArgs() throws Exception {
+ Grammar dummy = new Grammar("grammar T; a:'a';");
+
+ LinkedHashMap<String, Attribute> attributes = ScopeParser.parseTypedArgList(null, input, dummy).attributes;
+ List<String> out = new ArrayList<>();
+ for (String arg : attributes.keySet()) {
+ Attribute attr = attributes.get(arg);
+ out.add(attr.toString());
+ }
+ String actual = Utils.join(out.toArray(), ", ");
+ assertEquals(output, actual);
}
+
+ @Parameterized.Parameters(name="{0}")
+ public static Collection<Object[]> getAllTestDescriptors() {
+ List<Object[]> tests = new ArrayList<>();
+ for (int i = 0; i < argPairs.length; i+=2) {
+ String arg = argPairs[i];
+ String output = argPairs[i+1];
+ tests.add(new Object[]{arg,output});
+ }
+ return tests;
+ }
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java
index 1c68ba3..6d56775 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java
@@ -1,44 +1,20 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.LexerGrammar;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/** */
-public class TestSymbolIssues extends BaseTest {
+public class TestSymbolIssues extends BaseJavaToolTest {
static String[] A = {
// INPUT
"grammar A;\n" +
@@ -64,7 +40,7 @@ public class TestSymbolIssues extends BaseTest {
"warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:10:20: implicit definition of token Y in parser\n" +
"warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:11:4: implicit definition of token FJKD in parser\n" +
"error(" + ErrorType.RULE_HAS_NO_ARGS.code + "): A.g4:9:37: rule b has no defined parameters\n" +
- "error(" + ErrorType.MISSING_RULE_ARGS.code + "): A.g4:10:31: missing arguments(s) on rule reference: a\n"
+ "error(" + ErrorType.MISSING_RULE_ARGS.code + "): A.g4:10:31: missing argument(s) on rule reference: a\n"
};
static String[] B = {
@@ -130,6 +106,12 @@ public class TestSymbolIssues extends BaseTest {
"error(" + ErrorType.MODE_CONFLICTS_WITH_TOKEN.code + "): F.g4:3:0: mode M1 conflicts with token with same name\n"
};
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testA() { super.testErrors(A, false); }
@Test public void testB() { super.testErrors(B, false); }
@Test public void testD() { super.testErrors(D, false); }
@@ -223,4 +205,136 @@ public class TestSymbolIssues extends BaseTest {
testErrors(test, false);
}
+
+ // https://github.com/antlr/antlr4/issues/1411
+ @Test public void testWrongIdForTypeChannelModeCommand() throws Exception {
+ String[] test = {
+ "lexer grammar L;\n" +
+ "tokens { TOKEN1 }\n" +
+ "channels { CHANNEL1 }\n" +
+ "TOKEN: 'asdf' -> type(CHANNEL1), channel(MODE1), mode(TOKEN1);\n" +
+ "mode MODE1;\n" +
+ "MODE1_TOKEN: 'qwer';",
+
+ "error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_TOKEN_NAME.code + "): L.g4:4:22: CHANNEL1 is not a recognized token name\n" +
+ "error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME.code + "): L.g4:4:41: MODE1 is not a recognized channel name\n" +
+ "error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_MODE_NAME.code + "): L.g4:4:54: TOKEN1 is not a recognized mode name\n"
+ };
+
+ testErrors(test, false);
+ }
+
+ // https://github.com/antlr/antlr4/issues/1388
+ @Test public void testDuplicatedCommands() throws Exception {
+ String[] test = {
+ "lexer grammar Lexer;\n" +
+ "channels { CHANNEL1, CHANNEL2 }\n" +
+ "tokens { TEST1, TEST2 }\n" +
+ "TOKEN: 'a' -> mode(MODE1), mode(MODE2);\n" +
+ "TOKEN1: 'b' -> pushMode(MODE1), mode(MODE2);\n" +
+ "TOKEN2: 'c' -> pushMode(MODE1), pushMode(MODE2); // pushMode is not duplicate\n" +
+ "TOKEN3: 'd' -> popMode, popMode; // popMode is not duplicate\n" +
+ "mode MODE1;\n" +
+ "MODE1_TOKEN: 'e';\n" +
+ "mode MODE2;\n" +
+ "MODE2_TOKEN: 'f';\n" +
+ "MODE2_TOKEN1: 'g' -> type(TEST1), type(TEST2);\n" +
+ "MODE2_TOKEN2: 'h' -> channel(CHANNEL1), channel(CHANNEL2), channel(DEFAULT_TOKEN_CHANNEL);",
+
+ "warning(" + ErrorType.DUPLICATED_COMMAND.code + "): Lexer.g4:4:27: duplicated command mode\n" +
+ "warning(" + ErrorType.DUPLICATED_COMMAND.code + "): Lexer.g4:12:34: duplicated command type\n" +
+ "warning(" + ErrorType.DUPLICATED_COMMAND.code + "): Lexer.g4:13:40: duplicated command channel\n" +
+ "warning(" + ErrorType.DUPLICATED_COMMAND.code + "): Lexer.g4:13:59: duplicated command channel\n"
+ };
+
+ testErrors(test, false);
+ }
+
+ // https://github.com/antlr/antlr4/issues/1388
+ @Test public void testIncompatibleCommands() throws Exception {
+ String[] test = {
+ "lexer grammar L;\n" +
+ "channels { CHANNEL1 }\n" +
+ "tokens { TYPE1 }\n" +
+ "// Incompatible\n" +
+ "T00: 'a00' -> skip, more;\n" +
+ "T01: 'a01' -> skip, type(TYPE1);\n" +
+ "T02: 'a02' -> skip, channel(CHANNEL1);\n" +
+ "T03: 'a03' -> more, type(TYPE1);\n" +
+ "T04: 'a04' -> more, channel(CHANNEL1);\n" +
+ "T05: 'a05' -> more, skip;\n" +
+ "T06: 'a06' -> type(TYPE1), skip;\n" +
+ "T07: 'a07' -> type(TYPE1), more;\n" +
+ "T08: 'a08' -> channel(CHANNEL1), skip;\n" +
+ "T09: 'a09' -> channel(CHANNEL1), more;\n" +
+ "// Allowed\n" +
+ "T10: 'a10' -> type(TYPE1), channel(CHANNEL1);\n" +
+ "T11: 'a11' -> channel(CHANNEL1), type(TYPE1);",
+
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:5:20: incompatible commands skip and more\n" +
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:6:20: incompatible commands skip and type\n" +
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:7:20: incompatible commands skip and channel\n" +
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:8:20: incompatible commands more and type\n" +
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:9:20: incompatible commands more and channel\n" +
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:10:20: incompatible commands more and skip\n" +
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:11:27: incompatible commands type and skip\n" +
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:12:27: incompatible commands type and more\n" +
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:13:33: incompatible commands channel and skip\n" +
+ "warning(" + ErrorType.INCOMPATIBLE_COMMANDS.code + "): L.g4:14:33: incompatible commands channel and more\n"
+ };
+
+ testErrors(test, false);
+ }
+
+ // https://github.com/antlr/antlr4/issues/1409
+ @Test public void testLabelsForTokensWithMixedTypes() {
+ String[] test = {
+ "grammar L;\n" +
+ "\n" +
+ "rule1 // Correct (Alternatives)\n" +
+ " : t1 = a #aLabel\n" +
+ " | t1 = b #bLabel\n" +
+ " ;\n" +
+ "rule2 //Incorrect type casting in generated code (RULE_LABEL)\n" +
+ " : t2 = a | t2 = b\n" +
+ " ;\n" +
+ "rule3\n" +
+ " : t3 += a+ b t3 += c+ //Incorrect type casting in generated code (RULE_LIST_LABEL)\n" +
+ " ;\n" +
+ "rule4\n" +
+ " : a t4 = A b t4 = B c // Correct (TOKEN_LABEL)\n" +
+ " ;\n" +
+ "rule5\n" +
+ " : a t5 += A b t5 += B c // Correct (TOKEN_LIST_LABEL)\n" +
+ " ;\n" +
+ "a: A;\n" +
+ "b: B;\n" +
+ "c: C;\n" +
+ "A: 'a';\n" +
+ "B: 'b';\n" +
+ "C: 'c';\n",
+
+ "error(" + ErrorType.LABEL_TYPE_CONFLICT.code + "): L.g4:8:15: label t2=b type mismatch with previous definition: t2=a\n" +
+ "error(" + ErrorType.LABEL_TYPE_CONFLICT.code + "): L.g4:11:17: label t3+=c type mismatch with previous definition: t3+=a\n"
+ };
+
+ testErrors(test, false);
+ }
+
+ @Test public void testCharsCollision() throws Exception {
+ String[] test = {
+ "lexer grammar L;\n" +
+ "TOKEN_RANGE: [aa-f];\n" +
+ "TOKEN_RANGE_2: [A-FD-J];\n" +
+ "TOKEN_RANGE_3: 'Z' | 'K'..'R' | 'O'..'V';\n" +
+ "TOKEN_RANGE_4: 'g'..'l' | [g-l];\n", // Handling in ATNOptimizer.
+
+ "warning(" + ErrorType.CHARACTERS_COLLISION_IN_SET.code + "): L.g4:2:18: chars \"a-f\" used multiple times in set [aa-f]\n" +
+ "warning(" + ErrorType.CHARACTERS_COLLISION_IN_SET.code + "): L.g4:3:18: chars \"D-J\" used multiple times in set [A-FD-J]\n" +
+ "warning(" + ErrorType.CHARACTERS_COLLISION_IN_SET.code + "): L.g4:4:13: chars \"O-V\" used multiple times in set 'Z' | 'K'..'R' | 'O'..'V'\n" +
+ "warning(" + ErrorType.CHARACTERS_COLLISION_IN_SET.code + "): L.g4::: chars \"g-l\" used multiple times in set [g-l]\n"
+ };
+
+ testErrors(test, false);
+ }
}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenPositionOptions.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenPositionOptions.java
index 8a6881d..c6af3ee 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenPositionOptions.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenPositionOptions.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2014 Terence Parr
- * Copyright (c) 2014 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -33,9 +9,9 @@ import org.antlr.runtime.Token;
import org.antlr.v4.misc.Utils;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.misc.IntervalSet;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.ast.GrammarAST;
+import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
@@ -43,7 +19,13 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
-public class TestTokenPositionOptions extends BaseTest {
+public class TestTokenPositionOptions extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testLeftRecursionRewrite() throws Exception {
Grammar g = new Grammar(
"grammar T;\n" +
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenStreamRewriter.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenStreamRewriter.java
deleted file mode 100644
index e2d8061..0000000
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenStreamRewriter.java
+++ /dev/null
@@ -1,909 +0,0 @@
-/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package org.antlr.v4.test.tool;
-
-import org.antlr.v4.runtime.ANTLRInputStream;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.LexerInterpreter;
-import org.antlr.v4.runtime.TokenStreamRewriter;
-import org.antlr.v4.runtime.misc.Interval;
-import org.antlr.v4.test.runtime.java.BaseTest;
-import org.antlr.v4.tool.LexerGrammar;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-public class TestTokenStreamRewriter extends BaseTest {
-
- /** Public default constructor used by TestRig */
- public TestTokenStreamRewriter() {
- }
-
- @Test public void testInsertBeforeIndex0() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream("abc"));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(0, "0");
- String result = tokens.getText();
- String expecting = "0abc";
- assertEquals(expecting, result);
- }
-
- @Test public void testInsertAfterLastIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertAfter(2, "x");
- String result = tokens.getText();
- String expecting = "abcx";
- assertEquals(expecting, result);
- }
-
- @Test public void test2InsertBeforeAfterMiddleIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(1, "x");
- tokens.insertAfter(1, "x");
- String result = tokens.getText();
- String expecting = "axbxc";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceIndex0() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(0, "x");
- String result = tokens.getText();
- String expecting = "xbc";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceLastIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, "x");
- String result = tokens.getText();
- String expecting = "abx";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceMiddleIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(1, "x");
- String result = tokens.getText();
- String expecting = "axc";
- assertEquals(expecting, result);
- }
-
- @Test public void testToStringStartStop() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "ID : 'a'..'z'+;\n" +
- "INT : '0'..'9'+;\n" +
- "SEMI : ';';\n" +
- "MUL : '*';\n" +
- "ASSIGN : '=';\n" +
- "WS : ' '+;\n");
- // Tokens: 0123456789
- // Input: x = 3 * 0;
- String input = "x = 3 * 0;";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(4, 8, "0");
- stream.fill();
-// replace 3 * 0 with 0
-
- String result = tokens.getTokenStream().getText();
- String expecting = "x = 3 * 0;";
- assertEquals(expecting, result);
-
- result = tokens.getText();
- expecting = "x = 0;";
- assertEquals(expecting, result);
-
- result = tokens.getText(Interval.of(0, 9));
- expecting = "x = 0;";
- assertEquals(expecting, result);
-
- result = tokens.getText(Interval.of(4, 8));
- expecting = "0";
- assertEquals(expecting, result);
- }
-
- @Test public void testToStringStartStop2() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "ID : 'a'..'z'+;\n" +
- "INT : '0'..'9'+;\n" +
- "SEMI : ';';\n" +
- "ASSIGN : '=';\n" +
- "PLUS : '+';\n" +
- "MULT : '*';\n" +
- "WS : ' '+;\n");
- // Tokens: 012345678901234567
- // Input: x = 3 * 0 + 2 * 0;
- String input = "x = 3 * 0 + 2 * 0;";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
-
- String result = tokens.getTokenStream().getText();
- String expecting = "x = 3 * 0 + 2 * 0;";
- assertEquals(expecting, result);
-
- tokens.replace(4, 8, "0");
- stream.fill();
-// replace 3 * 0 with 0
- result = tokens.getText();
- expecting = "x = 0 + 2 * 0;";
- assertEquals(expecting, result);
-
- result = tokens.getText(Interval.of(0, 17));
- expecting = "x = 0 + 2 * 0;";
- assertEquals(expecting, result);
-
- result = tokens.getText(Interval.of(4, 8));
- expecting = "0";
- assertEquals(expecting, result);
-
- result = tokens.getText(Interval.of(0, 8));
- expecting = "x = 0";
- assertEquals(expecting, result);
-
- result = tokens.getText(Interval.of(12, 16));
- expecting = "2 * 0";
- assertEquals(expecting, result);
-
- tokens.insertAfter(17, "// comment");
- result = tokens.getText(Interval.of(12, 18));
- expecting = "2 * 0;// comment";
- assertEquals(expecting, result);
-
- result = tokens.getText(Interval.of(0, 8));
- stream.fill();
-// try again after insert at end
- expecting = "x = 0";
- assertEquals(expecting, result);
- }
-
-
- @Test public void test2ReplaceMiddleIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(1, "x");
- tokens.replace(1, "y");
- String result = tokens.getText();
- String expecting = "ayc";
- assertEquals(expecting, result);
- }
-
- @Test public void test2ReplaceMiddleIndex1InsertBefore() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(0, "_");
- tokens.replace(1, "x");
- tokens.replace(1, "y");
- String result = tokens.getText();
- String expecting = "_ayc";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceThenDeleteMiddleIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(1, "x");
- tokens.delete(1);
- String result = tokens.getText();
- String expecting = "ac";
- assertEquals(expecting, result);
- }
-
- @Test public void testInsertInPriorReplace() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(0, 2, "x");
- tokens.insertBefore(1, "0");
- Exception exc = null;
- try {
- tokens.getText();
- }
- catch (IllegalArgumentException iae) {
- exc = iae;
- }
- String expecting = "insert op <InsertBeforeOp@[@1,1:1='b',<2>,1:1]:\"0\"> within boundaries of previous <ReplaceOp@[@0,0:0='a',<1>,1:0]..[@2,2:2='c',<3>,1:2]:\"x\">";
- assertNotNull(exc);
- assertEquals(expecting, exc.getMessage());
- }
-
- @Test public void testInsertThenReplaceSameIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(0, "0");
- tokens.replace(0, "x");
- stream.fill();
-// supercedes insert at 0
- String result = tokens.getText();
- String expecting = "0xbc";
- assertEquals(expecting, result);
- }
-
- @Test public void test2InsertMiddleIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(1, "x");
- tokens.insertBefore(1, "y");
- String result = tokens.getText();
- String expecting = "ayxbc";
- assertEquals(expecting, result);
- }
-
- @Test public void test2InsertThenReplaceIndex0() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(0, "x");
- tokens.insertBefore(0, "y");
- tokens.replace(0, "z");
- String result = tokens.getText();
- String expecting = "yxzbc";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceThenInsertBeforeLastIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, "x");
- tokens.insertBefore(2, "y");
- String result = tokens.getText();
- String expecting = "abyx";
- assertEquals(expecting, result);
- }
-
- @Test public void testInsertThenReplaceLastIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(2, "y");
- tokens.replace(2, "x");
- String result = tokens.getText();
- String expecting = "abyx";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceThenInsertAfterLastIndex() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, "x");
- tokens.insertAfter(2, "y");
- String result = tokens.getText();
- String expecting = "abxy";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceRangeThenInsertAtLeftEdge() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcccba";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, 4, "x");
- tokens.insertBefore(2, "y");
- String result = tokens.getText();
- String expecting = "abyxba";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceRangeThenInsertAtRightEdge() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcccba";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, 4, "x");
- tokens.insertBefore(4, "y");
- stream.fill(); // no effect; within range of a replace
- Exception exc = null;
- try {
- tokens.getText();
- }
- catch (IllegalArgumentException iae) {
- exc = iae;
- }
- String expecting = "insert op <InsertBeforeOp@[@4,4:4='c',<3>,1:4]:\"y\"> within boundaries of previous <ReplaceOp@[@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"x\">";
- assertNotNull(exc);
- assertEquals(expecting, exc.getMessage());
- }
-
- @Test public void testReplaceRangeThenInsertAfterRightEdge() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcccba";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, 4, "x");
- tokens.insertAfter(4, "y");
- String result = tokens.getText();
- String expecting = "abxyba";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceAll() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcccba";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(0, 6, "x");
- String result = tokens.getText();
- String expecting = "x";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceSubsetThenFetch() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcccba";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, 4, "xyz");
- String result = tokens.getText(Interval.of(0, 6));
- String expecting = "abxyzba";
- assertEquals(expecting, result);
- }
-
- @Test public void testReplaceThenReplaceSuperset() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcccba";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, 4, "xyz");
- tokens.replace(3, 5, "foo");
- stream.fill();
-// overlaps, error
- Exception exc = null;
- try {
- tokens.getText();
- }
- catch (IllegalArgumentException iae) {
- exc = iae;
- }
- String expecting = "replace op boundaries of <ReplaceOp@[@3,3:3='c',<3>,1:3]..[@5,5:5='b',<2>,1:5]:\"foo\"> overlap with previous <ReplaceOp@[@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"xyz\">";
- assertNotNull(exc);
- assertEquals(expecting, exc.getMessage());
- }
-
- @Test public void testReplaceThenReplaceLowerIndexedSuperset() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcccba";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, 4, "xyz");
- tokens.replace(1, 3, "foo");
- stream.fill();
-// overlap, error
- Exception exc = null;
- try {
- tokens.getText();
- }
- catch (IllegalArgumentException iae) {
- exc = iae;
- }
- String expecting = "replace op boundaries of <ReplaceOp@[@1,1:1='b',<2>,1:1]..[@3,3:3='c',<3>,1:3]:\"foo\"> overlap with previous <ReplaceOp@[@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"xyz\">";
- assertNotNull(exc);
- assertEquals(expecting, exc.getMessage());
- }
-
- @Test public void testReplaceSingleMiddleThenOverlappingSuperset() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcba";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, 2, "xyz");
- tokens.replace(0, 3, "foo");
- String result = tokens.getText();
- String expecting = "fooa";
- assertEquals(expecting, result);
- }
-
- @Test public void testCombineInserts() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(0, "x");
- tokens.insertBefore(0, "y");
- String result = tokens.getText();
- String expecting = "yxabc";
- assertEquals(expecting, result);
- }
-
- @Test public void testCombine3Inserts() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(1, "x");
- tokens.insertBefore(0, "y");
- tokens.insertBefore(1, "z");
- String result = tokens.getText();
- String expecting = "yazxbc";
- assertEquals(expecting, result);
- }
-
- @Test public void testCombineInsertOnLeftWithReplace() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(0, 2, "foo");
- tokens.insertBefore(0, "z");
- stream.fill();
-// combine with left edge of rewrite
- String result = tokens.getText();
- String expecting = "zfoo";
- assertEquals(expecting, result);
- }
-
- @Test public void testCombineInsertOnLeftWithDelete() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.delete(0, 2);
- tokens.insertBefore(0, "z");
- stream.fill();
-// combine with left edge of rewrite
- String result = tokens.getText();
- String expecting = "z";
- stream.fill();
-// make sure combo is not znull
- assertEquals(expecting, result);
- }
-
- @Test public void testDisjointInserts() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(1, "x");
- tokens.insertBefore(2, "y");
- tokens.insertBefore(0, "z");
- String result = tokens.getText();
- String expecting = "zaxbyc";
- assertEquals(expecting, result);
- }
-
- @Test public void testOverlappingReplace() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(1, 2, "foo");
- tokens.replace(0, 3, "bar");
- stream.fill();
-// wipes prior nested replace
- String result = tokens.getText();
- String expecting = "bar";
- assertEquals(expecting, result);
- }
-
- @Test public void testOverlappingReplace2() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(0, 3, "bar");
- tokens.replace(1, 2, "foo");
- stream.fill();
-// cannot split earlier replace
- Exception exc = null;
- try {
- tokens.getText();
- }
- catch (IllegalArgumentException iae) {
- exc = iae;
- }
- String expecting = "replace op boundaries of <ReplaceOp@[@1,1:1='b',<2>,1:1]..[@2,2:2='c',<3>,1:2]:\"foo\"> overlap with previous <ReplaceOp@[@0,0:0='a',<1>,1:0]..[@3,3:3='c',<3>,1:3]:\"bar\">";
- assertNotNull(exc);
- assertEquals(expecting, exc.getMessage());
- }
-
- @Test public void testOverlappingReplace3() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(1, 2, "foo");
- tokens.replace(0, 2, "bar");
- stream.fill();
-// wipes prior nested replace
- String result = tokens.getText();
- String expecting = "barc";
- assertEquals(expecting, result);
- }
-
- @Test public void testOverlappingReplace4() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(1, 2, "foo");
- tokens.replace(1, 3, "bar");
- stream.fill();
-// wipes prior nested replace
- String result = tokens.getText();
- String expecting = "abar";
- assertEquals(expecting, result);
- }
-
- @Test public void testDropIdenticalReplace() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(1, 2, "foo");
- tokens.replace(1, 2, "foo");
- stream.fill();
-// drop previous, identical
- String result = tokens.getText();
- String expecting = "afooc";
- assertEquals(expecting, result);
- }
-
- @Test public void testDropPrevCoveredInsert() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(1, "foo");
- tokens.replace(1, 2, "foo");
- stream.fill();
-// kill prev insert
- String result = tokens.getText();
- String expecting = "afoofoo";
- assertEquals(expecting, result);
- }
-
- @Test public void testLeaveAloneDisjointInsert() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(1, "x");
- tokens.replace(2, 3, "foo");
- String result = tokens.getText();
- String expecting = "axbfoo";
- assertEquals(expecting, result);
- }
-
- @Test public void testLeaveAloneDisjointInsert2() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abcc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.replace(2, 3, "foo");
- tokens.insertBefore(1, "x");
- String result = tokens.getText();
- String expecting = "axbfoo";
- assertEquals(expecting, result);
- }
-
- @Test public void testInsertBeforeTokenThenDeleteThatToken() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "abc";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(2, "y");
- tokens.delete(2);
- String result = tokens.getText();
- String expecting = "aby";
- assertEquals(expecting, result);
- }
-
- // Test for https://github.com/antlr/antlr4/issues/550
- @Test
- @Ignore
- public void testPreservesOrderOfContiguousInserts() throws Exception {
- LexerGrammar g = new LexerGrammar(
- "lexer grammar T;\n"+
- "A : 'a';\n" +
- "B : 'b';\n" +
- "C : 'c';\n");
- String input = "aa";
- LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
- CommonTokenStream stream = new CommonTokenStream(lexEngine);
- stream.fill();
- TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
- tokens.insertBefore(0, "<b>");
- tokens.insertAfter(0, "</b>");
- tokens.insertBefore(1, "<b>");
- tokens.insertAfter(1, "</b>");
- String result = tokens.getText();
- String expecting = "<b>a</b><b>a</b>"; // fails with <b>a<b></b>a</b>"
- assertEquals(expecting, result);
- }
-
-}
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenTypeAssignment.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenTypeAssignment.java
index 635f15c..c338eec 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenTypeAssignment.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestTokenTypeAssignment.java
@@ -1,37 +1,12 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
import org.antlr.v4.runtime.Token;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
import org.junit.Test;
@@ -45,7 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-public class TestTokenTypeAssignment extends BaseTest {
+public class TestTokenTypeAssignment extends BaseJavaToolTest {
@Test
public void testParserSimpleTokens() throws Exception {
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java
index c411434..639c638 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java
@@ -1,47 +1,27 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
import org.antlr.v4.Tool;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.ErrorType;
+import org.junit.Before;
import org.junit.Test;
-public class TestToolSyntaxErrors extends BaseTest {
+public class TestToolSyntaxErrors extends BaseJavaToolTest {
static String[] A = {
- // INPUT
- "grammar A;\n" +
- "",
- // YIELDS
- "error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no rules\n",
+ // INPUT
+ "grammar A;\n" +
+ "",
+ // YIELDS
+ "error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no rules\n",
+
+ "lexer grammar A;\n" +
+ "",
+ "error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no rules\n",
"A;",
"error(" + ErrorType.SYNTAX_ERROR.code + "): A.g4:1:0: syntax error: 'A' came as a complete surprise to me\n",
@@ -74,6 +54,12 @@ public class TestToolSyntaxErrors extends BaseTest {
"error(" + ErrorType.SYNTAX_ERROR.code + "): A.g4:2:15: syntax error: mismatched input ';' expecting COLON while matching a lexer rule\n",
};
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testA() { super.testErrors(A, true); }
@Test public void testExtraColon() {
@@ -331,6 +317,40 @@ public class TestToolSyntaxErrors extends BaseTest {
super.testErrors(pair, true);
}
+ // Test for https://github.com/antlr/antlr4/issues/1203
+ @Test public void testEpsilonNestedClosureAnalysis() {
+ String grammar =
+ "grammar T;\n"+
+ "s : (a a)* ;\n"+
+ "a : 'foo'* ;\n";
+ String expected =
+ "error(" + ErrorType.EPSILON_CLOSURE.code + "): T.g4:2:0: rule s contains a closure with at least one alternative that can match an empty string\n";
+
+ String[] pair = new String[] {
+ grammar,
+ expected
+ };
+
+ super.testErrors(pair, true);
+ }
+
+ // Test for https://github.com/antlr/antlr4/issues/1203
+ @Test public void testEpsilonOptionalAndClosureAnalysis() {
+ String grammar =
+ "grammar T;\n"+
+ "s : (a a)? ;\n"+
+ "a : 'foo'* ;\n";
+ String expected =
+ "warning(" + ErrorType.EPSILON_OPTIONAL.code + "): T.g4:2:0: rule s contains an optional block with at least one alternative that can match an empty string\n";
+
+ String[] pair = new String[] {
+ grammar,
+ expected
+ };
+
+ super.testErrors(pair, true);
+ }
+
@Test public void testEpsilonOptionalAnalysis() {
String grammar =
"grammar A;\n"
@@ -467,11 +487,39 @@ public class TestToolSyntaxErrors extends BaseTest {
"Error3: '';\n" +
"NotError: ' ';";
String expected =
- "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:2:8: string literals cannot be empty\n" +
- "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:2:16: string literals cannot be empty\n" +
- "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:3:8: string literals cannot be empty\n" +
- "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:4:15: string literals cannot be empty\n" +
- "error(" + ErrorType.EMPTY_STRINGS_NOT_ALLOWED.code + "): T.g4:5:8: string literals cannot be empty\n";
+ "error(" + ErrorType.EMPTY_STRINGS_AND_SETS_NOT_ALLOWED.code + "): T.g4:2:8: string literals and sets cannot be empty: ''\n" +
+ "error(" + ErrorType.EMPTY_STRINGS_AND_SETS_NOT_ALLOWED.code + "): T.g4:2:16: string literals and sets cannot be empty: ''\n" +
+ "error(" + ErrorType.EMPTY_STRINGS_AND_SETS_NOT_ALLOWED.code + "): T.g4:3:8: string literals and sets cannot be empty: ''\n" +
+ "error(" + ErrorType.EMPTY_STRINGS_AND_SETS_NOT_ALLOWED.code + "): T.g4:4:15: string literals and sets cannot be empty: ''\n" +
+ "error(" + ErrorType.EMPTY_STRINGS_AND_SETS_NOT_ALLOWED.code + "): T.g4:5:8: string literals and sets cannot be empty: ''\n";
+
+ String[] pair = new String[] {
+ grammar,
+ expected
+ };
+
+ super.testErrors(pair, true);
+ }
+
+ @Test public void testInvalidCharSetAndRange() {
+ String grammar =
+ "lexer grammar Test;\n" +
+ "INVALID_RANGE: 'GH'..'LM';\n" +
+ "INVALID_RANGE_2: 'F'..'A' | 'Z';\n" +
+ "VALID_STRING_LITERALS: '\\u1234' | '\\t' | [\\-\\]];\n" +
+ "INVALID_CHAR_SET: [f-az][];\n" +
+ "INVALID_CHAR_SET_2: [\\u24\\uA2][\\u24];\n" + //https://github.com/antlr/antlr4/issues/1077
+ "INVALID_CHAR_SET_3: [\\t\\{];";
+
+ String expected =
+ "error(" + ErrorType.INVALID_LITERAL_IN_LEXER_SET.code + "): Test.g4:2:23: multi-character literals are not allowed in lexer sets: 'GH'\n" +
+ "error(" + ErrorType.INVALID_LITERAL_IN_LEXER_SET.code + "): Test.g4:2:29: multi-character literals are not allowed in lexer sets: 'LM'\n" +
+ "error(" + ErrorType.EMPTY_STRINGS_AND_SETS_NOT_ALLOWED.code + "): Test.g4:3:26: string literals and sets cannot be empty: 'F'..'A'\n" +
+ "error(" + ErrorType.EMPTY_STRINGS_AND_SETS_NOT_ALLOWED.code + "): Test.g4:5:23: string literals and sets cannot be empty: [f-a]\n" +
+ "error(" + ErrorType.EMPTY_STRINGS_AND_SETS_NOT_ALLOWED.code + "): Test.g4:5:29: string literals and sets cannot be empty: []\n" +
+ "error(" + ErrorType.INVALID_ESCAPE_SEQUENCE.code + "): Test.g4:6:23: invalid escape sequence\n" +
+ "error(" + ErrorType.INVALID_ESCAPE_SEQUENCE.code + "): Test.g4:6:33: invalid escape sequence\n" +
+ "error(" + ErrorType.INVALID_ESCAPE_SEQUENCE.code + "): Test.g4:7:23: invalid escape sequence\n";
String[] pair = new String[] {
grammar,
@@ -647,8 +695,8 @@ public class TestToolSyntaxErrors extends BaseTest {
"WHITESPACE: [ \\t]+ -> channel(WHITESPACE_CHANNEL);\n";
String expected =
- "warning(" + ErrorType.UNKNOWN_LEXER_CONSTANT.code + "): T.g4:10:35: rule COMMENT contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output\n" +
- "warning(" + ErrorType.UNKNOWN_LEXER_CONSTANT.code + "): T.g4:11:35: rule WHITESPACE contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output\n" +
+ "error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME.code + "): T.g4:10:35: COMMENT_CHANNEL is not a recognized channel name\n" +
+ "error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME.code + "): T.g4:11:35: WHITESPACE_CHANNEL is not a recognized channel name\n" +
"error(" + ErrorType.CHANNELS_BLOCK_IN_COMBINED_GRAMMAR.code + "): T.g4:3:0: custom channels are not supported in combined grammars\n";
String[] pair = { grammar, expected };
@@ -676,7 +724,7 @@ public class TestToolSyntaxErrors extends BaseTest {
// WHITESPACE_CHANNEL and COMMENT_CHANNEL are defined, but NEWLINE_CHANNEL is not
String expected =
- "warning(" + ErrorType.UNKNOWN_LEXER_CONSTANT.code + "): T.g4:10:34: rule NEWLINE contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output\n";
+ "error(" + ErrorType.CONSTANT_VALUE_IS_NOT_A_RECOGNIZED_CHANNEL_NAME.code + "): T.g4:10:34: NEWLINE_CHANNEL is not a recognized channel name\n";
String[] pair = { grammar, expected };
super.testErrors(pair, true);
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestTopologicalSort.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestTopologicalSort.java
index 38a2e60..2c0b596 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestTopologicalSort.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestTopologicalSort.java
@@ -1,36 +1,12 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
import org.antlr.v4.misc.Graph;
-import org.antlr.v4.test.runtime.java.BaseTest;
+import org.junit.Before;
import org.junit.Test;
import java.util.List;
@@ -38,7 +14,13 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
/** Test topo sort in GraphNode. */
-public class TestTopologicalSort extends BaseTest {
+public class TestTopologicalSort extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test
public void testFairlyLargeGraph() throws Exception {
Graph<String> g = new Graph<String>();
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedCharStream.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedCharStream.java
index 52a8a1b..fec0936 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedCharStream.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedCharStream.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -37,8 +13,8 @@ import org.antlr.v4.runtime.IntStream;
import org.antlr.v4.runtime.LexerInterpreter;
import org.antlr.v4.runtime.UnbufferedCharStream;
import org.antlr.v4.runtime.misc.Interval;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.LexerGrammar;
+import org.junit.Before;
import org.junit.Test;
import java.io.Reader;
@@ -47,7 +23,13 @@ import java.io.StringReader;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("unused")
-public class TestUnbufferedCharStream extends BaseTest {
+public class TestUnbufferedCharStream extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testNoChar() throws Exception {
CharStream input = createStream("");
assertEquals(IntStream.EOF, input.LA(1));
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedTokenStream.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedTokenStream.java
index 9ab81b3..5d9795d 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedTokenStream.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestUnbufferedTokenStream.java
@@ -1,31 +1,7 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
@@ -37,8 +13,8 @@ import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenSource;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.UnbufferedTokenStream;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.LexerGrammar;
+import org.junit.Before;
import org.junit.Test;
import java.io.StringReader;
@@ -49,7 +25,13 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("unused")
-public class TestUnbufferedTokenStream extends BaseTest {
+public class TestUnbufferedTokenStream extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testLookahead() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar t;\n"+
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestVocabulary.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestVocabulary.java
index b786e00..b956494 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestVocabulary.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestVocabulary.java
@@ -1,46 +1,27 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2014 Terence Parr
- * Copyright (c) 2014 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.test.tool;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.VocabularyImpl;
-import org.antlr.v4.test.runtime.java.BaseTest;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
/**
*
* @author Sam Harwell
*/
-public class TestVocabulary extends BaseTest {
+public class TestVocabulary extends BaseJavaToolTest {
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
@Test
public void testEmptyVocabulary() {
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestXPath.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestXPath.java
index 7a374ee..7dbd741 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestXPath.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestXPath.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
package org.antlr.v4.test.tool;
import org.antlr.v4.runtime.Lexer;
@@ -7,7 +13,7 @@ import org.antlr.v4.runtime.misc.Pair;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.antlr.v4.runtime.tree.xpath.XPath;
-import org.antlr.v4.test.runtime.java.BaseTest;
+import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
@@ -17,7 +23,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-public class TestXPath extends BaseTest {
+public class TestXPath extends BaseJavaToolTest {
public static final String grammar =
"grammar Expr;\n" +
"prog: func+ ;\n" +
@@ -52,6 +58,12 @@ public class TestXPath extends BaseTest {
"def f(x,y) { x = 3+4; y; ; }\n" +
"def g(x) { return 1+2*x; }\n";
+ @Before
+ @Override
+ public void testSetUp() throws Exception {
+ super.testSetUp();
+ }
+
@Test public void testValidPaths() throws Exception {
boolean ok =
rawGenerateAndBuildRecognizer("Expr.g4", grammar, "ExprParser",