add more simple tests

This commit is contained in:
Robert Muir 2016-06-16 12:40:30 -04:00
parent fdd1f152a7
commit 251001e435
1 changed files with 18 additions and 0 deletions

View File

@ -81,4 +81,22 @@ public class LambdaTests extends ScriptTestCase {
public void testMultipleStatements() { public void testMultipleStatements() {
assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(x -> { x = x + 1; return x;})")); assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(x -> { x = x + 1; return x;})"));
} }
public void testTwoLambdas() {
assertEquals("testingcdefg", exec(
"org.elasticsearch.painless.FeatureTest test = new org.elasticsearch.painless.FeatureTest(2,3);" +
"return test.twoFunctionsOfX(x -> 'testing'.concat(x), y -> 'abcdefg'.substring(y))"));
}
public void testNestedLambdas() {
assertEquals(1, exec("Optional.empty().orElseGet(() -> Optional.empty().orElseGet(() -> 1));"));
}
public void testLambdaInLoop() {
assertEquals(100, exec("int sum = 0; " +
"for (int i = 0; i < 100; i++) {" +
" sum += Optional.empty().orElseGet(() -> 1);" +
"}" +
"return sum;"));
}
} }