Search in sources :

Example 36 with SymbolTable

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);
}
Also used : SymbolTable(com.amazon.ion.SymbolTable)

Example 37 with SymbolTable

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());
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 38 with SymbolTable

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());
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 39 with SymbolTable

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);
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 40 with 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);
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Aggregations

SymbolTable (com.amazon.ion.SymbolTable)177 Test (org.junit.Test)105 IonValue (com.amazon.ion.IonValue)21 IonDatagram (com.amazon.ion.IonDatagram)18 com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable (com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable)17 SymbolToken (com.amazon.ion.SymbolToken)14 IonStruct (com.amazon.ion.IonStruct)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 IonWriter (com.amazon.ion.IonWriter)12 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)12 IonReader (com.amazon.ion.IonReader)11 IonSystem (com.amazon.ion.IonSystem)10 IOException (java.io.IOException)9 IonType (com.amazon.ion.IonType)8 ArrayList (java.util.ArrayList)7 IonException (com.amazon.ion.IonException)6 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)6 com.amazon.ion.impl.bin._Private_IonRawWriter (com.amazon.ion.impl.bin._Private_IonRawWriter)6 IonCatalog (com.amazon.ion.IonCatalog)5 IonList (com.amazon.ion.IonList)5