Search in sources :

Example 31 with SymbolTable

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

the class SymbolTableTest method testOverridingSystemSymbolId.

/**
 * Attempts to override system symbols are ignored.
 */
@Test
public void testOverridingSystemSymbolId() {
    String importingText = LocalSymbolTablePrefix + "{" + "  symbols:[ '''" + NAME + "''' ]," + "}\n" + "null";
    Iterator<IonValue> scanner = system().iterate(importingText);
    IonValue v = scanner.next();
    SymbolTable symtab = v.getSymbolTable();
    assertTrue(symtab.isLocalTable());
    checkSymbol(NAME, NAME_SID, symtab);
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 32 with SymbolTable

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

the class SymbolTableTest method testLocalSymbolTableMultiAppend.

@Test
public void testLocalSymbolTableMultiAppend() {
    String text = LocalSymbolTablePrefix + "{" + "  symbols:[ \"s1\", \"s2\"]" + "}\n" + LocalSymbolTablePrefix + "{" + "  imports:" + ION_SYMBOL_TABLE + "," + "  symbols:[ \"s3\"]" + "}\n" + LocalSymbolTablePrefix + "{" + "  imports:" + ION_SYMBOL_TABLE + "," + "  symbols:[\"s4\", \"s5\"]" + "}\n" + LocalSymbolTablePrefix + "{" + "  imports:" + ION_SYMBOL_TABLE + "," + "  symbols:[\"s6\"]" + "}\n" + "null";
    SymbolTable symbolTable = oneValue(text).getSymbolTable();
    checkLocalTable(symbolTable);
    // table contains all symbols and SIDs are in correct order
    checkSymbol("s1", systemMaxId() + 1, symbolTable);
    checkSymbol("s2", systemMaxId() + 2, symbolTable);
    checkSymbol("s3", systemMaxId() + 3, symbolTable);
    checkSymbol("s4", systemMaxId() + 4, symbolTable);
    checkSymbol("s5", systemMaxId() + 5, symbolTable);
    checkSymbol("s6", systemMaxId() + 6, symbolTable);
    checkUnknownSymbol("unknown", UNKNOWN_SYMBOL_ID, symbolTable);
    checkUnknownSymbol(33, symbolTable);
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 33 with SymbolTable

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

the class SymbolTableTest method testImportsFollowSymbols.

@Test
public void testImportsFollowSymbols() {
    registerImportedV1();
    final int import1id = systemMaxId() + 1;
    final int local1id = systemMaxId() + IMPORTED_1_MAX_ID + 1;
    final int local2id = local1id + 1;
    String importingText = "$ion_1_0 " + LocalSymbolTablePrefix + "{" + "  symbols:[ '''local1''' ]," + "  imports:[{name:'''imported''', version:1, max_id:2}]," + "}\n" + // This symbol is added to end of locals
    "local2\n" + "local1\n" + "'imported 1'";
    Iterator<IonValue> scanner = system().iterate(importingText);
    IonValue value = scanner.next();
    SymbolTable symtab = value.getSymbolTable();
    checkLocalTable(symtab);
    checkSymbol("local2", value);
    value = scanner.next();
    checkSymbol("local1", local1id, value);
    value = scanner.next();
    checkSymbol("imported 1", import1id, value);
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 34 with SymbolTable

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

the class SymbolTableTest method testOverridingImportedSymbolId.

@Test
public void testOverridingImportedSymbolId() {
    SymbolTable importedTable = registerImportedV1();
    final int import1id = systemMaxId() + 1;
    final int import1DupId = systemMaxId() + importedTable.getMaxId() + 1;
    String importingText = "$ion_1_0 " + LocalSymbolTablePrefix + "{" + "  imports:[{name:'''imported''', version:1, max_id:2}]," + "  symbols:[ '''imported 1''' ]," + "}\n" + "'imported 1'\n" + "$" + import1id;
    Iterator<IonValue> scanner = system().iterate(importingText);
    IonValue value = scanner.next();
    checkSymbol("imported 1", import1id, value);
    SymbolTable symtab = value.getSymbolTable();
    checkLocalTable(symtab);
    checkSymbol("imported 1", import1id, symtab);
    checkSymbol("imported 1", import1DupId, /* dupe */
    true, symtab);
    // Here the input text is $NNN  but it comes back correctly.
    value = scanner.next();
    checkSymbol("imported 1", import1id, value);
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 35 with SymbolTable

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

the class SymbolTableTest method registerImportedV1.

public SymbolTable registerImportedV1() {
    SymbolTable shared = registerSharedSymtab(IMPORTED_1_SERIALIZED);
    assertEquals(IMPORTED_1_MAX_ID, shared.getMaxId());
    SymbolTable importedTable = system().getCatalog().getTable("imported", 1);
    assertSame(shared, importedTable);
    return importedTable;
}
Also used : SymbolTable(com.amazon.ion.SymbolTable)

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