use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLInteropControlFlowTest method testWhile.
@Test
public void testWhile() throws IOException {
final Source src = Source.newBuilder("sl", "function testWhile(a) {while(a) {break;}} function main() {return testWhile;}", "testWhile.sl").build();
final Value fnc = context.eval(src);
Assert.assertTrue(fnc.canExecute());
fnc.execute(false);
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLInteropObjectTest method testObject.
@Test
public void testObject() throws IOException {
final Source src = Source.newBuilder("sl", "function main() {o = new(); o.a = 10; o.b = \"B\"; return o;}", "testObject.sl").build();
final Value obj = context.eval(src);
Assert.assertTrue(obj.hasMembers());
Value a = obj.getMember("a");
Assert.assertNotNull(a);
Assert.assertTrue(a.isNumber());
Assert.assertEquals(10, a.asInt());
Value b = obj.getMember("b");
Assert.assertNotNull(b);
Assert.assertTrue(b.isString());
Assert.assertEquals("B", b.asString());
obj.putMember("a", b);
a = obj.getMember("a");
Assert.assertTrue(a.isString());
Assert.assertEquals("B", a.asString());
obj.removeMember("a");
Assert.assertFalse(obj.hasMember("a"));
Assert.assertEquals("[b]", obj.getMemberKeys().toString());
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLInteropPrimitiveTest method testChar.
@Test
public void testChar() throws IOException {
final Source src = Source.newBuilder("sl", "function testChar(a,b) {return a == b;} function main() {return testChar;}", "testChar.sl").build();
final Value fnc = context.eval(src);
Assert.assertTrue(fnc.canExecute());
fnc.execute('a', 'b');
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLInteropPrimitiveTest method testBoolean.
@Test
public void testBoolean() throws IOException {
final Source src = Source.newBuilder("sl", "function testBoolean(a,b) {return a == b;} function main() {return testBoolean;}", "testBoolean.sl").build();
final Value fnc = context.eval(src);
Assert.assertTrue(fnc.canExecute());
fnc.execute(true, false);
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLParseErrorTest method testParseError.
@Test
public void testParseError() throws IOException {
try {
final Source src = Source.newBuilder("sl", "function testSyntaxError(a) {break;} function main() {return testSyntaxError;}", "testSyntaxError.sl").build();
context.eval(src);
Assert.assertTrue("Should not reach here.", false);
} catch (PolyglotException e) {
Assert.assertTrue("Should be a syntax error.", e.isSyntaxError());
Assert.assertNotNull("Should have source section.", e.getSourceLocation());
}
}
Aggregations