use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class SymbolTableTest method testLocalTableWithLesserImport.
/**
* Import v2 but catalog has v1.
*/
@Test
public void testLocalTableWithLesserImport() throws IOException {
final int import1id = systemMaxId() + 1;
final int import2id = systemMaxId() + 2;
final int fred3id = systemMaxId() + 3;
final int maxLocalId = systemMaxId() + IMPORTED_2_MAX_ID + 2;
registerImportedV1();
registerImportedV2();
String text = LocalSymbolTablePrefix + "{" + " imports:[{name:\"imported\", version:2, " + " max_id:" + IMPORTED_2_MAX_ID + "}]," + "}\n" + "local1 local2 'imported 1' 'imported 2' fred3";
byte[] binary = encode(text);
// Remove the imported table before decoding the binary.
SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
assertNotNull(catalog.removeTable("imported", 2));
IonDatagram dg = loader().load(binary);
checkSymbol("local1", dg.get(0));
checkSymbol("local2", dg.get(1));
checkSymbol("imported 1", import1id, dg.get(2));
checkSymbol("imported 2", import2id, dg.get(3));
checkUnknownSymbol(fred3id, dg.get(4));
SymbolTable st = dg.get(0).getSymbolTable();
checkFirstImport("imported", 2, new String[] { "imported 1", "imported 2", null, null }, st);
assertTrue(st.isLocalTable());
assertEquals(maxLocalId, st.getMaxId());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class TextWriterTest method testWritingFloatNegativeInfinityToJson.
@Test
public void testWritingFloatNegativeInfinityToJson() throws Exception {
options = IonTextWriterBuilder.json();
options.setInitialIvmHandling(SUPPRESS);
IonDatagram dg = system().newDatagram();
dg.add().newFloat(Double.NEGATIVE_INFINITY);
iw = makeWriter();
dg.writeTo(iw);
String actual = outputString();
assertEquals("null", actual);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class TextWriterTest method testWritingFloatNanToJson.
@Test
public void testWritingFloatNanToJson() throws Exception {
options = IonTextWriterBuilder.json();
options.setInitialIvmHandling(SUPPRESS);
IonDatagram dg = system().newDatagram();
dg.add().newFloat(Double.NaN);
iw = makeWriter();
dg.writeTo(iw);
String actual = outputString();
assertEquals("null", actual);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class TextWriterTest method testWritingTopLevelValuesOnNewLinesShouldHaveNoEffectWithPrettyPrint.
@Test
public void testWritingTopLevelValuesOnNewLinesShouldHaveNoEffectWithPrettyPrint() {
// Setting top-level newlines to false should have no effect when pretty printing.
IonTextWriterBuilder writerBuilder = IonTextWriterBuilder.standard().withInitialIvmHandling(SUPPRESS).withWriteTopLevelValuesOnNewLines(false).withPrettyPrinting().withNewLineType(IonTextWriterBuilder.NewLineType.LF);
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("\n\"Foo\"\nBar\n(\n 1\n 2\n 3\n)\n[\n 4,\n 5,\n 6\n]", sb.toString());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class TextWriterTest method testWritingTopLevelValuesOnNewLinesWithoutPrettyPrint.
@Test
public void testWritingTopLevelValuesOnNewLinesWithoutPrettyPrint() {
IonTextWriterBuilder writerBuilder = IonTextWriterBuilder.standard().withInitialIvmHandling(SUPPRESS).withWriteTopLevelValuesOnNewLines(true).withNewLineType(IonTextWriterBuilder.NewLineType.LF);
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 });
IonStruct struct = dg.add().newEmptyStruct();
struct.add("def").newInt(42);
struct.addTypeAnnotation("abc");
StringBuilder sb = new StringBuilder();
IonWriter writer = writerBuilder.build(sb);
dg.writeTo(writer);
assertEquals("\"Foo\"\nBar\n(1 2 3)\n[4,5,6]\nabc::{def:42}", sb.toString());
}
Aggregations