summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Eysholdt2011-08-09 11:00:54 (EDT)
committerEd Merks2011-08-09 11:01:47 (EDT)
commitbcb6ced01df3f0ee885b00271c8191e9b2a80abc (patch)
tree2e38fec5401d2ca0adcd7a9c5e424d819271f926
parent1c842b1500c36155c0949fe86d0761c37c21a940 (diff)
downloadorg.eclipse.emf-bcb6ced01df3f0ee885b00271c8191e9b2a80abc.zip
org.eclipse.emf-bcb6ced01df3f0ee885b00271c8191e9b2a80abc.tar.gz
org.eclipse.emf-bcb6ced01df3f0ee885b00271c8191e9b2a80abc.tar.bz2
updated tests
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/EObjectFormatter.java2
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore6
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore4
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java41
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/Annotations.xcore11
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/ClassExtends.xcore30
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/XcoreScopingTest.java19
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore9
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/XcoreValidationTest.java57
9 files changed, 87 insertions, 92 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/EObjectFormatter.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/EObjectFormatter.java
index f98a674..1f02877 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/EObjectFormatter.java
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/EObjectFormatter.java
@@ -49,6 +49,8 @@ public class EObjectFormatter implements Function<EObject, String>
public String format(EObject object)
{
+ if (object == null)
+ return "null";
StringBuilder result = new StringBuilder();
result.append(object.eClass().getName());
result.append(" {");
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore
index 3d0aac9..6795b2e 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenFeatures1.xcore
@@ -1,8 +1,10 @@
package foo
+// XPECT noValidationErrors
+
class X
{
- /* XPECT gen ---
+ /* XPECT genBase at x ---
GenFeature {
notify = 'false'
createChild = 'false'
@@ -13,7 +15,7 @@ class X
--- */
refers X x opposite y
- /* XPECT gen ---
+ /* XPECT genBase at y ---
GenFeature {
notify = 'false'
createChild = 'false'
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore
index 06e8eda..b9497f1 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/GenPackage1.xcore
@@ -1,4 +1,6 @@
-/* XPECT gen ---
+// XPECT noValidationErrors
+
+/* XPECT genBase ---
GenPackage {
prefix = 'Foo'
disposableProviderFactory = 'true'
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java
index 2f4ae1c..cfed586 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/genmodel/XcoreGenModelTest.java
@@ -1,58 +1,37 @@
package org.eclipse.emf.ecore.xcore.tests.genmodel;
-import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xcore.XNamedElement;
import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
import org.eclipse.emf.ecore.xcore.tests.EObjectFormatter;
import org.eclipse.xtext.junit4.InjectWith;
-import org.eclipse.xtext.junit4.parameterized.ParameterizedXtextRunner;
+import org.eclipse.xtext.junit4.parameterized.AbstractParameterizedXtextTest;
import org.eclipse.xtext.junit4.parameterized.ResourceURIs;
-import org.eclipse.xtext.nodemodel.ILeafNode;
-import org.eclipse.xtext.nodemodel.INode;
-import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
-import org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator;
+import org.eclipse.xtext.resource.XtextResource;
import org.junit.Test;
-import org.junit.runner.RunWith;
import com.google.inject.Inject;
@InjectWith(XcoreInjectorProvider.class)
-@RunWith(ParameterizedXtextRunner.class)
@ResourceURIs(baseDir = "src/org/eclipse/emf/ecore/xcore/tests/genmodel", fileExtensions = "xcore")
-public class XcoreGenModelTest
+public class XcoreGenModelTest extends AbstractParameterizedXtextTest
{
- protected String expected;
- protected INode leaf;
-
- public XcoreGenModelTest(ILeafNode leaf, String expected)
+ public XcoreGenModelTest(XtextResource resource, int offset, String[] params)
{
- super();
- this.leaf = leaf;
- NodeIterator ni = new NodeIterator(leaf);
- while (ni.hasNext())
- {
- INode n = ni.next();
- if (n instanceof ILeafNode && !((ILeafNode) n).isHidden())
- {
- this.leaf = n;
- break;
- }
- }
- this.expected = expected;
+ super(resource, offset, params);
}
@Inject
- private XcoreMapper mapper = new XcoreMapper();
+ private XcoreMapper mapper;
@Test
- public String gen()
+ public String genBase()
{
- EObject obj = NodeModelUtils.findActualSemanticObjectFor(leaf);
- EcoreUtil.resolveAll(obj.eResource());
- EObject gen = mapper.getGen((XNamedElement) obj);
+ EcoreUtil.resolveAll(resource);
+ GenBase gen = mapper.getGen((XNamedElement) getEObjectAtOffset());
return new EObjectFormatter().resolveCrossReferences().format(gen);
}
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/Annotations.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/Annotations.xcore
new file mode 100644
index 0000000..67779cd
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/Annotations.xcore
@@ -0,0 +1,11 @@
+// XPECT noValidationErrors
+
+package foo
+
+annotation "http://example.org/" as myAnnotation
+
+// FIXME: this scope should not contain qualified names of annotations since they are only visible locally.
+// __XPECT scopeAllElements at myAnnotation --> myAnnotation
+@myAnnotation
+class Class1 {}
+
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/ClassExtends.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/ClassExtends.xcore
new file mode 100644
index 0000000..8db9ac8
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/ClassExtends.xcore
@@ -0,0 +1,30 @@
+// XPECT noValidationErrors
+
+package foo
+
+class Foo {}
+class Bar<T> {}
+class Baz {}
+
+// FIXME: these scopes should not contain EDataTypes
+/* __XPECT scopeAllElements at Foo ---
+Bar, Baz, Class, Class1, Class2, Class3, Foo, Object,
+foo.Bar, foo.Baz, foo.Class1, foo.Class2, foo.Class3, foo.Foo,
+java.lang.Object
+--- */
+class Class1 extends Foo {}
+
+
+/* __XPECT scopeAllElements at Foo ---
+Bar, Baz, Class, Class1, Class2, Class3, Foo, Object,
+foo.Bar, foo.Baz, foo.Class1, foo.Class2, foo.Class3, foo.Foo,
+java.lang.Object
+--- */
+class Class2 extends Bar<Foo> {}
+
+/* __XPECT scopeAllElements at Foo ---
+Bar, Baz, Class, Class1, Class2, Class3, Foo, Object,
+foo.Bar, foo.Baz, foo.Class1, foo.Class2, foo.Class3, foo.Foo,
+java.lang.Object
+--- */
+class Class3<T extends Foo> {} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/XcoreScopingTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/XcoreScopingTest.java
new file mode 100644
index 0000000..f148128
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/XcoreScopingTest.java
@@ -0,0 +1,19 @@
+package org.eclipse.emf.ecore.xcore.tests.scoping;
+
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.parameterized.AbstractParameterizedXtextTest;
+import org.eclipse.xtext.junit4.parameterized.ResourceURIs;
+import org.eclipse.xtext.resource.XtextResource;
+
+@InjectWith(XcoreInjectorProvider.class)
+@ResourceURIs(baseDir = "src/org/eclipse/emf/ecore/xcore/tests/scoping", fileExtensions = "xcore")
+public class XcoreScopingTest extends AbstractParameterizedXtextTest
+{
+
+ public XcoreScopingTest(XtextResource resource, int offset, String[] params)
+ {
+ super(resource, offset, params);
+ }
+
+}
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore
index 240b303..715e9c0 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/Linking.xcore
@@ -1,9 +1,8 @@
package foo
-/* XPECT issues ---
-error for 'baz' message 'Couldn't resolve reference to GenBase 'baz'.'
-error ' message 'A generic super type must refer to a class'
----
-*/
+/* XPECT validationIssues ---
+error at 'baz' message 'Couldn't resolve reference to GenBase 'baz'.'
+error message 'A generic super type must refer to a class'
+--- */
class bar extends baz {} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/XcoreValidationTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/XcoreValidationTest.java
index 93f6453..42398cd 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/XcoreValidationTest.java
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/validation/XcoreValidationTest.java
@@ -1,66 +1,17 @@
package org.eclipse.emf.ecore.xcore.tests.validation;
-import java.util.List;
-
import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
import org.eclipse.xtext.junit4.InjectWith;
-import org.eclipse.xtext.junit4.parameterized.ParameterizedXtextRunner;
+import org.eclipse.xtext.junit4.parameterized.AbstractParameterizedXtextTest;
import org.eclipse.xtext.junit4.parameterized.ResourceURIs;
-import org.eclipse.xtext.nodemodel.ILeafNode;
-import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
-import org.eclipse.xtext.util.CancelIndicator;
-import org.eclipse.xtext.validation.CheckMode;
-import org.eclipse.xtext.validation.IResourceValidator;
-import org.eclipse.xtext.validation.Issue;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.Lists;
@InjectWith(XcoreInjectorProvider.class)
-@RunWith(ParameterizedXtextRunner.class)
@ResourceURIs(baseDir = "src/org/eclipse/emf/ecore/xcore/tests/validation", fileExtensions = "xcore")
-public class XcoreValidationTest
+public class XcoreValidationTest extends AbstractParameterizedXtextTest
{
-
- protected String expected;
- protected ILeafNode leaf;
-
- public XcoreValidationTest(ILeafNode leaf, String expected)
+ public XcoreValidationTest(XtextResource resource, int offset, String[] params)
{
- super();
- this.leaf = leaf;
- this.expected = expected;
+ super(resource, offset, params);
}
-
- protected String formatIssue(Issue issue)
- {
- StringBuilder result = new StringBuilder();
- result.append(issue.getSeverity().name().toLowerCase());
- if (issue.getOffset() != null && issue.getLength() != null)
- {
- result.append(" for '");
- result.append(leaf.getRootNode().getText().substring(issue.getOffset(), issue.getOffset() + issue.getLength()));
- } else
- result.append(" ");
- result.append("' message '");
- result.append(issue.getMessage());
- result.append("'");
- return result.toString();
- }
-
- @Test
- public String issues()
- {
- XtextResource resource = (XtextResource) NodeModelUtils.findActualSemanticObjectFor(leaf).eResource();
- IResourceValidator validator = resource.getResourceServiceProvider().get(IResourceValidator.class);
- List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
- List<String> result = Lists.newArrayList();
- for (Issue issue : issues)
- result.add(formatIssue(issue));
- return Joiner.on('\n').join(result);
- }
-
}