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));
}
}
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);
}
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);
}
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());
}
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));
}
Aggregations