use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method symbolTableWithImportsThenSymbols.
@Test
public void symbolTableWithImportsThenSymbols() throws Exception {
SimpleCatalog catalog = new SimpleCatalog();
catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
writerBuilder = IonBinaryWriterBuilder.standard().withCatalog(catalog);
IonReaderBinaryIncremental reader = readerFor(new WriterFunction() {
@Override
public void write(IonWriter writer) throws IOException {
writer.setTypeAnnotations("$ion_symbol_table");
writer.stepIn(IonType.STRUCT);
writer.setFieldName("imports");
writer.stepIn(IonType.LIST);
writer.stepIn(IonType.STRUCT);
writer.setFieldName("name");
writer.writeString("foo");
writer.setFieldName("version");
writer.writeInt(1);
writer.setFieldName("max_id");
writer.writeInt(2);
writer.stepOut();
writer.stepOut();
writer.setFieldName("symbols");
writer.stepIn(IonType.LIST);
writer.writeString("ghi");
writer.stepOut();
writer.stepOut();
writer.writeSymbol("abc");
writer.writeSymbol("def");
writer.writeSymbol("ghi");
}
});
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("ghi", reader.stringValue());
assertNull(reader.next());
reader.close();
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class BinaryWriterTest method testFlushingUnlockedSymtabWithImports.
@Test
public void testFlushingUnlockedSymtabWithImports() throws Exception {
SimpleCatalog catalog = catalog();
byte[] bytes = flushUnlockedSymtabWithImports(catalog, false);
assertEquals(0, bytes.length);
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class SystemProcessingTestCase method testSubstituteTableWithGreaterVersionImport.
/**
* Import v2 but catalog has v3.
*/
@Test
public void testSubstituteTableWithGreaterVersionImport() throws Exception {
SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
Symtabs.register("fred", 3, catalog);
checkImportTableSpecsWithVariants(catalog);
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class SystemProcessingTestCase method testLocalTableWithLesserImport.
/**
* Import v2 but catalog has v1.
*/
@Test
public void testLocalTableWithLesserImport() throws Exception {
final int fred1id = systemMaxId() + 1;
final int fred2id = systemMaxId() + 2;
final int fred3id = systemMaxId() + 3;
final int local = systemMaxId() + Symtabs.FRED_MAX_IDS[2];
final int local3id = local + 3;
SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
Symtabs.register("fred", 1, catalog);
Symtabs.register("fred", 2, catalog);
// { name:"fred", version:1,
// symbols:["fred_1", "fred_2"]}
// { name:"fred", version:2,
// symbols:["fred_1","fred_2","fred_3","fred_4",]}
String text = LocalSymbolTablePrefix + "{" + " imports:[{name:\"fred\", version:2, " + " max_id:" + Symtabs.FRED_MAX_IDS[2] + "}]," + "}\n" + "local1 local2 fred_1 fred_2 fred_3 $12 " + "fred_3::$10 [{fred_3:local2}]";
// TODO { $12:something }
// TODO $12::something
// Nesting flushed out a bug at one point
prepare(text);
// Remove the imported table: fred version 2
// We'll read using fred version 1 with a max id of 2
// which causes fred_3 to "disappear".
// If forced to, the reader will assign fred_2 to a new local id.
assertNotNull(catalog.removeTable("fred", 2));
// at this point the effective symbol list should be:
// fred::version::'2'::symbols:[
// 10:: '''fred_1''',
// 11:: '''fred_2''',
// 12:: null,
// 13:: null,
// local::symbols:[
// 14:: '''local1''',
// 15:: '''local2''',
// 16:: '''fred_3''',
// 17:: '''fred_4''',
startIteration();
nextValue();
checkSymbol("local1");
nextValue();
checkSymbol("local2");
nextValue();
checkSymbol("fred_1", fred1id);
nextValue();
checkSymbol("fred_2", fred2id);
nextValue();
checkMissingSymbol("fred_3", fred3id);
nextValue();
// TODO checkAbsentSidLiteral("fred_3", fred3id);
nextValue();
checkSymbol("fred_1", fred1id);
checkMissingAnnotation("fred_3", fred3id);
nextValue();
stepIn();
nextValue();
stepIn();
nextValue();
checkMissingFieldName("fred_3", fred3id);
checkSymbol("local2");
checkEof();
stepOut();
checkEof();
stepOut();
checkEof();
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class SystemProcessingTestCase method testSubstituteTableWithLesserVersionImport.
/**
* Import v2 but catalog has v1.
*/
@Test
public void testSubstituteTableWithLesserVersionImport() throws Exception {
SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
Symtabs.register("fred", 1, catalog);
checkImportTableSpecsWithVariants(catalog);
}
Aggregations