Search in sources :

Example 1 with IonSymbol

use of com.amazon.ion.IonSymbol 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 2 with IonSymbol

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

the class ValueWriterTest method testWriteValuesWithSymtabIntoContainer.

// TODO more thorough testing that you can't output from DOM w/ bad text
@Test
public void testWriteValuesWithSymtabIntoContainer() throws Exception {
    myOutputInList = true;
    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.writeValues(r);
    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, systemMaxId() + Symtabs.FRED_MAX_IDS[1] + 1, s);
}
Also used : IonSymbol(com.amazon.ion.IonSymbol) IonDatagram(com.amazon.ion.IonDatagram) IonList(com.amazon.ion.IonList) IonReader(com.amazon.ion.IonReader) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 3 with IonSymbol

use of com.amazon.ion.IonSymbol 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);
}
Also used : IonSymbol(com.amazon.ion.IonSymbol) IonDatagram(com.amazon.ion.IonDatagram) IonList(com.amazon.ion.IonList) IonReader(com.amazon.ion.IonReader) SymbolTable(com.amazon.ion.SymbolTable) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Example 4 with IonSymbol

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

the class IonWriterTestCase method testWritingEmptySymtab.

@Test
public void testWritingEmptySymtab() throws Exception {
    iw = makeWriter();
    iw.addTypeAnnotation(ION_SYMBOL_TABLE);
    iw.stepIn(IonType.STRUCT);
    iw.stepOut();
    iw.writeSymbol("foo");
    iw.close();
    IonDatagram dg = reload();
    IonSymbol foo = (IonSymbol) dg.get(0);
    assertEquals(0, foo.getTypeAnnotations().length);
}
Also used : IonSymbol(com.amazon.ion.IonSymbol) IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 5 with IonSymbol

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

the class IterationTest method testSimpleIteration.

// =========================================================================
// Test cases
@Test
public void testSimpleIteration() {
    Iterator<IonValue> i = system().iterate("abc");
    assertTrue(i.hasNext());
    IonSymbol value = (IonSymbol) i.next();
    checkSymbol("abc", value);
    assertFalse(i.hasNext());
    checkEmptyIterator(i);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSymbol(com.amazon.ion.IonSymbol) Test(org.junit.Test)

Aggregations

IonSymbol (com.amazon.ion.IonSymbol)18 Test (org.junit.Test)9 IonDatagram (com.amazon.ion.IonDatagram)6 IonReader (com.amazon.ion.IonReader)4 IonString (com.amazon.ion.IonString)4 IonStruct (com.amazon.ion.IonStruct)4 SymbolTable (com.amazon.ion.SymbolTable)4 IonList (com.amazon.ion.IonList)3 BlobTest (com.amazon.ion.BlobTest)2 ClobTest (com.amazon.ion.ClobTest)2 IntTest (com.amazon.ion.IntTest)2 IonBool (com.amazon.ion.IonBool)2 IonFloat (com.amazon.ion.IonFloat)2 IonInt (com.amazon.ion.IonInt)2 IonTimestamp (com.amazon.ion.IonTimestamp)2 IonType (com.amazon.ion.IonType)2 IonValue (com.amazon.ion.IonValue)2 BinaryTest (com.amazon.ion.BinaryTest)1 IonBlob (com.amazon.ion.IonBlob)1 IonClob (com.amazon.ion.IonClob)1