Search in sources :

Example 1 with IonSequence

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

the class IonAssert method doAssertIonEquals.

// ========================================================================
private static void doAssertIonEquals(String path, IonValue expected, IonValue actual) {
    if (expected == actual)
        return;
    IonType expectedType = expected.getType();
    assertSame(path + " type", expectedType, actual.getType());
    assertEqualAnnotations(path, expected, actual);
    if (expected.isNullValue() || actual.isNullValue()) {
        assertEquals(path, expected, actual);
        return;
    }
    switch(expectedType) {
        case BOOL:
        case DECIMAL:
        case FLOAT:
        case INT:
        case NULL:
        case STRING:
        case SYMBOL:
        case TIMESTAMP:
            {
                // "Normal" IonValue.equals()
                assertEquals(path + " IonValue", expected, actual);
                break;
            }
        case BLOB:
        case CLOB:
            {
                assertArrayEquals(path, ((IonLob) expected).getBytes(), ((IonLob) actual).getBytes());
                break;
            }
        // user data, not system data.
        case DATAGRAM:
        case LIST:
        case SEXP:
            {
                assertSequenceEquals(path, (IonSequence) expected, (IonSequence) actual);
                break;
            }
        case STRUCT:
            {
                assertStructEquals(path, (IonStruct) expected, (IonStruct) actual);
                break;
            }
    }
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonType(com.amazon.ion.IonType) IonLob(com.amazon.ion.IonLob) IonSequence(com.amazon.ion.IonSequence)

Example 2 with IonSequence

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

the class IonListSexpLiteSublistTest method sublistListIteratorWithSet.

@Test
public void sublistListIteratorWithSet() {
    final IonSequence sequence = newSequence();
    final List<IonValue> sublist = sequence.subList(2, 5);
    final ListIterator<IonValue> iterator = sublist.listIterator();
    iterator.next();
    final IonInt newSetValue = SYSTEM.newInt(100);
    iterator.set(newSetValue);
    assertEquals(newSetValue, sublist.get(0));
}
Also used : IonValue(com.amazon.ion.IonValue) IonInt(com.amazon.ion.IonInt) IonSequence(com.amazon.ion.IonSequence) Test(org.junit.Test)

Example 3 with IonSequence

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

the class IonListSexpLiteSublistTest method sublistSet.

@Test
public void sublistSet() {
    final IonSequence sequence = newSequence();
    final List<IonValue> sublist = sequence.subList(2, 5);
    final IonInt element = SYSTEM.newInt(99);
    final IonValue previous = sublist.set(0, 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 4 with IonSequence

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

the class IonListSexpLiteSublistTest method sublistSetOutOfRange.

@Test(expected = IndexOutOfBoundsException.class)
public void sublistSetOutOfRange() {
    final IonSequence sequence = newSequence();
    final List<IonValue> sublist = sequence.subList(2, 5);
    final IonInt element = SYSTEM.newInt(99);
    sublist.set(4, element);
}
Also used : IonValue(com.amazon.ion.IonValue) IonInt(com.amazon.ion.IonInt) IonSequence(com.amazon.ion.IonSequence) Test(org.junit.Test)

Example 5 with IonSequence

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

the class IonSequenceLiteSubListViewEqualityTests method testSublistNonEquivalence.

// makes a sublist of seq and asserts its non-equivalence to the same subList range of the "other" sequence
// and to a sublist derived from OTHER_ARRAY_LIST
private static void testSublistNonEquivalence(List<IonValue> seq, SublistMaker maker) {
    // A hash collision is unlikely but possible so we do not assert that the hashCodes are different here.
    List<IonValue> subList = maker.makeSublist(seq);
    for (IonSequence otherSeq : getOtherTestSequences()) {
        List<IonValue> otherSubList = maker.makeSublist(otherSeq);
        assertNotEquals("subLists should *not* be equivalent", subList, otherSubList);
    }
    assertNotEquals("subList should *not* be equivalent to a sublist of OTHER_ARRAY_LIST", maker.makeSublist(OTHER_ARRAY_LIST), subList);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSequence(com.amazon.ion.IonSequence)

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