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;
}
}
}
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));
}
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));
}
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);
}
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);
}
Aggregations