Search in sources :

Example 6 with Source

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

the class SourceBuilderTest method assignMimeTypeAndIdentity.

@Test
public void assignMimeTypeAndIdentity() {
    Source.Builder<RuntimeException, MissingMIMETypeException, RuntimeException> builder = Source.newBuilder("// a comment\n").name("Empty comment");
    Source s1 = builder.mimeType("content/unknown").build();
    assertEquals("No mime type assigned", "content/unknown", s1.getMimeType());
    Source s2 = builder.mimeType("text/x-c").build();
    assertEquals("They have the same content", s1.getCharacters(), s2.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 : MissingMIMETypeException(com.oracle.truffle.api.source.MissingMIMETypeException) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 7 with Source

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

the class SourceBuilderTest method markSourceAsInteractive.

@Test
public void markSourceAsInteractive() {
    Source source = Source.newBuilder("anything interactive").mimeType("text/plain").name("interactivesrc").interactive().build();
    assertTrue("This source is interactive", source.isInteractive());
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 8 with Source

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

the class SourceBuilderTest method assignMimeTypeAndIdentityForVirtualFile.

@Test
public void assignMimeTypeAndIdentityForVirtualFile() throws Exception {
    File file = File.createTempFile("Hello", ".java").getCanonicalFile();
    file.deleteOnExit();
    String text = "// Hello";
    Source.Builder<RuntimeException, RuntimeException, RuntimeException> builder = Source.newBuilder(file).content(text).mimeType("text/x-java");
    // JDK8 default fails on OS X: https://bugs.openjdk.java.net/browse/JDK-8129632
    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 : File(java.io.File) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 9 with Source

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

the class SourceBuilderTest method normalSourceIsNotInter.

@Test
public void normalSourceIsNotInter() {
    Source source = Source.newBuilder("anything").mimeType("text/plain").name("anyname").build();
    assertFalse("Not internal", source.isInternal());
    assertFalse("Not interactive", source.isInteractive());
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 10 with Source

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

the class SourceBuilderTest method noIOWhenContentSpecified.

@Test
public void noIOWhenContentSpecified() {
    File file = new File("some.js");
    String text = "// Hello";
    Source source = Source.newBuilder(file).content(text).build();
    assertEquals("The content has been changed", text, source.getCharacters());
    assertNotNull("Mime type specified", source.getMimeType());
    assertTrue("Recognized as JavaScript", source.getMimeType().endsWith("/javascript"));
    assertEquals("some.js", source.getName());
}
Also used : 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