Search in sources :

Example 71 with SymbolTable

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

the class IonTextWriterBuilderTest method testImportsImmutability.

@Test(expected = UnsupportedOperationException.class)
public void testImportsImmutability() {
    SymbolTable f = Symtabs.CATALOG.getTable("fred", 1);
    SymbolTable[] symtabs = new SymbolTable[] { f };
    IonTextWriterBuilder b = IonTextWriterBuilder.standard();
    b.setImports(f);
    IonTextWriterBuilder b2 = b.immutable();
    assertArrayEquals(symtabs, b2.getImports());
    b2.setImports();
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 72 with SymbolTable

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

the class IonTextWriterBuilderTest method testImports.

// -------------------------------------------------------------------------
@Test
public void testImports() {
    SymbolTable f = Symtabs.CATALOG.getTable("fred", 1);
    SymbolTable g = Symtabs.CATALOG.getTable("ginger", 1);
    SymbolTable[] symtabsF = new SymbolTable[] { f };
    SymbolTable[] symtabsG = new SymbolTable[] { g };
    IonTextWriterBuilder b = IonTextWriterBuilder.standard();
    b.setImports(f);
    StringBuilder out = new StringBuilder();
    IonWriter writer = b.build(out);
    SymbolTable st = writer.getSymbolTable();
    assertArrayEquals(symtabsF, st.getImportedTables());
    // Test with...() on mutable builder
    IonTextWriterBuilder b2 = b.withImports(g);
    assertSame(b, b2);
    assertArrayEquals(symtabsG, b2.getImports());
    // Test with...() on immutable builder
    b2 = b.immutable();
    assertArrayEquals(symtabsG, b2.getImports());
    IonTextWriterBuilder b3 = b2.withImports(f);
    assertNotSame(b2, b3);
    assertArrayEquals(symtabsG, b2.getImports());
    assertArrayEquals(symtabsF, b3.getImports());
    // Test cloning of array
    SymbolTable[] symtabs = new SymbolTable[] { f };
    b3.setImports(symtabs);
    assertNotSame(symtabs, b3.getImports());
    assertArrayEquals(symtabsF, b3.getImports());
    symtabs[0] = g;
    assertArrayEquals(symtabsF, b3.getImports());
    b3.getImports()[0] = g;
    assertArrayEquals(symtabsF, b3.getImports());
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) Test(org.junit.Test)

Example 73 with SymbolTable

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

the class SimpleCatalogTest method testGetMissingVersion.

@Test
public void testGetMissingVersion() {
    SimpleCatalog cat = myCatalog = new SimpleCatalog();
    assertNull(cat.getTable("T"));
    assertNull(cat.getTable("T", 3));
    String t1Text = "$ion_shared_symbol_table::{" + "  name:'''T''', version:1," + "  symbols:[ '''yes''', '''no''' ]" + "}";
    registerSharedSymtab(t1Text);
    SymbolTable t1 = cat.getTable("T", 1);
    assertEquals(1, t1.getVersion());
    checkSymbol("no", 2, t1);
    checkUnknownSymbol("maybe", t1);
    assertSame(t1, cat.getTable("T"));
    assertSame(t1, cat.getTable("T", 5));
    String t2Text = "$ion_shared_symbol_table::{" + "  name:'''T''', version:2," + "  symbols:[ '''yes''', '''no''', '''maybe''' ]" + "}";
    registerSharedSymtab(t2Text);
    SymbolTable t2 = cat.getTable("T", 2);
    assertEquals(2, t2.getVersion());
    checkSymbol("maybe", 3, t2);
    assertSame(t2, cat.getTable("T"));
    assertSame(t1, cat.getTable("T", 1));
    assertSame(t2, cat.getTable("T", 5));
    assertSame(t1, cat.removeTable("T", 1));
    assertSame(t2, cat.getTable("T"));
    assertSame(t2, cat.getTable("T", 1));
    assertSame(t2, cat.getTable("T", 2));
    assertSame(t2, cat.getTable("T", 5));
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Example 74 with SymbolTable

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

the class IonBinaryWriterBuilderTest method testImmutableInitialSymtab.

@Test
public void testImmutableInitialSymtab() {
    SymbolTable sst = _Private_Utils.systemSymtab(1);
    // Immutable local symtabs shouldn't get copied.
    SymbolTable lst = Symtabs.localSymbolTableFactory().newLocalSymtab(sst);
    lst.intern("hello");
    lst.makeReadOnly();
    _Private_IonBinaryWriterBuilder b = _Private_IonBinaryWriterBuilder.standard();
    b.setInitialSymbolTable(lst);
    assertSame(lst, b.getInitialSymbolTable());
    OutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    assertTrue(symbolTableEquals(lst, writer.getSymbolTable()));
    writer = b.build(out);
    assertTrue(symbolTableEquals(lst, writer.getSymbolTable()));
}
Also used : com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 75 with SymbolTable

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

the class IonBinaryWriterBuilderTest method testImportsImmutability.

@Test(expected = UnsupportedOperationException.class)
public void testImportsImmutability() {
    SymbolTable f = Symtabs.CATALOG.getTable("fred", 1);
    SymbolTable[] symtabs = new SymbolTable[] { f };
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
    b.setImports(f);
    IonBinaryWriterBuilder b2 = b.immutable();
    assertArrayEquals(symtabs, b2.getImports());
    b2.setImports();
}
Also used : com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) 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