| author | Moritz Eysholdt | 2011-10-29 11:49:30 (EDT) |
|---|---|---|
| committer | Ed Merks | 2011-10-29 11:49:30 (EDT) |
| commit | 96a6c200493cbe40e3edb9fec8f5d3210369a89a (patch) (side-by-side diff) | |
| tree | a4a2b7097a13265dbc670b1bff77d9bc2e113a8b | |
| parent | a0ff20bca276bee3f455e2514c4ee8ed2762ba84 (diff) | |
| download | org.eclipse.emf-96a6c200493cbe40e3edb9fec8f5d3210369a89a.zip org.eclipse.emf-96a6c200493cbe40e3edb9fec8f5d3210369a89a.tar.gz org.eclipse.emf-96a6c200493cbe40e3edb9fec8f5d3210369a89a.tar.bz2 | |
migrated tests to the latest changes in Xtext
10 files changed, 192 insertions, 65 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/EPackage1.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/EPackage1.xcore index 6e3198e..ce36e33 100644 --- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/EPackage1.xcore +++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/EPackage1.xcore @@ -1,5 +1,3 @@ -// XPECT noValidationErrors - /* XPECT eNamedElement --- EPackage { name = 'foo' diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/EPackage2.xcore b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/EPackage2.xcore index 66525ac..09a9683 100644 --- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/EPackage2.xcore +++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/EPackage2.xcore @@ -1,5 +1,3 @@ -// XPECT noValidationErrors - /* XPECT eNamedElement --- EPackage { name = 'foo' diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/XcoreEcoreTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/XcoreEcoreTest.java index 400de87..6164971 100644 --- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/XcoreEcoreTest.java +++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ecore/XcoreEcoreTest.java @@ -1,5 +1,7 @@ package org.eclipse.emf.ecore.xcore.tests.ecore; +import java.util.Map; + import org.eclipse.emf.ecore.ENamedElement; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.xcore.XNamedElement; @@ -7,31 +9,51 @@ import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider; import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper; import org.eclipse.emf.ecore.xcore.tests.GenModelFormatter; import org.eclipse.xtext.junit4.InjectWith; -import org.eclipse.xtext.junit4.parameterized.AbstractParameterizedXtextTest; +import org.eclipse.xtext.junit4.parameterized.OffsetHelper; +import org.eclipse.xtext.junit4.parameterized.ParameterizedXtextRunner; import org.eclipse.xtext.junit4.parameterized.ResourceURIs; -import org.eclipse.xtext.junit4.parameterized.TestAsString; +import org.eclipse.xtext.junit4.parameterized.XpectString; +import org.eclipse.xtext.junit4.validation.ValidationTestHelper; import org.eclipse.xtext.resource.XtextResource; +import org.junit.Test; +import org.junit.runner.RunWith; import com.google.inject.Inject; +@SuppressWarnings("restriction") @InjectWith(XcoreInjectorProvider.class) +@RunWith(ParameterizedXtextRunner.class) @ResourceURIs(baseDir = "src/org/eclipse/emf/ecore/xcore/tests/ecore", fileExtensions = "xcore") -public class XcoreEcoreTest extends AbstractParameterizedXtextTest +public class XcoreEcoreTest { - public XcoreEcoreTest(XtextResource resource, int offset, String[] params) + @Inject + private XcoreMapper mapper; + @Inject + private OffsetHelper offsetHelper; + private Map<String, String> params; + private XtextResource resource; + @Inject + private ValidationTestHelper validationHelper; + + public XcoreEcoreTest(XtextResource resource, Map<String, String> params) { - super(resource, offset, params); + this.resource = resource; + this.params = params; } - @Inject - private XcoreMapper mapper; + @Test + public void noValidationIssues() + { + validationHelper.assertNoIssues(resource.getContents().get(0)); + } - @TestAsString + @XpectString public String eNamedElement() { EcoreUtil.resolveAll(resource); - ENamedElement gen = mapper.getEcore((XNamedElement) getEObjectAtOffset()); + XNamedElement namedElement = (XNamedElement) offsetHelper.at(resource, params.get("offset")).getEObject(); + ENamedElement gen = mapper.getEcore(namedElement); return new GenModelFormatter().resolveCrossReferences().format(gen); } 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 fade518..2eed29e 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,7 +1,5 @@ package foo -// XPECT noValidationErrors - class X { /* XPECT genBase at x --- 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 35473e4..da7c0d7 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,5 +1,3 @@ -// XPECT noValidationErrors - /* XPECT genBase --- GenPackage { prefix = 'Foo' 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 a2430ea..317f712 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,5 +1,7 @@ package org.eclipse.emf.ecore.xcore.tests.genmodel; +import java.util.Map; + import org.eclipse.emf.codegen.ecore.genmodel.GenBase; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.xcore.XNamedElement; @@ -7,31 +9,53 @@ import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider; import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper; import org.eclipse.emf.ecore.xcore.tests.GenModelFormatter; import org.eclipse.xtext.junit4.InjectWith; -import org.eclipse.xtext.junit4.parameterized.AbstractParameterizedXtextTest; +import org.eclipse.xtext.junit4.parameterized.OffsetHelper; +import org.eclipse.xtext.junit4.parameterized.Parameter; +import org.eclipse.xtext.junit4.parameterized.ParameterizedXtextRunner; import org.eclipse.xtext.junit4.parameterized.ResourceURIs; -import org.eclipse.xtext.junit4.parameterized.TestAsString; +import org.eclipse.xtext.junit4.parameterized.XpectString; +import org.eclipse.xtext.junit4.validation.ValidationTestHelper; import org.eclipse.xtext.resource.XtextResource; +import org.junit.Test; +import org.junit.runner.RunWith; import com.google.inject.Inject; +@SuppressWarnings("restriction") @InjectWith(XcoreInjectorProvider.class) +@RunWith(ParameterizedXtextRunner.class) @ResourceURIs(baseDir = "src/org/eclipse/emf/ecore/xcore/tests/genmodel", fileExtensions = "xcore") -public class XcoreGenModelTest extends AbstractParameterizedXtextTest +public class XcoreGenModelTest { - public XcoreGenModelTest(XtextResource resource, int offset, String[] params) + @Inject + private XcoreMapper mapper; + @Inject + private OffsetHelper offsetHelper; + private Map<String, String> params; + private XtextResource resource; + @Inject + private ValidationTestHelper validationHelper; + + public XcoreGenModelTest(XtextResource resource, Map<String, String> params) { - super(resource, offset, params); + this.resource = resource; + this.params = params; } - @Inject - private XcoreMapper mapper; + @Test + public void noValidationIssues() + { + validationHelper.assertNoIssues(resource.getContents().get(0)); + } - @TestAsString + @XpectString + @Parameter(syntax = "'at' offset=OFFSET") public String genBase() { EcoreUtil.resolveAll(resource); - GenBase gen = mapper.getGen((XNamedElement) getEObjectAtOffset()); + XNamedElement namedElement = (XNamedElement) offsetHelper.at(resource, params.get("offset")).getEObject(); + GenBase gen = mapper.getGen(namedElement); return new GenModelFormatter().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 index 67779cd..1ab1bbb 100644 --- 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 @@ -1,11 +1,9 @@ -// 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 +// !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 index 8db9ac8..cd8bef8 100644 --- 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 @@ -1,5 +1,3 @@ -// XPECT noValidationErrors - package foo class Foo {} @@ -7,24 +5,21 @@ 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 +/* XPECT scopeAllElements at Foo --- +Bar, Baz, Class, Class1, Class2, Class3, Foo, +foo.Bar, foo.Baz, foo.Class1, foo.Class2, foo.Class3, foo.Foo, ... --- */ 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 +/* XPECT scopeAllElements at Foo --- +Bar, Baz, Class, Class1, Class2, Class3, Foo, +foo.Bar, foo.Baz, foo.Class1, foo.Class2, foo.Class3, foo.Foo, ... --- */ 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 +/* XPECT scopeAllElements at Foo --- +Bar, Baz, Class, Class1, Class2, Class3, Foo, +foo.Bar, foo.Baz, foo.Class1, foo.Class2, foo.Class3, foo.Foo, ... --- */ 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 index f148128..be5be73 100644 --- 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 @@ -1,19 +1,73 @@ package org.eclipse.emf.ecore.xcore.tests.scoping; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; 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.OffsetHelper; +import org.eclipse.xtext.junit4.parameterized.Parameter; +import org.eclipse.xtext.junit4.parameterized.ParameterizedXtextRunner; import org.eclipse.xtext.junit4.parameterized.ResourceURIs; +import org.eclipse.xtext.junit4.parameterized.XpectCommaSeparatedValues; +import org.eclipse.xtext.junit4.validation.ValidationTestHelper; +import org.eclipse.xtext.resource.IEObjectDescription; import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.scoping.IScope; +import org.eclipse.xtext.scoping.IScopeProvider; +import org.eclipse.xtext.util.Pair; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.google.common.collect.Lists; +import com.google.inject.Inject; +@SuppressWarnings("restriction") @InjectWith(XcoreInjectorProvider.class) +@RunWith(ParameterizedXtextRunner.class) @ResourceURIs(baseDir = "src/org/eclipse/emf/ecore/xcore/tests/scoping", fileExtensions = "xcore") -public class XcoreScopingTest extends AbstractParameterizedXtextTest +public class XcoreScopingTest { - public XcoreScopingTest(XtextResource resource, int offset, String[] params) + private XtextResource resource; + private Map<String, String> params; + @Inject + private OffsetHelper offsetHelper; + @Inject + private ValidationTestHelper validationHelper; + @Inject + private IScopeProvider scopeProvider; + + public XcoreScopingTest(XtextResource resource, Map<String, String> params) + { + super(); + this.resource = resource; + this.params = params; + } + + @Test + public void noValidationIssues() + { + validationHelper.assertNoIssues(resource.getContents().get(0)); + } + + @XpectCommaSeparatedValues() + @Parameter(syntax = "'at' offset=OFFSET") + public List<String> scopeAllElements() { - super(resource, offset, params); + Pair<EObject, EStructuralFeature> objAndFeature = offsetHelper.at(resource, params.get("offset")) + .getEStructuralFeatureByParent(); + Assert.assertTrue(objAndFeature.getSecond() instanceof EReference); + Assert.assertFalse(((EReference) objAndFeature.getSecond()).isContainment()); + IScope scope = scopeProvider.getScope(objAndFeature.getFirst(), (EReference) objAndFeature.getSecond()); + List<String> result = Lists.newArrayList(); + for (IEObjectDescription desc : scope.getAllElements()) + result.add(desc.getName().toString()); + return result; } } 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 59a2ce3..396d38d 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,49 +1,91 @@ package org.eclipse.emf.ecore.xcore.tests.validation; +import java.util.List; + import org.eclipse.emf.ecore.util.EcoreValidator; 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.ParameterizedXtextRunner; import org.eclipse.xtext.junit4.parameterized.ResourceURIs; +import org.eclipse.xtext.junit4.parameterized.XpectLines; 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.runner.RunWith; + +import com.google.common.collect.Lists; +import com.google.inject.Inject; /** * There are cases not covered because the grammar doesn't allow it, i.e., * {@link EcoreValidator#CONSISTENT_BOUNDS_NOT_ALLOWED}, - * {@link EcoreValidator#CONSISTENT_BOUNDS_NO_BOUNDS_WITH_TYPE_PARAMETER_OR_CLASSIFIER}, - * {@link EcoreValidator#CONSISTENT_BOUNDS_NO_LOWER_AND_UPPER}, + * {@link EcoreValidator#CONSISTENT_BOUNDS_NO_BOUNDS_WITH_TYPE_PARAMETER_OR_CLASSIFIER} + * , {@link EcoreValidator#CONSISTENT_BOUNDS_NO_LOWER_AND_UPPER}, * {@link EcoreValidator#CONSISTENT_TYPE_NO_TYPE_PARAMETER_AND_CLASSIFIER}, * {@link EcoreValidator#CONSISTENT_TYPE_WILDCARD_NOT_PERMITTED}, * {@link EcoreValidator#INTERFACE_IS_ABSTRACT}, * {@link EcoreValidator#NO_REPEATING_VOID}, * {@link EcoreValidator#UNIQUE_NS_URIS}, * {@link EcoreValidator#UNIQUE_SUBPACKAGE_NAMES}, - * {@link EcoreValidator#VALID_LOWER_BOUND}, - * {@link EcoreValidator#VALID_TYPE}, + * {@link EcoreValidator#VALID_LOWER_BOUND}, {@link EcoreValidator#VALID_TYPE}, * {@link EcoreValidator#VALID_UPPER_BOUND}, - * {@link EcoreValidator#WELL_FORMED_INSTANCE_TYPE_NAME}, - * or the scoping rules won't resolve that way, i.e., - * {@link EcoreValidator#CONSISTENT_KEYS}, + * {@link EcoreValidator#WELL_FORMED_INSTANCE_TYPE_NAME}, or the scoping rules + * won't resolve that way, i.e., {@link EcoreValidator#CONSISTENT_KEYS}, * {@link EcoreValidator#CONSISTENT_OPPOSITE_NOT_FROM_TYPE}, * {@link EcoreValidator#CONSISTENT_TYPE_TYPE_PARAMETER_NOT_IN_SCOPE}, - * {@link EcoreValidator#WELL_FORMED_NAME}, - * or we don't set the flags yet, i.e., - * {@link EcoreValidator#CONSISTENT_TRANSIENT}, - * or we can't get into that state, i.e., - * {@link EcoreValidator#VALID_DEFAULT_VALUE_LITERAL}, - * {@link EcoreValidator#CONSISTENT_UNIQUE}, - * or are TODO items + * {@link EcoreValidator#WELL_FORMED_NAME}, or we don't set the flags yet, i.e., + * {@link EcoreValidator#CONSISTENT_TRANSIENT}, or we can't get into that state, + * i.e., {@link EcoreValidator#VALID_DEFAULT_VALUE_LITERAL}, + * {@link EcoreValidator#CONSISTENT_UNIQUE}, or are TODO items * {@link EcoreValidator#WELL_FORMED_NS_PREFIX}, * {@link EcoreValidator#WELL_FORMED_NS_URI}, * {@link EcoreValidator#WELL_FORMED_SOURCE_URI}, * */ +@SuppressWarnings("restriction") @InjectWith(XcoreInjectorProvider.class) +@RunWith(ParameterizedXtextRunner.class) @ResourceURIs(baseDir = "src/org/eclipse/emf/ecore/xcore/tests/validation", fileExtensions = "xcore") -public class XcoreValidationTest extends AbstractParameterizedXtextTest +public class XcoreValidationTest { - public XcoreValidationTest(XtextResource resource, int offset, String[] params) + + private XtextResource resource; + + @Inject + private IResourceValidator validator; + + public XcoreValidationTest(XtextResource resource) + { + super(); + this.resource = resource; + } + + protected String formatIssue(Issue issue) + { + StringBuilder result = new StringBuilder(); + result.append(issue.getSeverity().name().toLowerCase()); + if (issue.getOffset() != null && issue.getLength() != null) + { + result.append(" at '"); + result.append(resource.getParseResult().getRootNode().getText() + .substring(issue.getOffset(), issue.getOffset() + issue.getLength())); + result.append("' "); + } else + result.append(" "); + result.append("message '"); + result.append(issue.getMessage()); + result.append("'"); + return result.toString(); + } + + @XpectLines() + public List<String> validationIssues() { - super(resource, offset, params); + List<String> result = Lists.newArrayList(); + for (Issue issue : validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)) + result.add(formatIssue(issue)); + return result; } } |

