use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_04.
@Test
public void testEnum_04() throws Exception {
String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/4'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName;";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
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(value.getLiteral(), decl.getLiteral().getValue());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_02.
@Test
public void testEnum_02() throws Exception {
String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/2'\n" + "Model: enumValue=MyEnumRule;\n" + "enum MyEnumRule returns MyEnum: Value1;";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/2", pack.getNsURI());
EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
assertNotNull(eEnum);
assertEquals(1, eEnum.getELiterals().size());
EEnumLiteral value = eEnum.getELiterals().get(0);
assertEquals("Value1", value.getName());
assertEquals(0, value.getValue());
assertEquals("Value1", value.getLiteral());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_10.
@Test
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/AbstractEnumRulesTest/TestEnum/10'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName;";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
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());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_11.
@Test
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/AbstractEnumRulesTest/TestEnum/11'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName;";
Grammar grammar = (Grammar) getModelAndExpect(modelAsString, 1);
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("ExistingEnum"), offset);
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_06.
@Test
public void testEnum_06() throws Exception {
String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/6'\n" + "Model: enumValue=MyEnum;\n" + "enum MyEnum: Value1 | Value2='value' | Value3;";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/6", pack.getNsURI());
EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
assertNotNull(eEnum);
assertEquals(3, eEnum.getELiterals().size());
EEnumLiteral value = eEnum.getELiterals().get(0);
assertEquals("Value1", value.getName());
assertEquals(0, value.getValue());
assertEquals("Value1", value.getLiteral());
value = eEnum.getELiterals().get(1);
assertEquals("Value2", value.getName());
assertEquals(1, value.getValue());
assertEquals("value", value.getLiteral());
value = eEnum.getELiterals().get(2);
assertEquals("Value3", value.getName());
assertEquals(2, value.getValue());
assertEquals("Value3", value.getLiteral());
}
Aggregations