diff -r 000000000000 -r 6fcc0dfbe324 vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Tue Sep 25 17:30:13 2012 +0200 @@ -0,0 +1,46 @@ +package org.apidesign.vm4brwsr; + +import javax.script.Invocable; +import javax.script.ScriptException; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * + * @author Jaroslav Tulach + */ +public class StringTest { + @Test public void firstChar() throws Exception { + assertExec( + "First char in Hello is H", + "org_apidesign_vm4brwsr_StringSample_sayHelloCI", + Double.valueOf((int)'H'), 0 + ); + } + + private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception { + StringBuilder sb = new StringBuilder(); + Invocable i = StaticMethodTest.compileClass(sb, + "org/apidesign/vm4brwsr/StringSample", + "java/lang/String" + ); + + Object ret = null; + try { + ret = i.invokeFunction(methodName, args); + } catch (ScriptException ex) { + fail("Execution failed in " + sb, ex); + } catch (NoSuchMethodException ex) { + fail("Cannot find method in " + sb, ex); + } + if (ret == null && expRes == null) { + return; + } + if (expRes.equals(ret)) { + return; + } + assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb); + + } + +}