Move what used to be AfterGrammar template from a test in legacy runtime tests to tool test and remove from runtime test functionality.

This commit is contained in:
parrt 2016-11-17 13:05:34 -08:00
parent 125a509e4e
commit c5acec19db
6 changed files with 54 additions and 28 deletions

View File

@ -125,9 +125,9 @@ public abstract class BaseRuntimeTest {
descriptor.getInput(),
descriptor.showDiagnosticErrors()
);
if ( delegate instanceof RuntimeTestAssert ) {
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
if ( delegate instanceof SpecialRuntimeTestAssert ) {
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
}
else {
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
@ -166,10 +166,10 @@ public abstract class BaseRuntimeTest {
grammar = grammarST.render();
String found = delegate.execLexer(grammarName+".g4", grammar, grammarName, descriptor.getInput(), descriptor.showDFA());
if ( delegate instanceof RuntimeTestAssert ) {
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
if ( delegate instanceof SpecialRuntimeTestAssert ) {
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
}
else {
assertEquals(descriptor.getOutput(), found);

View File

@ -36,9 +36,6 @@ public interface RuntimeTestDescriptor {
/** The rule at which parsing should start */
String getStartRule(); // TODO: alter tests to use same default start rule?
/** Initialization code */
//String getAfterGrammar(); // TODO: only a few use. make part of testrig or rename?
/** For lexical tests, dump the DFA of the default lexer mode to stdout */
boolean showDFA();

View File

@ -3,6 +3,6 @@ package org.antlr.v4.test.runtime;
/** This interface acts like a tag on a Base*Test class that wants
* to use its own assertEquals() instead of jUnit's.
*/
public interface RuntimeTestAssert {
public interface SpecialRuntimeTestAssert {
void assertEqualStrings(String expected, String actual);
}

View File

@ -36,8 +36,8 @@ import org.antlr.v4.runtime.TokenSource;
import org.antlr.v4.runtime.WritableToken;
import org.antlr.v4.runtime.misc.Utils;
import org.antlr.v4.test.runtime.ErrorQueue;
import org.antlr.v4.test.runtime.RuntimeTestAssert;
import org.antlr.v4.test.runtime.RuntimeTestSupport;
import org.antlr.v4.test.runtime.SpecialRuntimeTestAssert;
import org.antlr.v4.tool.ANTLRMessage;
import org.antlr.v4.tool.DefaultToolListener;
import org.antlr.v4.tool.GrammarSemanticsMessage;
@ -79,7 +79,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class BaseCSharpTest implements RuntimeTestSupport, RuntimeTestAssert {
public class BaseCSharpTest implements RuntimeTestSupport, SpecialRuntimeTestAssert {
public static final String newline = System.getProperty("line.separator");
public static final String pathSep = System.getProperty("path.separator");

View File

@ -96,21 +96,6 @@ public class CompositeParsersDescriptors {
public String startRule = "s";
public String grammarName = "M";
/**
writeFile(tmpdir, "M.g4", grammar);
ErrorQueue equeue = new ErrorQueue();
Grammar g = new Grammar(tmpdir+"/M.g4", grammar, 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());
*/
@CommentHasStringValue
public String afterGrammar;
/**
// The lexer will create rules to match letters a, b, c.
// The associated token types A, B, C must have the same value

View File

@ -72,6 +72,50 @@ public class TestCompositeGrammars extends BaseJavaTest {
assertEquals(equeue.size(), 0);
}
@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";
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" +