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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations