Search in sources :

Example 71 with IonDatagram

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

the class TextWriterTest method testWritingLongClobs.

@Test
public void testWritingLongClobs() throws Exception {
    options = IonTextWriterBuilder.standard();
    options.setInitialIvmHandling(SUPPRESS);
    options.setLongStringThreshold(4);
    IonDatagram dg = system().newDatagram();
    dg.add().newClob(new byte[] { 'a', '"', '\'', '\n' });
    expectRendering("{{\"a\\\"'\\n\"}}", dg);
    dg.clear();
    dg.add().newClob(new byte[] { 'a', '"', '\'', '\n', 'c' });
    expectRendering("{{'''a\"\\'\n" + "c'''}}", dg);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 72 with IonDatagram

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

the class TextWriterTest method testWritingLongStrings.

@Test
public void testWritingLongStrings() throws Exception {
    options = IonTextWriterBuilder.standard();
    options.setInitialIvmHandling(SUPPRESS);
    options.setLongStringThreshold(5);
    // This is tricky because we must avoid triple-quoting multiple
    // long strings in such a way that they'd get concatenated together!
    IonDatagram dg = system().newDatagram();
    dg.add().newNullString();
    dg.add().newString("hello");
    dg.add().newString("hello\nnurse");
    dg.add().newString("goodbye").addTypeAnnotation("a");
    dg.add().newString("what's\nup\ndoc");
    expectRendering("null.string \"hello\" '''hello\nnurse''' a::'''goodbye''' \"what's\\nup\\ndoc\"", dg);
    dg.clear();
    dg.add().newString("looong");
    IonSequence seq = dg.add().newEmptySexp();
    seq.add().newString("looong");
    seq.add().newString("hello");
    seq.add().newString("hello\nnurse");
    seq.add().newString("goodbye").addTypeAnnotation("a");
    seq.add().newString("what's\nup\ndoc");
    expectRendering("'''looong''' ('''looong''' \"hello\" '''hello\nnurse''' a::'''goodbye''' \"what's\\nup\\ndoc\")", dg);
    dg.clear();
    dg.add().newString("looong");
    seq = dg.add().newEmptyList();
    seq.add().newString("looong");
    seq.add().newString("hello");
    seq.add().newString("hello\nnurse");
    seq.add().newString("what's\nup\ndoc");
    expectRendering("'''looong''' ['''looong''',\"hello\",'''hello\n" + "nurse''','''what\\'s\n" + "up\n" + "doc''']", dg);
    options.setLongStringThreshold(0);
    expectRendering("\"looong\" [\"looong\",\"hello\",\"hello\\nnurse\",\"what's\\nup\\ndoc\"]", dg);
    options.setLongStringThreshold(5);
    dg.clear();
    dg.add().newString("looong");
    IonStruct struct = dg.add().newEmptyStruct();
    struct.add("a").newString("looong");
    struct.add("b").newString("hello");
    struct.add("c").newString("hello\nnurse");
    struct.add("d").newString("what's\nup\ndoc");
    expectRendering("'''looong''' {a:'''looong''',b:\"hello\",c:'''hello\n" + "nurse''',d:'''what\\'s\n" + "up\n" + "doc'''}", dg);
    options.withPrettyPrinting();
    expectRendering(// TODO amzn/ion-java/issues/57 determine if these really should be platform independent newlines
    format("%n" + "'''looong'''%n" + "{%n" + "  a:'''looong''',%n" + "  b:\"hello\",%n" + "  c:'''hello\n" + "nurse''',%n" + "  d:'''what\\'s\n" + "up\n" + "doc'''%n" + "}"), dg);
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) IonSequence(com.amazon.ion.IonSequence) Test(org.junit.Test)

Example 73 with IonDatagram

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

the class TreeReaderTest method testReadingReadOnly.

@Test
public void testReadingReadOnly() {
    IonDatagram dg = loader().load("{hello:hello}");
    // Make just part of the datagram read-only
    IonStruct s = (IonStruct) dg.get(0);
    s.makeReadOnly();
    IonReader r = system().newReader(s);
    TestUtils.deepRead(r);
    r = system().newReader(dg);
    TestUtils.deepRead(r);
    // Now the whole thing
    dg.makeReadOnly();
    r = system().newReader(dg);
    TestUtils.deepRead(r);
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader) Test(org.junit.Test)

Example 74 with IonDatagram

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

the class IonWriterTestCase method flushDoesNotReset.

private void flushDoesNotReset(boolean lstAppendEnabled) throws Exception {
    myLstAppendEnabled = lstAppendEnabled;
    SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
    iw = makeWriter(fred1);
    iw.writeSymbol("hey");
    iw.flush();
    iw.writeSymbol("now");
    iw.close();
    IonDatagram dg = reload();
    assertEquals(2, dg.size());
    assertEquals("hey", ((IonSymbol) dg.get(0)).stringValue());
    assertEquals("now", ((IonSymbol) dg.get(1)).stringValue());
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable)

Example 75 with IonDatagram

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

the class IonWriterTestCase method testWriteValueNull.

/**
 * Discovered this old behavior during test builds, some user code relies
 * on it.
 */
@Test
public void testWriteValueNull() throws Exception {
    iw = makeWriter();
    iw.writeValue((IonValue) null);
    IonDatagram dg = reload();
    assertEquals(0, dg.size());
}
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