Search in sources :

Example 21 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class SymbolTableTest method testBadLocalSymtabCreation.

@Test
public void testBadLocalSymtabCreation() {
    SymbolTable systemTable = system().getSystemSymbolTable();
    SymbolTable fred1 = Symtabs.CATALOG.getTable("fred", 1);
    try {
        system().newLocalSymbolTable((SymbolTable) null);
    } catch (NullPointerException e) {
    }
    try {
        system().newLocalSymbolTable(fred1, systemTable);
    } catch (IllegalArgumentException e) {
    }
    try {
        system().newLocalSymbolTable(fred1, null);
    } catch (NullPointerException e) {
    }
    try {
        system().newLocalSymbolTable(fred1, system().newLocalSymbolTable());
    } catch (IllegalArgumentException e) {
    }
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 22 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class SymbolTableTest method testSharedSymtabCreationWithImports.

@Test
public void testSharedSymtabCreationWithImports() {
    SymbolTable fred1 = Symtabs.CATALOG.getTable("fred", 1);
    SymbolTable ginger1 = Symtabs.CATALOG.getTable("ginger", 1);
    String[] syms = { "a", "fred_1", "b" };
    SymbolTable st = system().newSharedSymbolTable("ST", 1, Arrays.asList(syms).iterator(), fred1);
    checkSharedTable("ST", 1, new String[] { "fred_1", "fred_2", "a", "b" }, st);
    assertEquals(fred1.findSymbol("fred_1"), st.findSymbol("fred_1"));
    // Again, with two imports
    st = system().newSharedSymbolTable("ST", 1, Arrays.asList(syms).iterator(), fred1, ginger1);
    checkSharedTable("ST", 1, new String[] { "fred_1", "fred_2", "g1", "g2", "a", "b" }, st);
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 23 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class SymbolTableTest method testNewSharedSymtabFromReaderWithImports.

@Test
public void testNewSharedSymtabFromReaderWithImports() {
    SymbolTable v1 = registerImportedV1();
    String text = SharedSymbolTablePrefix + "{ name:\"ST\", version:1, " + "  imports:[{name:\"imported\", version:1," + "            max_id:" + v1.getMaxId() + "  }]," + "  symbols:[\"imported 1\"]" + "}";
    SymbolTable st = system().newSharedSymbolTable(system().newReader(text));
    assertEquals(v1.findSymbol("imported 1"), st.findSymbol("imported 1"));
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 24 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class SymbolTableTest method testInitialSystemSymtab.

@Test
public void testInitialSystemSymtab() {
    final SymbolTable systemTable = system().getSystemSymbolTable(ION_1_0);
    assertEquals(ION, systemTable.getName());
    String text = "0";
    IonValue v = oneValue(text);
    SymbolTable st = v.getSymbolTable();
    assertSame(systemTable, st.getSystemSymbolTable());
    IonDatagram dg = loader().load(text);
    IonSymbol sysId = (IonSymbol) dg.systemGet(0);
    checkSymbol(ION_1_0, ION_1_0_SID, sysId);
    assertSame(systemTable, sysId.getSymbolTable());
    v = dg.get(0);
    st = v.getSymbolTable();
    assertSame(systemTable, st.getSystemSymbolTable());
}
Also used : IonValue(com.amazon.ion.IonValue) IonSymbol(com.amazon.ion.IonSymbol) IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 25 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class SymbolTableTest method testImportWithBadMaxId.

@Test
public void testImportWithBadMaxId() {
    SymbolTable importedV1 = registerImportedV1();
    testImportWithBadMaxId(importedV1, "null.int");
    testImportWithBadMaxId(importedV1, "null");
    testImportWithBadMaxId(importedV1, "not_an_int");
    // testImportWithBadMaxId(importedV1, "0");  Zero isn't bad, its zero!
    testImportWithBadMaxId(importedV1, "-1");
    testImportWithBadMaxId(importedV1, "-2223");
    String text = LocalSymbolTablePrefix + "{" + "  imports:[{name:\"imported\", version:1}]," + "}\n" + "null";
    IonValue v = oneValue(text);
    assertSame(importedV1, v.getSymbolTable().getImportedTables()[0]);
    SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
    catalog.removeTable(importedV1.getName(), importedV1.getVersion());
    badValue(text);
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) IonValue(com.amazon.ion.IonValue) 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