01: package org.antlr.test;
02:
03: import org.antlr.Tool;
04: import org.antlr.codegen.CodeGenerator;
05: import org.antlr.codegen.ActionTranslatorLexer;
06: import org.antlr.tool.*;
07:
08: public class TestMessages extends BaseTest {
09:
10: /** Public default constructor used by TestRig */
11: public TestMessages() {
12: }
13:
14: public void testMessageStringificationIsConsistent()
15: throws Exception {
16: String action = "$other.tree = null;";
17: ErrorQueue equeue = new ErrorQueue();
18: ErrorManager.setErrorListener(equeue);
19: Grammar g = new Grammar("grammar a;\n"
20: + "options { output = AST;}" + "otherrule\n"
21: + " : 'y' ;" + "rule\n" + " : other=otherrule {"
22: + action + "}\n" + " ;");
23: Tool antlr = newTool();
24: CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
25: g.setCodeGenerator(generator);
26: generator.genRecognizer(); // forces load of templates
27: ActionTranslatorLexer translator = new ActionTranslatorLexer(
28: generator, "rule", new antlr.CommonToken(
29: ANTLRParser.ACTION, action), 1);
30: String rawTranslation = translator.translate();
31:
32: int expectedMsgID = ErrorManager.MSG_WRITE_TO_READONLY_ATTR;
33: Object expectedArg = "other";
34: Object expectedArg2 = "tree";
35: GrammarSemanticsMessage expectedMessage = new GrammarSemanticsMessage(
36: expectedMsgID, g, null, expectedArg, expectedArg2);
37: String expectedMessageString = expectedMessage.toString();
38: assertEquals(expectedMessageString, expectedMessage.toString());
39: }
40: }
|