use of com.amazon.ion.IonStruct in project ion-java by amzn.
the class SymbolTableTest method testSymtabImageMaintenance.
@Test
public void testSymtabImageMaintenance() {
IonSystem system = system();
SymbolTable st = ((_Private_ValueFactory) system).getLstFactory().newLocalSymtab(system.getSystemSymbolTable());
st.intern("foo");
IonStruct image = symtabTree(st, system);
st.intern("bar");
image = symtabTree(st, system);
IonList symbols = (IonList) image.get(SYMBOLS);
assertEquals("[\"foo\",\"bar\"]", symbols.toString());
}
use of com.amazon.ion.IonStruct in project ion-java by amzn.
the class Symtabs method sharedSymtabStruct.
/**
* Constructs the DOM for a shared symtab.
*
* @param syms If null, so symbols list will be added.
*/
public static IonStruct sharedSymtabStruct(ValueFactory factory, String name, int version, String... syms) {
IonStruct s = factory.newEmptyStruct();
s.setTypeAnnotations(SystemSymbols.ION_SHARED_SYMBOL_TABLE);
s.add(SystemSymbols.NAME).newString(name);
s.add(SystemSymbols.VERSION).newInt(version);
if (syms != null) {
IonList l = s.add(SystemSymbols.SYMBOLS).newEmptyList();
for (String sym : syms) {
l.add().newString(sym);
}
}
return s;
}
use of com.amazon.ion.IonStruct in project ion-java by amzn.
the class TextWriterTest method testWritingTopLevelValuesOnNewLinesWithoutPrettyPrint.
@Test
public void testWritingTopLevelValuesOnNewLinesWithoutPrettyPrint() {
IonTextWriterBuilder writerBuilder = IonTextWriterBuilder.standard().withInitialIvmHandling(SUPPRESS).withWriteTopLevelValuesOnNewLines(true).withNewLineType(IonTextWriterBuilder.NewLineType.LF);
IonDatagram dg = system().newDatagram();
dg.add().newString("Foo");
dg.add().newSymbol("Bar");
dg.add().newSexp(new int[] { 1, 2, 3 });
dg.add().newList(new int[] { 4, 5, 6 });
IonStruct struct = dg.add().newEmptyStruct();
struct.add("def").newInt(42);
struct.addTypeAnnotation("abc");
StringBuilder sb = new StringBuilder();
IonWriter writer = writerBuilder.build(sb);
dg.writeTo(writer);
assertEquals("\"Foo\"\nBar\n(1 2 3)\n[4,5,6]\nabc::{def:42}", sb.toString());
}
use of com.amazon.ion.IonStruct in project ion-java by amzn.
the class TreeReaderTest method testReadingStructFields.
@Test
public void testReadingStructFields() {
IonStruct s = struct("{f:null}");
in = system().newReader(s.get("f"));
assertTopLevel(in, /* inStruct */
false);
expectNoCurrentValue();
check().next().fieldName((String) null).type(IonType.NULL);
assertTopLevel(in, /* inStruct */
false);
}
use of com.amazon.ion.IonStruct in project ion-java by amzn.
the class IonWriterTestCase method testWritingSymtabWithExtraAnnotations.
// TODO amzn/ion-java/issues/15
@Test
// TODO amzn/ion-java/issues/15
@Ignore
public void testWritingSymtabWithExtraAnnotations() throws Exception {
String[] annotations = new String[] { ION_SYMBOL_TABLE, ION_SYMBOL_TABLE };
iw = makeWriter();
iw.setTypeAnnotations(annotations);
iw.stepIn(IonType.STRUCT);
iw.stepOut();
iw.writeSymbol("foo");
iw.close();
IonDatagram dg = reload();
IonStruct v = (IonStruct) dg.systemGet(1);
Assert.assertArrayEquals(annotations, v.getTypeAnnotations());
}
Aggregations