use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class SymbolTableTest method checkEmptyLocalSymtab.
public void checkEmptyLocalSymtab(SymbolTable st) {
SymbolTable systemTable = system().getSystemSymbolTable();
checkLocalTable(st);
assertSame(systemTable, st.getSystemSymbolTable());
assertEquals(systemTable.getMaxId(), st.getMaxId());
assertEquals(systemTable.getMaxId(), st.getImportedMaxId());
assertEquals(0, st.getImportedTables().length);
}
use of com.amazon.ion.SymbolTable 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.SymbolTable in project ion-java by amzn.
the class SymbolTableTest method testSymtabImageMaintenance.
@Test
public void testSymtabImageMaintenance() {
IonSystem system = system();
SymbolTable st = ((_Private_ValueFactory) system).getLstFactory().newLocalSymtab(system.getSystemSymbolTable());
st.intern("foo");
IonStruct image = symtabTree(st, system);
st.intern("bar");
image = symtabTree(st, system);
IonList symbols = (IonList) image.get(SYMBOLS);
assertEquals("[\"foo\",\"bar\"]", symbols.toString());
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class SymbolTableTest method testImportWithZeroMaxId.
// TODO test getUsedTable(null)
// TODO test getImportedTable(null)
@Test
public void testImportWithZeroMaxId() throws Exception {
registerImportedV1();
String text = LocalSymbolTablePrefix + "{" + " imports:[{name:\"imported\", version:1, max_id:0}]," + " symbols:['''local''']" + "}\n" + "null";
IonValue v = oneValue(text);
SymbolTable symbolTable = v.getSymbolTable();
SymbolTable imported = checkFirstImport("imported", 1, EMPTY_STRING_ARRAY, symbolTable);
assertTrue(imported.isSubstitute());
checkUnknownSymbol("imported 1", 1, imported);
checkSymbol("local", systemMaxId() + 1, symbolTable);
checkUnknownSymbol("imported 1", UNKNOWN_SYMBOL_ID, symbolTable);
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class SymbolTableTest method testBasicLocalSymtabCreation.
@Test
public void testBasicLocalSymtabCreation() {
SymbolTable systemTable = system().getSystemSymbolTable();
SymbolTable fred1 = Symtabs.CATALOG.getTable("fred", 1);
SymbolTable st = system().newLocalSymbolTable(systemTable, fred1);
final int importedMaxId = systemTable.getMaxId() + fred1.getMaxId();
checkLocalTable(st);
assertSame(systemTable, st.getSystemSymbolTable());
assertEquals(importedMaxId, st.getMaxId());
assertEquals(importedMaxId, st.getImportedMaxId());
assertEquals(1, st.getImportedTables().length);
assertSame(fred1, st.getImportedTables()[0]);
st = system().newLocalSymbolTable(systemTable);
checkEmptyLocalSymtab(st);
}
Aggregations