Search in sources :

Example 6 with RubyProc

use of org.jruby.RubyProc in project enumerable by hraberg.

the class JRubyTest method convertRubyMethodProcToFn.

@Test
public void convertRubyMethodProcToFn() throws ScriptException {
    RubyProc proc = (RubyProc) rb.eval("(\"hello\".method :upcase).to_proc");
    assertEquals("HELLO", toFn0(proc).call());
}
Also used : RubyProc(org.jruby.RubyProc) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 7 with RubyProc

use of org.jruby.RubyProc in project enumerable by hraberg.

the class JRubyTest method convertFnToRubyProc.

@Test
public void convertFnToRubyProc() throws ScriptException {
    Ruby ruby = Ruby.getGlobalRuntime();
    RubyProc proc = toProc(Lambda.λ(s, s.toUpperCase()));
    assertEquals(ruby.newString("HELLO"), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newString("hello") }));
}
Also used : RubyProc(org.jruby.RubyProc) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 8 with RubyProc

use of org.jruby.RubyProc in project enumerable by hraberg.

the class JRubyTest method interactingWithGroovy.

@Test
public void interactingWithGroovy() throws Exception {
    Ruby ruby = Ruby.getGlobalRuntime();
    ScriptEngine groovy = GroovyTest.getGroovyEngine();
    Closure<?> closure = (Closure<?>) groovy.eval("{ n, m -> n * m }");
    RubyProc proc = toProc(LambdaGroovy.toFn2(closure));
    assertEquals(ruby.newFixnum(6), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newFixnum(2), ruby.newFixnum(3) }));
    rb.put("block", proc);
    assertEquals(120L, rb.eval("[1, 2, 3, 4, 5].inject &block"));
}
Also used : RubyProc(org.jruby.RubyProc) Closure(groovy.lang.Closure) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) ScriptEngine(javax.script.ScriptEngine) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 9 with RubyProc

use of org.jruby.RubyProc in project enumerable by hraberg.

the class JRubyTest method convertRubyMethodProcToFnKeepsDefaultValues.

@Test
public void convertRubyMethodProcToFnKeepsDefaultValues() throws ScriptException {
    RubyProc proc = (RubyProc) rb.eval("def my_upcase(s = 'world') s.upcase end; method(:my_upcase).to_proc");
    assertEquals("WORLD", toFn1(proc).call());
}
Also used : RubyProc(org.jruby.RubyProc) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 10 with RubyProc

use of org.jruby.RubyProc in project enumerable by hraberg.

the class JRubyTest method interactingWithClojure.

@Test
public void interactingWithClojure() throws Exception {
    Ruby ruby = Ruby.getGlobalRuntime();
    IFn star = (IFn) ClojureTest.getClojureEngine().eval("*");
    RubyProc proc = toProc(LambdaClojure.toFn2(star));
    assertEquals(ruby.newFixnum(6), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newFixnum(2), ruby.newFixnum(3) }));
    rb.put("block", proc);
    assertEquals(120L, rb.eval("[1, 2, 3, 4, 5].inject &block"));
}
Also used : IFn(clojure.lang.IFn) RubyProc(org.jruby.RubyProc) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Aggregations

RubyProc (org.jruby.RubyProc)15 Test (org.junit.Test)15 ClojureTest (org.enumerable.lambda.support.clojure.ClojureTest)14 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)14 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)14 ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)14 LambdaJRuby (org.enumerable.lambda.support.jruby.LambdaJRuby)8 Ruby (org.jruby.Ruby)8 IRubyObject (org.jruby.runtime.builtin.IRubyObject)6 ScriptEngine (javax.script.ScriptEngine)5 JRubyTest (org.enumerable.lambda.support.jruby.JRubyTest)4 IFn (clojure.lang.IFn)2 RaiseException (org.jruby.exceptions.RaiseException)2 Closure (groovy.lang.Closure)1 FunctionFn2 (org.enumerable.lambda.support.javascript.LambdaJavaScript.FunctionFn2)1 ScalaInterpreter (org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter)1 Function2 (scala.Function2)1 Function (sun.org.mozilla.javascript.internal.Function)1