Skip to content

Commit

Permalink
also verify error's position for parameter INVALID_USE_OF_TYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Dec 20, 2023
1 parent 759e7c7 commit 9c8360d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,19 @@ public abstract class AbstractXtendTestCase extends Assert {

@Rule
@Inject public TemporaryFolder temporaryFolder;

@Inject
private Provider<XtextResourceSet> resourceSetProvider;

/**
* To build a function or constructor for tests
*/
protected static final String TEMPLATE_CLASS = "class Foo { %s }";
/**
* Use it to subtract from the index position of a source element of a function or constructor
*/
protected static final int TEMPLATE_CLASS_SIZE = TEMPLATE_CLASS.length() - 2; // 2 is the length of placeholder %s

protected XtendClass clazz(String string) throws Exception {
return (XtendClass) file(string).getXtendTypes().get(0);
}
Expand Down Expand Up @@ -160,7 +169,7 @@ protected XtendEnum enumeration(String string) throws Exception {
}

protected XtendFunction function(String string) throws Exception {
XtendClass clazz = clazz("class Foo { " + string + "}");
XtendClass clazz = clazz(String.format(TEMPLATE_CLASS, string));
return (XtendFunction) clazz.getMembers().get(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,11 @@ public void clearPreferences() {
}

@Test public void testParameterTypeMayNotBeVoid() throws Exception {
XtendFunction function = function("def void foo(void myParam) { }");
helper.assertError(function, TypesPackage.Literals.JVM_TYPE_REFERENCE, INVALID_USE_OF_TYPE);
var source = "def void foo(void myParam) { }";
XtendFunction function = function(source);
helper.assertError(function, TypesPackage.Literals.JVM_TYPE_REFERENCE,
INVALID_USE_OF_TYPE,
source.lastIndexOf("void") - TEMPLATE_CLASS_SIZE, "void".length());
}

@Test public void testVarArgIsNotExtension() throws Exception {
Expand Down

0 comments on commit 9c8360d

Please sign in to comment.