Search in sources :

Example 56 with Source

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);
}
Also used : Value(org.graalvm.polyglot.Value) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 57 with Source

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());
}
Also used : Value(org.graalvm.polyglot.Value) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 58 with Source

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');
}
Also used : Value(org.graalvm.polyglot.Value) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 59 with Source

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);
}
Also used : Value(org.graalvm.polyglot.Value) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 60 with Source

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());
    }
}
Also used : PolyglotException(org.graalvm.polyglot.PolyglotException) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Aggregations

Source (org.graalvm.polyglot.Source)196 Test (org.junit.Test)165 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)103 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)95 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)51 Value (org.graalvm.polyglot.Value)31 Context (org.graalvm.polyglot.Context)25 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)21 DebugValue (com.oracle.truffle.api.debug.DebugValue)20 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)14 Instrument (org.graalvm.polyglot.Instrument)14 Debugger (com.oracle.truffle.api.debug.Debugger)13 SourceSection (com.oracle.truffle.api.source.SourceSection)12 EventContext (com.oracle.truffle.api.instrumentation.EventContext)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Engine (org.graalvm.polyglot.Engine)9 ArrayList (java.util.ArrayList)8 PolyglotException (org.graalvm.polyglot.PolyglotException)8 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)7 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)7