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