Search in sources :

Example 36 with Source

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

the class SourceSectionFilterTest method testLineEndsIn.

@Test
public void testLineEndsIn() {
    Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 23));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineEndsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(6, 6))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineEndsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(0, 6))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineEndsIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 6))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineEndsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(0, 6))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineEndsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(6, 6))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineEndsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(12, 6))));
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 37 with Source

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

the class SourceSectionFilterTest method testRootSourceSectionEquals.

@Test
public void testRootSourceSectionEquals() {
    Source sampleSource1 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Assert.assertTrue(isInstrumentedNode(SourceSectionFilter.newBuilder().rootSourceSectionEquals(sampleSource1.createSection(1, 6)).build(), createNode(sampleSource1.createSection(6, 4))));
    Assert.assertTrue(isInstrumentedRoot(SourceSectionFilter.newBuilder().rootSourceSectionEquals(sampleSource1.createSection(1, 6)).build(), createNode(sampleSource1.createSection(1, 6))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().rootSourceSectionEquals(sampleSource1.createSection(1, 6)).build(), createNode(sampleSource1.createSection(1, 6)), createNode(sampleSource1.createSection(6, 4))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().rootSourceSectionEquals(sampleSource1.createSection(1, 6)).build(), createNode(sampleSource1.createSection(2, 6)), createNode(sampleSource1.createSection(1, 4))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().rootSourceSectionEquals(sampleSource1.createSection(1, 6)).build(), createNode(sampleSource1.createSection(1, 7)), createNode(sampleSource1.createSection(1, 4))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().rootSourceSectionEquals(sampleSource1.createSection(1, 6)).build(), createNode(sampleSource1.createSection(1, 6)), createNode(sampleSource1.createUnavailableSection())));
    Assert.assertNotNull(SourceSectionFilter.newBuilder().rootSourceSectionEquals(sampleSource1.createSection(1, 6)).build().toString());
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 38 with Source

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

the class SourceSectionFilterTest method testColumnNotIn.

@Test
public void testColumnNotIn() {
    Source sampleSource = Source.newBuilder("123456789\n123456789").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 19));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(0, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(1, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(3, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(2, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(2, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 2), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(1, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createUnavailableSection())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(0, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(1, 1), IndexRange.between(2, 3), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnNotIn(IndexRange.byLength(1, 1), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertNotNull(SourceSectionFilter.newBuilder().columnIn(2, 2).build().toString());
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 39 with Source

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

the class SourceSectionFilterTest method testMimeType.

@Test
public void testMimeType() {
    String src = "line1\nline2\nline3\nline4";
    Source mime1 = Source.newBuilder(src).name("unknown").mimeType("mime1").build();
    Source mime2 = Source.newBuilder(src).name("unknown").mimeType("mime2").build();
    Source mime3 = Source.newBuilder(src).name("unknown").mimeType("mime3").build();
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().mimeTypeIs().build(), null, createNode(mime3.createSection(0, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().mimeTypeIs("mime1").build(), null, createNode(mime1.createSection(0, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().mimeTypeIs("mime1").build(), null, createNode(mime2.createSection(0, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().mimeTypeIs("mime1", "mime2").build(), null, createNode(mime2.createSection(0, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().mimeTypeIs("mime1", "mime2").build(), null, createNode(mime3.createSection(0, 5), tags())));
    Assert.assertNotNull(SourceSectionFilter.newBuilder().mimeTypeIs("mime1", "mime2").build().toString());
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 40 with Source

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

the class SourceSectionFilterTest method testColumnEndsIn.

@Test
public void testColumnEndsIn() {
    Source sampleSource = Source.newBuilder("123456789\n123456789").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 19));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnEndsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(1, 1))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnEndsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(0, 1))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnEndsIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 1))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnEndsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(0, 1))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnEndsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(1, 1))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnEndsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(2, 1))));
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) 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