Skip to content

Commit

Permalink
Don't use ICommaSeparatedValuesExpectation for single-value references
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Eysholdt <[email protected]>
  • Loading branch information
meysholdt committed Jun 30, 2017
1 parent 3f95b2a commit 7ef85bf
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions org.xpect.xtext.lib/src/org/xpect/xtext/lib/tests/LinkingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,35 @@ protected String getLinkedFragment(EObject targetObject, URI baseUri) {
URI target = EcoreUtil.getURI(targetObject);
return deresolve(baseUri, target);
}

@SuppressWarnings("unchecked")

@Xpect(liveExecution = LiveExecutionType.FAST)
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public void linkedFragment(@CommaSeparatedValuesExpectation(ordered = true) ICommaSeparatedValuesExpectation expectation, @ThisOffset ICrossEReferenceAndEObject arg1) {
URI baseUri = arg1.getEObject().eResource().getURI();
public void linkedFragment(IStringExpectation expectation, @ThisOffset ICrossEReferenceAndEObject arg1) {
Object targetObject = arg1.getEObject().eGet(arg1.getCrossEReference());
if (targetObject == null) {
Assert.fail("Reference is null");
} else if (targetObject instanceof EObject) {
URI baseUri = arg1.getEObject().eResource().getURI();
String actual = getLinkedFragment((EObject) targetObject, baseUri);
expectation.assertEquals(Collections.singletonList(actual));
expectation.assertEquals(actual);
} else if (targetObject instanceof EList<?>) {
Assert.fail("use 'XPECT linkedFragment' (plural)");
}
}

@SuppressWarnings("unchecked")
@Xpect(liveExecution = LiveExecutionType.FAST)
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public void linkedFragments(@CommaSeparatedValuesExpectation(ordered = true) ICommaSeparatedValuesExpectation expectation, @ThisOffset ICrossEReferenceAndEObject arg1) {
Object targetObject = arg1.getEObject().eGet(arg1.getCrossEReference());
if (targetObject == null) {
Assert.fail("Reference is null");
} else if (targetObject instanceof EObject) {
Assert.fail("use 'XPECT linkedFragment' (singular)");
} else if (targetObject instanceof EList<?>) {
URI baseUri = arg1.getEObject().eResource().getURI();
List<String> result = Lists.newArrayList();
for(EObject target:(List<EObject>) targetObject) {
for (EObject target : (List<EObject>) targetObject) {
String fragment = getLinkedFragment(target, baseUri);
result.add(fragment);
}
Expand Down

0 comments on commit 7ef85bf

Please sign in to comment.