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();
}
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());
}
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));
}
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()));
}
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();
}
Aggregations