Search in sources :

Example 16 with Span

use of com.amazon.ion.Span in project ion-java by amzn.

the class SeekableReaderTest method testWalkingBackwards.

@Test
public void testWalkingBackwards() {
    if (getStreamingMode() == StreamingMode.NEW_STREAMING_INCREMENTAL) {
        // See ion-java/issues/382 and ion-java/issues/383.
        return;
    }
    String text = "null true 3 4e0 5.0 6666-06-06T '7' \"8\" {{\"\"}} {{}} [] () {}";
    IonDatagram dg = loader().load(text);
    Span[] positions = new Span[dg.size()];
    read(text);
    for (int i = 0; i < dg.size(); i++) {
        assertEquals(dg.get(i).getType(), in.next());
        positions[i] = sr.currentSpan();
    }
    expectEof();
    checkSpans(dg, positions);
    // Collect spans *after* extracting scalar body.
    read(text);
    for (int i = 0; i < dg.size(); i++) {
        IonType t = in.next();
        assertEquals(dg.get(i).getType(), t);
        if (!IonType.isContainer(t)) {
            TestUtils.consumeCurrentValue(in);
        }
        positions[i] = sr.currentSpan();
    }
    expectTopEof();
    checkSpans(dg, positions);
}
Also used : IonType(com.amazon.ion.IonType) IonDatagram(com.amazon.ion.IonDatagram) Span(com.amazon.ion.Span) Test(org.junit.Test)

Example 17 with Span

use of com.amazon.ion.Span in project ion-java by amzn.

the class SeekableReaderTest method testTrivialSpan.

@Test
public void testTrivialSpan() {
    if (getStreamingMode() == StreamingMode.NEW_STREAMING_INCREMENTAL) {
        // See ion-java/issues/382 and ion-java/issues/383.
        return;
    }
    String text = "null";
    read(text);
    in.next();
    Span s = sr.currentSpan();
    expectTopEof();
    hoist(s);
    assertSame(IonType.NULL, in.next());
    expectTopLevel();
    expectTopEof();
}
Also used : Span(com.amazon.ion.Span) Test(org.junit.Test)

Example 18 with Span

use of com.amazon.ion.Span in project ion-java by amzn.

the class SeekableReaderTest method testHoistingAnnotatedTopLevelValue.

@Test
public void testHoistingAnnotatedTopLevelValue() throws IOException {
    if (getStreamingMode() == StreamingMode.NEW_STREAMING_INCREMENTAL) {
        // See ion-java/issues/382 and ion-java/issues/383.
        return;
    }
    read("a::v");
    in.next();
    Span span = sr.currentSpan();
    expectTopEof();
    hoist(span);
    assertSame(IonType.SYMBOL, in.next());
    expectTopLevel();
    Assert.assertArrayEquals(new String[] { "a" }, in.getTypeAnnotations());
    expectTopEof();
}
Also used : Span(com.amazon.ion.Span) Test(org.junit.Test)

Example 19 with Span

use of com.amazon.ion.Span in project ion-java by amzn.

the class SpanReaderTest method testCurrentSpanWithinContainers.

@Test
public void testCurrentSpanWithinContainers() {
    if (getStreamingMode() == StreamingMode.NEW_STREAMING_INCREMENTAL) {
        // See ion-java/issues/382 and ion-java/issues/383.
        return;
    }
    read("{f:v,g:[c]} s");
    in.next();
    in.stepIn();
    in.next();
    Span fPos = sp.currentSpan();
    assertEquals("v", in.stringValue());
    in.next();
    Span gPos = sp.currentSpan();
    in.stepIn();
    in.next();
    assertEquals("c", in.stringValue());
    Span cPos = sp.currentSpan();
    expectEof();
    in.stepOut();
    expectEof();
    in.stepOut();
    in.next();
    Span sPos = sp.currentSpan();
    expectTopEof();
}
Also used : Span(com.amazon.ion.Span) Test(org.junit.Test)

Aggregations

Span (com.amazon.ion.Span)19 Test (org.junit.Test)14 TextSpan (com.amazon.ion.TextSpan)4 IonType (com.amazon.ion.IonType)3 OffsetSpan (com.amazon.ion.OffsetSpan)3 Spans.currentSpan (com.amazon.ion.util.Spans.currentSpan)3 IonDatagram (com.amazon.ion.IonDatagram)2 SpanProvider (com.amazon.ion.SpanProvider)1 File (java.io.File)1