Search in sources :

Example 16 with IonStruct

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());
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 17 with IonStruct

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;
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList) IonTextUtils.printString(com.amazon.ion.util.IonTextUtils.printString)

Example 18 with IonStruct

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());
}
Also used : IonTextWriterBuilder(com.amazon.ion.system.IonTextWriterBuilder) IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) IonWriter(com.amazon.ion.IonWriter) Test(org.junit.Test)

Example 19 with IonStruct

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);
}
Also used : IonStruct(com.amazon.ion.IonStruct) Test(org.junit.Test)

Example 20 with IonStruct

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());
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) IonString(com.amazon.ion.IonString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

IonStruct (com.amazon.ion.IonStruct)68 Test (org.junit.Test)28 IonValue (com.amazon.ion.IonValue)18 IonDatagram (com.amazon.ion.IonDatagram)13 IonList (com.amazon.ion.IonList)13 IonReader (com.amazon.ion.IonReader)13 SymbolTable (com.amazon.ion.SymbolTable)13 IOException (java.io.IOException)8 IonString (com.amazon.ion.IonString)7 IonSystem (com.amazon.ion.IonSystem)6 IonException (com.amazon.ion.IonException)5 IonSequence (com.amazon.ion.IonSequence)5 IonType (com.amazon.ion.IonType)5 IonFloat (com.amazon.ion.IonFloat)4 IonSymbol (com.amazon.ion.IonSymbol)4 IonTimestamp (com.amazon.ion.IonTimestamp)4 IonWriter (com.amazon.ion.IonWriter)4 SymbolToken (com.amazon.ion.SymbolToken)4 ArrayList (java.util.ArrayList)4 IonBlob (com.amazon.ion.IonBlob)3