Search in sources :

Example 81 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class AsyncExecutorTest method testSynchronousLanguageAccess.

@Test
public void testSynchronousLanguageAccess() {
    PolyglotEngine engine = PolyglotEngine.newBuilder().build();
    Source s = Source.newBuilder("").mimeType("application/x-test-async").name("").build();
    List<PolyglotEngine.Value> values = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        values.add(engine.eval(s));
    }
    for (int i = 0; i < 100; i++) {
        Assert.assertEquals(i, (int) values.get(i).as(Integer.class));
    }
}
Also used : ArrayList(java.util.ArrayList) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 82 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class InteractiveEvalTest method testSpecialInteractiveLanguageDirectly.

@Test
public void testSpecialInteractiveLanguageDirectly() throws UnsupportedEncodingException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PolyglotEngine engine = PolyglotEngine.newBuilder().setOut(out).build();
    Source s = Source.newBuilder("").mimeType("application/x-test-specinteract").name("specinteract").interactive().build();
    PolyglotEngine.Value value = engine.getLanguages().get("application/x-test-specinteract").eval(s);
    Assert.assertEquals("42", value.get());
    String strOutput = out.toString(StandardCharsets.UTF_8.name());
    Assert.assertEquals("\"42\"", strOutput);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 83 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class InteractiveEvalTest method testDefaultInteractiveLanguage.

@Test
public void testDefaultInteractiveLanguage() throws UnsupportedEncodingException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PolyglotEngine engine = PolyglotEngine.newBuilder().setOut(out).build();
    Source s = Source.newBuilder("").mimeType("application/x-test-definteract").name("definteract").interactive().build();
    PolyglotEngine.Value value = engine.eval(s);
    Assert.assertEquals("42", value.get());
    String strOutput = out.toString(StandardCharsets.UTF_8.name());
    Assert.assertEquals("42" + System.getProperty("line.separator"), strOutput);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 84 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class InteractiveEvalTest method testDefaultNoninteractiveLanguage.

@Test
public void testDefaultNoninteractiveLanguage() throws UnsupportedEncodingException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PolyglotEngine engine = PolyglotEngine.newBuilder().setOut(out).build();
    Source s = Source.newBuilder("").mimeType("application/x-test-definteract").name("defnoninteract").build();
    PolyglotEngine.Value value = engine.eval(s);
    Assert.assertEquals("42", value.get());
    String strOutput = out.toString(StandardCharsets.UTF_8.name());
    Assert.assertTrue(strOutput.isEmpty());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 85 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class ToStringTest method toStringForNullLikeValue.

@Test
public void toStringForNullLikeValue() throws Exception {
    engine = PolyglotEngine.newBuilder().build();
    final Source src0 = Source.newBuilder("0").mimeType("application/x-unbox").name("zero.ux").build();
    PolyglotEngine.Value fourtyTwo = engine.eval(src0).execute();
    assertNull("Zero is treated as null", fourtyTwo.get());
    assertEquals("MyLang.toString is called", "Unboxed: 0", fourtyTwo.as(String.class));
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Aggregations

Source (com.oracle.truffle.api.source.Source)113 Test (org.junit.Test)65 RootNode (com.oracle.truffle.api.nodes.RootNode)23 File (java.io.File)20 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)16 Node (com.oracle.truffle.api.nodes.Node)16 SourceSection (com.oracle.truffle.api.source.SourceSection)16 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)15 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)11 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CallTarget (com.oracle.truffle.api.CallTarget)5 FileWriter (java.io.FileWriter)5 RootCallTarget (com.oracle.truffle.api.RootCallTarget)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)3 Script (com.oracle.truffle.tools.chromeinspector.types.Script)3