use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class SourceBuilderTest method jarURLGetsAName.
@Test
public void jarURLGetsAName() throws IOException {
File sample = File.createTempFile("sample", ".jar");
sample.deleteOnExit();
JarOutputStream os = new JarOutputStream(new FileOutputStream(sample));
os.putNextEntry(new ZipEntry("x.js"));
os.write("Hi!".getBytes("UTF-8"));
os.closeEntry();
os.close();
URL resource = new URL("jar:" + sample.toURI() + "!/x.js");
assertNotNull("Resource found", resource);
assertEquals("JAR protocol", "jar", resource.getProtocol());
Source s = Source.newBuilder(resource).build();
assertEquals("Hi!", s.getCharacters());
assertEquals("x.js", s.getName());
sample.delete();
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class InitializationTest method checkPostInitializationInRunMethod.
@Test
public void checkPostInitializationInRunMethod() throws Exception {
vm = PolyglotEngine.newBuilder().build();
Source source = Source.newBuilder("accessProbeForAbstractLanguage text").mimeType("application/x-abstrlang").name("sample.txt").build();
assertEquals("Properly evaluated", 42, vm.eval(source).get());
Object global = vm.findGlobalSymbol("MyEnv").get();
assertNotNull(global);
assertTrue(global instanceof MyEnv);
MyEnv env = (MyEnv) global;
assertEquals("Post initialization hook called", 1, env.cnt);
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class InteractiveEvalTest method testDefaultInteractiveLanguageDirectly.
@Test
public void testDefaultInteractiveLanguageDirectly() 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.getLanguages().get("application/x-test-definteract").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 testSpecialInteractiveLanguage.
@Test
public void testSpecialInteractiveLanguage() 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.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 testSpecialNoninteractiveLanguage.
@Test
public void testSpecialNoninteractiveLanguage() throws UnsupportedEncodingException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PolyglotEngine engine = PolyglotEngine.newBuilder().setOut(out).build();
Source s = Source.newBuilder("").mimeType("application/x-test-specinteract").name("specnoninteract").build();
PolyglotEngine.Value value = engine.eval(s);
Assert.assertEquals("42", value.get());
String strOutput = out.toString(StandardCharsets.UTF_8.name());
Assert.assertTrue(strOutput.isEmpty());
}
Aggregations