use of com.amazon.ion.IonSequence in project ion-java by amzn.
the class TextWriterTest method testWritingLongStrings.
@Test
public void testWritingLongStrings() throws Exception {
options = IonTextWriterBuilder.standard();
options.setInitialIvmHandling(SUPPRESS);
options.setLongStringThreshold(5);
// This is tricky because we must avoid triple-quoting multiple
// long strings in such a way that they'd get concatenated together!
IonDatagram dg = system().newDatagram();
dg.add().newNullString();
dg.add().newString("hello");
dg.add().newString("hello\nnurse");
dg.add().newString("goodbye").addTypeAnnotation("a");
dg.add().newString("what's\nup\ndoc");
expectRendering("null.string \"hello\" '''hello\nnurse''' a::'''goodbye''' \"what's\\nup\\ndoc\"", dg);
dg.clear();
dg.add().newString("looong");
IonSequence seq = dg.add().newEmptySexp();
seq.add().newString("looong");
seq.add().newString("hello");
seq.add().newString("hello\nnurse");
seq.add().newString("goodbye").addTypeAnnotation("a");
seq.add().newString("what's\nup\ndoc");
expectRendering("'''looong''' ('''looong''' \"hello\" '''hello\nnurse''' a::'''goodbye''' \"what's\\nup\\ndoc\")", dg);
dg.clear();
dg.add().newString("looong");
seq = dg.add().newEmptyList();
seq.add().newString("looong");
seq.add().newString("hello");
seq.add().newString("hello\nnurse");
seq.add().newString("what's\nup\ndoc");
expectRendering("'''looong''' ['''looong''',\"hello\",'''hello\n" + "nurse''','''what\\'s\n" + "up\n" + "doc''']", dg);
options.setLongStringThreshold(0);
expectRendering("\"looong\" [\"looong\",\"hello\",\"hello\\nnurse\",\"what's\\nup\\ndoc\"]", dg);
options.setLongStringThreshold(5);
dg.clear();
dg.add().newString("looong");
IonStruct struct = dg.add().newEmptyStruct();
struct.add("a").newString("looong");
struct.add("b").newString("hello");
struct.add("c").newString("hello\nnurse");
struct.add("d").newString("what's\nup\ndoc");
expectRendering("'''looong''' {a:'''looong''',b:\"hello\",c:'''hello\n" + "nurse''',d:'''what\\'s\n" + "up\n" + "doc'''}", dg);
options.withPrettyPrinting();
expectRendering(// TODO amzn/ion-java/issues/57 determine if these really should be platform independent newlines
format("%n" + "'''looong'''%n" + "{%n" + " a:'''looong''',%n" + " b:\"hello\",%n" + " c:'''hello\n" + "nurse''',%n" + " d:'''what\\'s\n" + "up\n" + "doc'''%n" + "}"), dg);
}
use of com.amazon.ion.IonSequence in project ion-java by amzn.
the class IonListSexpLiteSublistTest method sublistSublistChangingParentValues.
@Test
public void sublistSublistChangingParentValues() {
IonSequence sequence = newSequence();
// 1,2,3,4
final List<IonValue> sublist = sequence.subList(1, 5);
// 1,2
final List<IonValue> subSublist = sublist.subList(0, 2);
final IonInt newValue = SYSTEM.newInt(100);
sequence.set(1, newValue);
assertEquals(newValue, sublist.get(0));
assertEquals(newValue, subSublist.get(0));
}
use of com.amazon.ion.IonSequence in project ion-java by amzn.
the class IonListSexpLiteSublistTest method sublistSetOnParent.
@Test
public void sublistSetOnParent() {
final IonSequence sequence = newSequence();
final List<IonValue> sublist = sequence.subList(2, 5);
final IonInt element = SYSTEM.newInt(99);
final IonValue previous = sequence.set(2, element);
assertEquals(2, ((IonInt) previous).intValue());
assertEquals(element, sublist.get(0));
assertEquals(element, sequence.get(2));
}
use of com.amazon.ion.IonSequence in project ion-java by amzn.
the class IonSequenceLiteSubListViewEqualityTests method testSublistEquivalence.
// makes a sublist of seq and asserts its equivalence to sublists of all sequence types and to a sublist
// derived from ARRAY_LIST
private static void testSublistEquivalence(List<IonValue> seq, SublistMaker maker) {
List<IonValue> subList = maker.makeSublist(seq);
for (IonSequence otherSeq : getTestSequences()) {
List<IonValue> otherSubList = maker.makeSublist(otherSeq);
assertEquals("subLists should be equivalent", subList, otherSubList);
assertEquals("subLists should have the same hashCode", subList.hashCode(), otherSubList.hashCode());
}
List<IonValue> ararySubList = maker.makeSublist(ARRAY_LIST);
assertEquals("subList should be equivalent to a sublist of ARRAY_LIST", ararySubList, subList);
assertEquals("subList should have the same hash code as a sublist of ARRAY_LIST", ararySubList.hashCode(), subList.hashCode());
}
use of com.amazon.ion.IonSequence in project ion-java by amzn.
the class BaseIonSequenceLiteSublistTestCase method sublistToTypedArrayConcurrentModification.
@Test(expected = ConcurrentModificationException.class)
public void sublistToTypedArrayConcurrentModification() {
final IonSequence sequence = newSequence();
final List<IonValue> sublist = sequence.subList(2, 5);
sequence.remove(0);
sublist.toArray(IonValue.EMPTY_ARRAY);
}
Aggregations