Search in sources :

Example 96 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method testBug_272566_2.

@Test
public void testBug_272566_2() throws Exception {
    String grammar = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model:\n" + "   test=Test\n" + ";\n" + "\n" + "Test:\n" + "   'keyword' FooBar name=ID\n" + ";\n" + "FooBar:\n" + "\t'zonk' WS WS INT WS;\n";
    XtextResource resource = getResourceFromString(grammar);
    Assert.assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 97 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method testBug_287550_01.

@Test
public void testBug_287550_01() throws Exception {
    String grammar = "grammar language with org.eclipse.xtext.common.Terminals\n" + "generate myDsl 'http://example.xtext.org/MyDsl'\n" + "Model: Left | Right;\n" + "Left: Delegate;\n" + "Right returns Model: Delegate '=';\n" + "Delegate returns Left: value=ID;\n";
    XtextResource resource = getResourceFromString(grammar);
    Assert.assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 98 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method testEclipseIssue1547.

@Test
public void testEclipseIssue1547() throws Exception {
    String grammarAsString = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate myDsl 'uri'\n" + "Model: element=Element;\n" + "enum Element : //das ist ein test\n^false='false' | true='true';\n";
    XtextResource resource = getResourceFromString(grammarAsString);
    Grammar g = (Grammar) resource.getContents().get(0);
    EnumRule enumRule = (EnumRule) g.getRules().get(1);
    EnumLiteralDeclaration eld1 = (EnumLiteralDeclaration) ((Alternatives) enumRule.getAlternatives()).getElements().get(0);
    EnumLiteralDeclaration eld2 = (EnumLiteralDeclaration) ((Alternatives) enumRule.getAlternatives()).getElements().get(1);
    Assert.assertEquals("false", eld1.getEnumLiteral().getName());
    Assert.assertEquals("true", eld2.getEnumLiteral().getName());
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) EnumLiteralDeclaration(org.eclipse.xtext.EnumLiteralDeclaration) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) Alternatives(org.eclipse.xtext.Alternatives) Test(org.junit.Test)

Example 99 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method testContainmentVsReference_05.

@Test
public void testContainmentVsReference_05() throws Exception {
    String grammar = "grammar test with org.eclipse.xtext.common.Terminals import 'http://www.eclipse.org/emf/2002/Ecore' EReference: name=ID eContainingClass=[EClass];";
    XtextResource resource = getResourceFromStringAndExpect(grammar, 1);
    Assert.assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 100 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.

the class Xtext2EcoreTransformerTest method testContainmentVsReference_01.

@Test
public void testContainmentVsReference_01() throws Exception {
    String grammar = "grammar test with org.eclipse.xtext.common.Terminals import 'http://www.eclipse.org/emf/2002/Ecore' EClass: name=ID eSuperTypes+=EClass;";
    XtextResource resource = getResourceFromStringAndExpect(grammar, 1);
    Assert.assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

XtextResource (org.eclipse.xtext.resource.XtextResource)627 Test (org.junit.Test)367 Resource (org.eclipse.emf.ecore.resource.Resource)107 EObject (org.eclipse.emf.ecore.EObject)99 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)67 StringInputStream (org.eclipse.xtext.util.StringInputStream)67 URI (org.eclipse.emf.common.util.URI)62 Diagnostic (org.eclipse.emf.common.util.Diagnostic)55 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)55 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)46 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)40 Grammar (org.eclipse.xtext.Grammar)32 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)31 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)30 IFile (org.eclipse.core.resources.IFile)29 Issue (org.eclipse.xtext.validation.Issue)29 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)28 List (java.util.List)26 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)26 INode (org.eclipse.xtext.nodemodel.INode)23