Search in sources :

Example 91 with Source

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

the class SourceBuilderTest method ioExceptionWhenFileDoesntExist.

@Test
public void ioExceptionWhenFileDoesntExist() throws Exception {
    File file = File.createTempFile("Hello", ".java").getCanonicalFile();
    file.delete();
    assertFalse("Doesn't exist", file.exists());
    Source.Builder<IOException, RuntimeException, RuntimeException> builder = Source.newBuilder(file);
    Source s1 = null;
    try {
        s1 = builder.build();
    } catch (IOException e) {
        // OK, file doesn't exist
        return;
    }
    fail("No source should be created: " + s1);
}
Also used : IOException(java.io.IOException) File(java.io.File) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 92 with Source

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

the class SourceBuilderTest method mimeTypeIsDetectedRandomBytes.

@Test
public void mimeTypeIsDetectedRandomBytes() throws IOException {
    File file = File.createTempFile("Hello", ".bin").getCanonicalFile();
    file.deleteOnExit();
    try (FileOutputStream w = new FileOutputStream(file)) {
        w.write(0x04);
        w.write(0x05);
    }
    Source source = Source.newBuilder(file).build();
    assertEither(source.getMimeType(), "content/unknown", "application/octet-stream", "text/plain", "application/macbinary");
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 93 with Source

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

the class SourceBuilderTest method assignMimeTypeAndIdentityForReader.

@Test
public void assignMimeTypeAndIdentityForReader() throws IOException {
    String text = "// Hello";
    Source.Builder<IOException, MissingMIMETypeException, RuntimeException> builder = Source.newBuilder(new StringReader(text)).name("test.txt");
    Source s1 = builder.name("Hello").mimeType("text/plain").build();
    assertEquals("Base type assigned", "text/plain", s1.getMimeType());
    Source s2 = builder.mimeType("text/x-c").build();
    assertEquals("They have the same content", s1.getCharacters(), s2.getCharacters());
    assertEquals("// Hello", s1.getCharacters());
    assertNotEquals("But different type", s1.getMimeType(), s2.getMimeType());
    assertNotEquals("So they are different", s1, s2);
    assertNotNull("Every source must have URI", s1.getURI());
    assertEquals("Source with different MIME type has the same URI", s1.getURI(), s2.getURI());
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) MissingMIMETypeException(com.oracle.truffle.api.source.MissingMIMETypeException) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 94 with Source

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

the class SourceBuilderTest method succeedsWithBothNameAndMIME.

@Test
public void succeedsWithBothNameAndMIME() {
    Source src = Source.newBuilder("Hi").mimeType("content/unknown").name("unknown.txt").build();
    assertNotNull(src);
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 95 with Source

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

the class SourceBuilderTest method assignMimeTypeAndIdentityForURL.

@Test
public void assignMimeTypeAndIdentityForURL() throws IOException {
    File file = File.createTempFile("Hello", ".java");
    file.deleteOnExit();
    String text;
    try (FileWriter w = new FileWriter(file)) {
        text = "// Hello";
        w.write(text);
    }
    Source.Builder<IOException, RuntimeException, RuntimeException> builder = Source.newBuilder(file.toURI().toURL()).name("Hello.java");
    Source s1 = builder.build();
    assertEquals("Recognized as Java", "text/x-java", s1.getMimeType());
    Source s2 = builder.mimeType("text/x-c").build();
    assertEquals("They have the same content", s1.getCharacters(), s2.getCharacters());
    assertEquals("// Hello", s1.getCharacters());
    assertNotEquals("But different type", s1.getMimeType(), s2.getMimeType());
    assertNotEquals("So they are different", s1, s2);
    assertEquals("File URI", file.toURI(), s1.getURI());
    assertEquals("Source with different MIME type has the same URI", s1.getURI(), s2.getURI());
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) 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