Search in sources :

Example 66 with IonDatagram

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

the class IonWriterTestCase method testWriteSymbolTokenWithGoodSid.

@Test
public void testWriteSymbolTokenWithGoodSid() throws Exception {
    iw = makeWriter();
    iw.writeSymbolToken(newSymbolToken((String) null, NAME_SID));
    IonDatagram dg = reload();
    IonSymbol s = (IonSymbol) dg.get(0);
    checkSymbol(SystemSymbols.NAME, NAME_SID, s);
}
Also used : IonSymbol(com.amazon.ion.IonSymbol) IonDatagram(com.amazon.ion.IonDatagram) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Example 67 with IonDatagram

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

the class IonWriterTestCase method testWriteLobNull.

@Test
public void testWriteLobNull() throws Exception {
    iw = makeWriter();
    iw.writeBlob(null);
    iw.writeBlob(null, 10, 12);
    iw.writeClob(null);
    iw.writeClob(null, 23, 1);
    IonDatagram dg = reload();
    for (int i = 0; i < 4; i++) {
        IonLob lob = (IonLob) dg.get(i);
        assertTrue("dg[" + i + "] not null", lob.isNullValue());
    }
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonLob(com.amazon.ion.IonLob) Test(org.junit.Test)

Example 68 with IonDatagram

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

the class TextWriterTest method testNewLineTypesWithPrettyPrinting.

@Test
public void testNewLineTypesWithPrettyPrinting() {
    for (IonTextWriterBuilder.NewLineType nlt : IonTextWriterBuilder.NewLineType.values()) {
        String expected = String.format("%s\"Foo\"%<sBar%<s(%<s  1%<s  2%<s  3%<s)%<s[%<s  4,%<s  5,%<s  6%<s]", nlt.getCharSequence());
        IonTextWriterBuilder writerBuilder = IonTextWriterBuilder.standard().withInitialIvmHandling(SUPPRESS).withWriteTopLevelValuesOnNewLines(false).withPrettyPrinting().withNewLineType(nlt);
        IonDatagram dg = system().newDatagram();
        dg.add().newString("Foo");
        dg.add().newSymbol("Bar");
        dg.add().newSexp(new int[] { 1, 2, 3 });
        dg.add().newList(new int[] { 4, 5, 6 });
        StringBuilder sb = new StringBuilder();
        IonWriter writer = writerBuilder.build(sb);
        dg.writeTo(writer);
        assertEquals(expected, sb.toString());
    }
}
Also used : IonTextWriterBuilder(com.amazon.ion.system.IonTextWriterBuilder) IonDatagram(com.amazon.ion.IonDatagram) IonWriter(com.amazon.ion.IonWriter) Test(org.junit.Test)

Example 69 with IonDatagram

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

the class TextWriterTest method testJsonLongStrings.

@Test
public void testJsonLongStrings() throws Exception {
    options = IonTextWriterBuilder.json();
    options.setLongStringThreshold(5);
    IonDatagram dg = system().newDatagram();
    dg.add().newString("hello");
    dg.add().newString("hello!");
    dg.add().newString("goodbye");
    dg.add().newString("what's\nup\ndoc");
    expectRendering("\"hello\" '''hello!''' \"goodbye\" '''what\\'s\nup\ndoc'''", dg);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 70 with IonDatagram

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

the class TextWriterTest method testWritingFloatPositiveInfinityToJson.

@Test
public void testWritingFloatPositiveInfinityToJson() throws Exception {
    options = IonTextWriterBuilder.json();
    options.setInitialIvmHandling(SUPPRESS);
    IonDatagram dg = system().newDatagram();
    dg.add().newFloat(Double.POSITIVE_INFINITY);
    iw = makeWriter();
    dg.writeTo(iw);
    String actual = outputString();
    assertEquals("null", actual);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Aggregations

IonDatagram (com.amazon.ion.IonDatagram)92 Test (org.junit.Test)77 IonValue (com.amazon.ion.IonValue)20 SymbolTable (com.amazon.ion.SymbolTable)18 IonReader (com.amazon.ion.IonReader)17 IonString (com.amazon.ion.IonString)15 IonStruct (com.amazon.ion.IonStruct)13 IonWriter (com.amazon.ion.IonWriter)11 IonSymbol (com.amazon.ion.IonSymbol)6 IonSystem (com.amazon.ion.IonSystem)6 IonLoader (com.amazon.ion.IonLoader)5 IonType (com.amazon.ion.IonType)5 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)5 BlobTest (com.amazon.ion.BlobTest)4 ClobTest (com.amazon.ion.ClobTest)4 IntTest (com.amazon.ion.IntTest)4 IonList (com.amazon.ion.IonList)4 IonTextWriterBuilder (com.amazon.ion.system.IonTextWriterBuilder)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BinaryTest (com.amazon.ion.BinaryTest)2