use of javax.script.ScriptEngine in project enumerable by hraberg.
the class ScalaTest method interactingWithGroovy.
@Test
public void interactingWithGroovy() throws Exception {
ScriptEngine groovy = GroovyTest.getGroovyEngine();
Closure<?> closure = (Closure<?>) groovy.eval("{ n, m -> n * m }");
Function2<Object, Object, Object> times = toFunction(LambdaGroovy.toFn2(closure));
assertEquals(6, times.apply(2, 3));
scala.bind("timesGroovy", "Function2[Any, Any, Any]", times);
assertEquals(120, scala.eval("List(1, 2, 3, 4, 5).reduceLeft(timesGroovy)"));
}
use of javax.script.ScriptEngine in project enumerable by hraberg.
the class ScalaTest method interactingWithJavaScript.
@Test
public void interactingWithJavaScript() throws Exception {
ScriptEngine js = JavaScriptTest.getJavaScriptEngine();
Function f = (Function) js.eval("var f = function(n, m) { return n * m; }; f;");
Function2<Object, Object, Object> times = toFunction(LambdaJavaScript.toFn2(f));
assertEquals(6.0, times.apply(2, 3));
scala.bind("timesJS", "Function2[Any, Any, Any]", times);
assertEquals(120.0, scala.eval("List(1, 2, 3, 4, 5).reduceLeft(timesJS)"));
}
use of javax.script.ScriptEngine in project enumerable by hraberg.
the class GroovyTest method interactingWithJRuby.
@Test
public void interactingWithJRuby() throws Exception {
ScriptEngine rb = JRubyTest.getJRubyEngine();
RubyProc proc = (RubyProc) rb.eval(":*.to_proc");
Closure<?> closure = toClosure(LambdaJRuby.toFn2(proc));
groovy.put("f", closure);
assertEquals(6L, groovy.eval("f(2, 3)"));
}
use of javax.script.ScriptEngine in project enumerable by hraberg.
the class GroovyTest method interactingWithJavaScript.
@Test
public void interactingWithJavaScript() throws Exception {
ScriptEngine js = JavaScriptTest.getJavaScriptEngine();
Function f = (Function) js.eval("var f = function(n, m) { return n * m; }; f;");
ClosureFn2 closure = toClosure(LambdaJavaScript.toFn2(f));
assertEquals(6.0, closure.call(new Object[] { 2, 3 }));
groovy.put("closure", closure);
assertEquals(120.0, groovy.eval("[1, 2, 3, 4, 5].inject(1, closure)"));
}
use of javax.script.ScriptEngine in project enumerable by hraberg.
the class JavaScriptTest method interactingWithGroovy.
@Test
public void interactingWithGroovy() throws Exception {
ScriptEngine groovy = GroovyTest.getGroovyEngine();
Closure<?> closure = (Closure<?>) groovy.eval("{ n, m -> n * m }");
FunctionFn2 f = toFunction(LambdaGroovy.toFn2(closure));
js.put("f", f);
assertEquals(6.0, js.eval("f(2, 3)"));
}
Aggregations