Search in sources :

Example 6 with IonDatagram

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

the class SymbolTableTest method testLocalTableWithLesserImport.

/**
 * Import v2 but catalog has v1.
 */
@Test
public void testLocalTableWithLesserImport() throws IOException {
    final int import1id = systemMaxId() + 1;
    final int import2id = systemMaxId() + 2;
    final int fred3id = systemMaxId() + 3;
    final int maxLocalId = systemMaxId() + IMPORTED_2_MAX_ID + 2;
    registerImportedV1();
    registerImportedV2();
    String text = LocalSymbolTablePrefix + "{" + "  imports:[{name:\"imported\", version:2, " + "            max_id:" + IMPORTED_2_MAX_ID + "}]," + "}\n" + "local1 local2 'imported 1' 'imported 2' fred3";
    byte[] binary = encode(text);
    // Remove the imported table before decoding the binary.
    SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
    assertNotNull(catalog.removeTable("imported", 2));
    IonDatagram dg = loader().load(binary);
    checkSymbol("local1", dg.get(0));
    checkSymbol("local2", dg.get(1));
    checkSymbol("imported 1", import1id, dg.get(2));
    checkSymbol("imported 2", import2id, dg.get(3));
    checkUnknownSymbol(fred3id, dg.get(4));
    SymbolTable st = dg.get(0).getSymbolTable();
    checkFirstImport("imported", 2, new String[] { "imported 1", "imported 2", null, null }, st);
    assertTrue(st.isLocalTable());
    assertEquals(maxLocalId, st.getMaxId());
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 7 with IonDatagram

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

the class TextWriterTest method testWritingFloatNegativeInfinityToJson.

@Test
public void testWritingFloatNegativeInfinityToJson() throws Exception {
    options = IonTextWriterBuilder.json();
    options.setInitialIvmHandling(SUPPRESS);
    IonDatagram dg = system().newDatagram();
    dg.add().newFloat(Double.NEGATIVE_INFINITY);
    iw = makeWriter();
    dg.writeTo(iw);
    String actual = outputString();
    assertEquals("null", actual);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 8 with IonDatagram

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

the class TextWriterTest method testWritingFloatNanToJson.

@Test
public void testWritingFloatNanToJson() throws Exception {
    options = IonTextWriterBuilder.json();
    options.setInitialIvmHandling(SUPPRESS);
    IonDatagram dg = system().newDatagram();
    dg.add().newFloat(Double.NaN);
    iw = makeWriter();
    dg.writeTo(iw);
    String actual = outputString();
    assertEquals("null", actual);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 9 with IonDatagram

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

the class TextWriterTest method testWritingTopLevelValuesOnNewLinesShouldHaveNoEffectWithPrettyPrint.

@Test
public void testWritingTopLevelValuesOnNewLinesShouldHaveNoEffectWithPrettyPrint() {
    // Setting top-level newlines to false should have no effect when pretty printing.
    IonTextWriterBuilder writerBuilder = IonTextWriterBuilder.standard().withInitialIvmHandling(SUPPRESS).withWriteTopLevelValuesOnNewLines(false).withPrettyPrinting().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 });
    StringBuilder sb = new StringBuilder();
    IonWriter writer = writerBuilder.build(sb);
    dg.writeTo(writer);
    assertEquals("\n\"Foo\"\nBar\n(\n  1\n  2\n  3\n)\n[\n  4,\n  5,\n  6\n]", sb.toString());
}
Also used : IonTextWriterBuilder(com.amazon.ion.system.IonTextWriterBuilder) IonDatagram(com.amazon.ion.IonDatagram) IonWriter(com.amazon.ion.IonWriter) Test(org.junit.Test)

Example 10 with IonDatagram

use of com.amazon.ion.IonDatagram 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)

Aggregations

IonDatagram (com.amazon.ion.IonDatagram)92 Test (org.junit.Test)77 IonValue (com.amazon.ion.IonValue)20 SymbolTable (com.amazon.ion.SymbolTable)18 IonReader (com.amazon.ion.IonReader)17 IonString (com.amazon.ion.IonString)15 IonStruct (com.amazon.ion.IonStruct)13 IonWriter (com.amazon.ion.IonWriter)11 IonSymbol (com.amazon.ion.IonSymbol)6 IonSystem (com.amazon.ion.IonSystem)6 IonLoader (com.amazon.ion.IonLoader)5 IonType (com.amazon.ion.IonType)5 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)5 BlobTest (com.amazon.ion.BlobTest)4 ClobTest (com.amazon.ion.ClobTest)4 IntTest (com.amazon.ion.IntTest)4 IonList (com.amazon.ion.IonList)4 IonTextWriterBuilder (com.amazon.ion.system.IonTextWriterBuilder)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BinaryTest (com.amazon.ion.BinaryTest)2