use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class SymbolTableTest method testInjectingMaxIdIntoImport.
@Test
public // TODO implement
void testInjectingMaxIdIntoImport() {
SymbolTable importedTable = registerImportedV1();
String text = LocalSymbolTablePrefix + "{" + " imports:[{name:'''imported''',version:1}],\n" + "}\n" + "null";
IonDatagram dg = loader().load(text);
SymbolTable symbolTable = dg.get(0).getSymbolTable();
checkLocalTable(symbolTable);
SymbolTable[] imported = symbolTable.getImportedTables();
assertEquals(1, imported.length);
assertSame(importedTable, imported[0]);
// Check that the encoded table has max_id on import
byte[] binary = dg.getBytes();
dg = loader().load(binary);
IonStruct symtabStruct = (IonStruct) dg.systemGet(1);
IonList imports = (IonList) symtabStruct.get("imports");
IonStruct importStruct = (IonStruct) imports.get(0);
checkString("imported", importStruct.get("name"));
IonValue maxIdValue = importStruct.get("max_id");
assertNotNull("max_id wasn't injected into import", maxIdValue);
checkInt(IMPORTED_1_MAX_ID, maxIdValue);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingNonAscii.
@Test
public void testWritingNonAscii() throws Exception {
String text = TestUtils.YEN_SIGN + FERMATA;
iw = makeWriter();
iw.writeString(text);
iw.writeSymbol(text);
IonDatagram dg = reload();
IonText t = (IonString) dg.get(0);
assertEquals(text, t.stringValue());
t = (IonSymbol) dg.get(1);
checkSymbol(text, t);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingAnnotationWithUnknownText.
@Test
public void testWritingAnnotationWithUnknownText() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
iw.setTypeAnnotationSymbols(newSymbolToken((String) null, 0));
// expected: the type annotation is written
iw.writeNull();
IonValue v = expected.add().newNull();
v.setTypeAnnotationSymbols(newSymbolToken(0));
assertEquals(expected, reload());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingNulls.
@Test
public void testWritingNulls() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
iw.writeBlob(null);
expected.add().newNullBlob();
iw.writeClob(null);
expected.add().newNullClob();
iw.writeDecimal((BigDecimal) null);
expected.add().newNullDecimal();
iw.writeString(null);
expected.add().newNullString();
iw.writeSymbol(null);
expected.add().newNullSymbol();
iw.writeTimestamp(null);
expected.add().newNullTimestamp();
assertEquals(expected, reload());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingClob.
@Test
public void testWritingClob() throws Exception {
byte[] data = new byte[256];
for (int i = 0; i < data.length; i++) {
data[i] = (byte) i;
}
iw = makeWriter();
iw.writeBlob(data);
iw.writeBlob(data, 10, 90);
iw.writeClob(data);
iw.writeClob(data, 20, 30);
byte[] bytes = outputByteArray();
IonDatagram dg = loader().load(bytes);
assertEquals(4, dg.size());
IonLob lob = (IonBlob) dg.get(0);
assertTrue(Arrays.equals(data, lob.getBytes()));
lob = (IonBlob) dg.get(1);
assertEqualBytes(data, 10, 90, lob.getBytes());
lob = (IonClob) dg.get(2);
assertTrue(Arrays.equals(data, lob.getBytes()));
lob = (IonClob) dg.get(3);
assertEqualBytes(data, 20, 30, lob.getBytes());
}
Aggregations