use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonWriterTestCase method testWritingWithSystemImport.
@Test
public void testWritingWithSystemImport() throws Exception {
final int FRED_ID_OFFSET = systemMaxId();
final int LOCAL_ID_OFFSET = FRED_ID_OFFSET + FRED_MAX_IDS[1];
SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
iw = makeWriter(system().getSystemSymbolTable(), fred1);
iw.writeSymbol("fred_2");
iw.writeSymbol("localSym");
byte[] bytes = outputByteArray();
IonDatagram dg = loader().load(bytes);
assertEquals(4, dg.systemSize());
IonValue f2sym = dg.systemGet(2);
IonValue local = dg.systemGet(3);
checkSymbol("fred_2", FRED_ID_OFFSET + 2, f2sym);
checkSymbol("localSym", local);
SymbolTable symtab = f2sym.getSymbolTable();
assertSame(symtab, local.getSymbolTable());
SymbolTable[] importedTables = symtab.getImportedTables();
assertEquals(1, importedTables.length);
assertSame(fred1, importedTables[0]);
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonWriterTestCase method testWriteValuesWithSymtab.
@Test
public void testWriteValuesWithSymtab() throws Exception {
SymbolTable fredSymtab = Symtabs.register(Symtabs.FRED_NAME, 1, catalog());
SymbolTable gingerSymtab = Symtabs.register(Symtabs.GINGER_NAME, 1, catalog());
String gingerSym = gingerSymtab.findKnownSymbol(1);
// First setup some data to be copied.
IonDatagram dg = system().newDatagram(gingerSymtab);
dg.add().newSymbol(gingerSym);
IonReader r = system().newReader(dg.getBytes());
// Now copy that data into a non-top-level context
iw = makeWriter(fredSymtab);
iw.stepIn(IonType.LIST);
iw.writeValues(r);
iw.stepOut();
IonDatagram result = reload();
IonList l = (IonList) result.get(0);
assertEquals(1, l.size());
IonSymbol s = (IonSymbol) l.get(0);
// Should've assigned a new SID
checkSymbol(gingerSym, s);
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class LocalSymbolTableTest method testCopyLSTThenAddSymbols.
@Test
public void testCopyLSTThenAddSymbols() {
SymbolTable orig = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC);
// method under test
SymbolTable copy = copyLocalSymbolTable(orig);
// interning in copy doesn't modify orig
assertNull(orig.find("amazon"));
copy.intern("amazon");
assertNull(orig.find("amazon"));
// interning in orig doesn't modify copy
assertNull(copy.find("dotcom"));
orig.intern("dotcom");
assertNull(copy.find("dotcom"));
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class LocalSymbolTableTest method testInternNull.
@Test(expected = NullPointerException.class)
public void testInternNull() {
SymbolTable st = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC);
st.intern(null);
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class LocalSymbolTableTest method testInternKnownText.
@Test
public void testInternKnownText() {
SymbolTable st = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC, ST_FRED_V2, ST_GINGER_V1);
internKnownText(st);
}
Aggregations