aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-03-19 05:48:42 (EDT)
committersefftinge2009-03-19 05:48:42 (EDT)
commit3639004a4a6390af164aab3fe4acf0f4a572f90b (patch)
treeed84337460df2bce9cd0f95fc3a26e51874708fc
parentcb6243c3bf47faff7ce1cea60d2b8b5b9c3ccefb (diff)
downloadorg.eclipse.xtext-3639004a4a6390af164aab3fe4acf0f4a572f90b.zip
org.eclipse.xtext-3639004a4a6390af164aab3fe4acf0f4a572f90b.tar.gz
org.eclipse.xtext-3639004a4a6390af164aab3fe4acf0f4a572f90b.tar.bz2
enum rule: ensure consistency for overridden rules
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/enumrules/GrammarParserTest.java41
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java1
2 files changed, 42 insertions, 0 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/enumrules/GrammarParserTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/enumrules/GrammarParserTest.java
index 1cc844f..4d86af3 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/enumrules/GrammarParserTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/enumrules/GrammarParserTest.java
@@ -219,4 +219,45 @@ public class GrammarParserTest extends AbstractEnumRulesTest {
int offset = diag.getOffset();
assertEquals(modelAsString.lastIndexOf("Absent"), offset);
}
+
+ public void testEnum_10() throws Exception {
+ String modelAsString =
+ "grammar TestLanguage with org.eclipse.xtext.enumrules.EnumRulesTestLanguage\n" +
+ "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" +
+ "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/EnumRulesTest/TestEnum/10'\n" +
+ "Model: enumValue=ExistingEnum;\n" +
+ "enum ExistingEnum: SameName;";
+ Grammar grammar = (Grammar) getModel(modelAsString);
+ assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
+ EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
+ assertEquals("http://www.eclipse.org/2009/tmf/xtext/EnumRulesTestLanguage/imported", pack.getNsURI());
+ EEnum eEnum = (EEnum) pack.getEClassifier("ExistingEnum");
+ assertNotNull(eEnum);
+ assertEquals(3, eEnum.getELiterals().size());
+ EEnumLiteral value = eEnum.getELiterals().get(0);
+ assertEquals(ExistingEnum.SAME_NAME.getName(), value.getName());
+ assertEquals(ExistingEnum.SAME_NAME.getValue(), value.getValue());
+ assertEquals(ExistingEnum.SAME_NAME.getLiteral(), value.getLiteral());
+
+ EnumRule rule = (EnumRule) grammar.getRules().get(1);
+ assertEquals(eEnum, rule.getType().getClassifier());
+ EnumLiteralDeclaration decl = (EnumLiteralDeclaration) rule.getAlternatives();
+ assertEquals(value, decl.getEnumLiteral());
+ assertNotNull(decl.getLiteral());
+ assertEquals("SameName", decl.getLiteral().getValue());
+ }
+
+ public void testEnum_11() throws Exception {
+ String modelAsString =
+ "grammar TestLanguage with org.eclipse.xtext.enumrules.EnumRulesTestLanguage\n" +
+ "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore' as existing\n" +
+ "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/EnumRulesTest/TestEnum/11'\n" +
+ "Model: enumValue=ExistingEnum;\n" +
+ "enum ExistingEnum: SameName;";
+ Grammar grammar = (Grammar) getModel(modelAsString);
+ assertEquals(grammar.eResource().getErrors().toString(), 1, grammar.eResource().getErrors().size());
+ TransformationDiagnostic diag = (TransformationDiagnostic) grammar.eResource().getErrors().get(0);
+ int offset = diag.getOffset();
+ assertEquals(modelAsString.lastIndexOf("enum ExistingEnum"), offset);
+ }
}
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 773b147..9cc07b3 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
@@ -23,6 +23,7 @@ public class PluginTestSuite {
suite.addTestSuite(org.eclipse.xtext.crossrefs.LinkingErrorTest.class);
suite.addTestSuite(org.eclipse.xtext.enumrules.ParserTest.Antlr.class);
suite.addTestSuite(org.eclipse.xtext.enumrules.ParserTest.Packrat.class);
+ suite.addTestSuite(org.eclipse.xtext.enumrules.GrammarParserTest.class);
suite.addTestSuite(org.eclipse.xtext.generator.ParserTest.class);
suite.addTestSuite(org.eclipse.xtext.generator.ManifestMergerTest.class);
suite.addTestSuite(org.eclipse.xtext.generator.resource.ResourceTest.class);