use of com.amazon.ion.IonValue in project ion-java by amzn.
the class IonWriterTestCase method testWritingClearedAnnotations.
/**
* Test case to ensure that {@link IonWriter#setTypeAnnotations(String...)}
* and {@link IonWriter#setTypeAnnotationSymbols(SymbolToken...)} clearing
* of type annotations behavior is correct.
*/
@Test
public void testWritingClearedAnnotations() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
// ===== Test on IonWriter.setTypeAnnotationSymbols(...) =====
// empty SymbolToken[]
iw.setTypeAnnotationSymbols(new SymbolToken[0]);
iw.writeNull();
IonValue v = expected.add().newNull();
v.clearTypeAnnotations();
// null SymbolToken[]
iw.setTypeAnnotationSymbols((SymbolToken[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
// empty SymbolToken[]
iw.setTypeAnnotationSymbols(new SymbolToken[0]);
// expected: the pending "b" annotation is cleared
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
// null SymbolToken[]
iw.setTypeAnnotationSymbols((SymbolToken[]) null);
// expected: the pending "b" annotation is cleared
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
// ===== Test on IonWriter.setTypeAnnotations(...) =====
// empty String[]
iw.setTypeAnnotations(new String[0]);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
// null String[]
iw.setTypeAnnotations((String[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
// empty String[]
iw.setTypeAnnotations(new String[0]);
// expected: the pending "b" annotation is cleared
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
// null String[]
iw.setTypeAnnotations((String[]) null);
// expected: the pending "b" annotation is cleared
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
assertEquals(expected, reload());
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class IonWriterTestCase method testWritingAnnotations.
@Test
public void testWritingAnnotations() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
iw.addTypeAnnotation("a");
iw.writeNull();
IonValue v = expected.add().newNull();
v.addTypeAnnotation("a");
iw.addTypeAnnotation("b");
iw.addTypeAnnotation("c");
iw.writeNull();
v = expected.add().newNull();
v.addTypeAnnotation("b");
v.addTypeAnnotation("c");
iw.addTypeAnnotation("b");
iw.addTypeAnnotation("b");
iw.writeNull();
v = expected.add().newNull();
v.setTypeAnnotations("b", "b");
iw.setTypeAnnotations("b", "b");
iw.writeNull();
v = expected.add().newNull();
v.setTypeAnnotations("b", "b");
iw.addTypeAnnotation("b");
iw.setTypeAnnotations("c", "d");
iw.writeNull();
v = expected.add().newNull();
v.setTypeAnnotations("c", "d");
iw.addTypeAnnotation("b");
iw.setTypeAnnotations(new String[0]);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotations((String[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotations();
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotationSymbols(new SymbolToken[0]);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotationSymbols((SymbolToken[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotationSymbols();
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
assertEquals(expected, reload());
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class IonWriterTestCase method testWritingAnnotationWithBadSid.
@Test
public void testWritingAnnotationWithBadSid() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
iw.setTypeAnnotationSymbols(newSymbolToken("a", 99));
// expected: the type annotation is written
iw.writeNull();
IonValue v = expected.add().newNull();
v.setTypeAnnotations("a");
assertEquals(expected, reload());
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class IterationTest method testSimpleIteration.
// =========================================================================
// Test cases
@Test
public void testSimpleIteration() {
Iterator<IonValue> i = system().iterate("abc");
assertTrue(i.hasNext());
IonSymbol value = (IonSymbol) i.next();
checkSymbol("abc", value);
assertFalse(i.hasNext());
checkEmptyIterator(i);
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class ReverseBinaryEncoder method writeIonDatagramContent.
private void writeIonDatagramContent(IonDatagram dg) {
ListIterator<IonValue> reverseIter = dg.listIterator(dg.size());
while (reverseIter.hasPrevious()) {
IonValue currentTopLevelValue = reverseIter.previous();
checkLocalSymbolTablePlacement(currentTopLevelValue);
writeIonValue(currentTopLevelValue);
}
}
Aggregations