summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-03-26 11:55:24 (EDT)
committer sefftinge2009-03-26 11:55:24 (EDT)
commit6af41f299283432ec77f6904b6a4bd3f052311e7 (patch)
tree63df36d75b2760fd7cb84fada1f1f07d9bb8f4fb
parent79db19ed047eb23a0acdc1095d809f6f3b75fdb0 (diff)
downloadorg.eclipse.xtext-6af41f299283432ec77f6904b6a4bd3f052311e7.zip
org.eclipse.xtext-6af41f299283432ec77f6904b6a4bd3f052311e7.tar.gz
org.eclipse.xtext-6af41f299283432ec77f6904b6a4bd3f052311e7.tar.bz2
Fix: https://bugs.eclipse.org/bugs/show_bug.cgi?id=270115
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java1
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/TerminalRuleToLexerBodyTest.java53
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
index 9cc07b3..8db9d47 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
@@ -39,6 +39,7 @@ public class PluginTestSuite {
suite.addTestSuite(org.eclipse.xtext.parser.PartialParserTest.class);
suite.addTestSuite(org.eclipse.xtext.parser.PartialParsingPerformanceTest.class);
suite.addTestSuite(org.eclipse.xtext.parser.PartialParsingPointerTest.class);
+ suite.addTestSuite(org.eclipse.xtext.parser.TerminalRuleToLexerBodyTest.class);
suite.addTestSuite(org.eclipse.xtext.parser.XtextGrammarComparingTest.class);
suite.addTestSuite(org.eclipse.xtext.parser.XtextParserBugsTest.class);
suite.addTestSuite(org.eclipse.xtext.parser.XtextParserTest.class);
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/TerminalRuleToLexerBodyTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/TerminalRuleToLexerBodyTest.java
new file mode 100644
index 0000000..3e3b82a
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/TerminalRuleToLexerBodyTest.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2009 itemis AG (http://www.itemis.eu) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.xtext.parser;
+
+import org.eclipse.xtext.Grammar;
+import org.eclipse.xtext.GrammarUtil;
+import org.eclipse.xtext.TerminalRule;
+import org.eclipse.xtext.XtextStandaloneSetup;
+import org.eclipse.xtext.junit.AbstractXtextTests;
+
+import de.itemis.xtext.antlr.TerminalRuleToLexerBody;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public class TerminalRuleToLexerBodyTest extends AbstractXtextTests {
+
+ private Grammar grammar;
+ private TerminalRule adaString;
+ private TerminalRule workaroundString;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ with(XtextStandaloneSetup.class);
+ String model = "grammar foo\n" +
+ "generate fooModel 'uri' as foo\n" +
+ "import 'http://www.eclipse.org/emf/2002/Ecore' as ecore\n" +
+ "Model returns foo::Model: name=ADA_STRING\n;" +
+ "terminal ADA_STRING: '\"' ((!'\"')|'\"\"')* '\"'\n;" +
+ "terminal WORKAROUND_STRING: '\"' ((!'\"')|'\"''\"')* '\"'\n;";
+ grammar = (Grammar) getModel(model);
+ adaString = (TerminalRule) GrammarUtil.findRuleForName(grammar, "ADA_STRING");
+ workaroundString = (TerminalRule) GrammarUtil.findRuleForName(grammar, "WORKAROUND_STRING");
+ }
+
+ public void testToLexerBody_01() {
+ String ada = TerminalRuleToLexerBody.toLexerBody(adaString);
+ String expectation = "'\"' (~('\"')|'\"\"')* '\"'"; // '"' (~('"')|'""')* '"'
+ assertEquals(expectation, ada);
+ }
+
+ public void testToLexerBody_02() {
+ String workaround = TerminalRuleToLexerBody.toLexerBody(workaroundString);
+ String expectation = "'\"' (~('\"')|'\"' '\"')* '\"'"; // '"' (~('"')|'"' '"')* '"'
+ assertEquals(expectation, workaround);
+ }
+}