Skip to content

Commit

Permalink
How to use varargs signature #48
Browse files Browse the repository at this point in the history
  • Loading branch information
aeberhart committed Sep 14, 2024
1 parent f528267 commit 4415e2c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/test/java/com/dashjoin/jsonata/CustomFunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import com.dashjoin.jsonata.Jsonata.JFunction;
import com.dashjoin.jsonata.Jsonata.JFunctionCallable;
Expand Down Expand Up @@ -70,4 +71,21 @@ public Object call(Object input, @SuppressWarnings("rawtypes") List args) throws
Assertions.assertEquals("T0410", ex.getError());
Assertions.assertEquals("append", ex.getExpected());
}

@Disabled
@Test
public void testVarArg() {
var expression = Jsonata.jsonata("$sum(1,2,3)");
expression.registerFunction("sum", new JFunction(new JFunctionCallable() {
@SuppressWarnings("rawtypes")
@Override
public Object call(Object input, List args) throws Throwable {
int sum = 0;
for (Object i : args)
sum += (int) i;
return sum;
}
}, "<n+:n>"));
Assertions.assertEquals(6, expression.evaluate(null));
}
}

0 comments on commit 4415e2c

Please sign in to comment.