Search in sources :

Example 1 with MissingMIMETypeException

use of com.oracle.truffle.api.source.MissingMIMETypeException 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 2 with MissingMIMETypeException

use of com.oracle.truffle.api.source.MissingMIMETypeException 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)

Aggregations

MissingMIMETypeException (com.oracle.truffle.api.source.MissingMIMETypeException)2 Source (com.oracle.truffle.api.source.Source)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1