Skip to content

Commit

Permalink
more tests for closures and lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed May 27, 2024
1 parent d37580d commit 4ff65d1
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ public void testFunctionCallWithArguments() throws ScriptException, NoSuchMethod
assertThat( result ).isEqualTo( "Hello, World!" );
}

@Test
public void testClosureCall() throws ScriptException, NoSuchMethodException {
engine.eval( "test = ( name ) => { return 'Hello, ' & arguments.1 & '!' }" );
Invocable invocable = ( Invocable ) engine;
Object result = invocable.invokeFunction( "test", "World" );
assertThat( result ).isEqualTo( "Hello, World!" );
}

@Test
public void testLambdaCall() throws ScriptException, NoSuchMethodException {
engine.eval( "test = ( name ) -> { return 'Hello, ' & arguments.1 & '!' }" );
Invocable invocable = ( Invocable ) engine;
Object result = invocable.invokeFunction( "test", "World" );
assertThat( result ).isEqualTo( "Hello, World!" );
}

@DisplayName( "Eval a script with no bindings" )
@Test
public void testEval() throws ScriptException {
Expand Down

0 comments on commit 4ff65d1

Please sign in to comment.