Search in sources :

Example 36 with IonSequence

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

Example 37 with IonSequence

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

Example 38 with IonSequence

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

Example 39 with IonSequence

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());
}
Also used : IonValue(com.amazon.ion.IonValue) IonSequence(com.amazon.ion.IonSequence)

Example 40 with IonSequence

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

Aggregations

IonSequence (com.amazon.ion.IonSequence)68 Test (org.junit.Test)62 IonValue (com.amazon.ion.IonValue)61 IonInt (com.amazon.ion.IonInt)17 IonStruct (com.amazon.ion.IonStruct)5 IonLob (com.amazon.ion.IonLob)3 IonType (com.amazon.ion.IonType)3 SymbolToken (com.amazon.ion.SymbolToken)2 ArrayList (java.util.ArrayList)2 IonBool (com.amazon.ion.IonBool)1 IonDatagram (com.amazon.ion.IonDatagram)1 IonException (com.amazon.ion.IonException)1 IonFloat (com.amazon.ion.IonFloat)1 IonSymbol (com.amazon.ion.IonSymbol)1 IonText (com.amazon.ion.IonText)1 IonTimestamp (com.amazon.ion.IonTimestamp)1 SymbolTable (com.amazon.ion.SymbolTable)1 IOException (java.io.IOException)1