Search in sources :

Example 26 with IonValue

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

the class SymbolTableTest method testOverridingImportedSymbolId.

@Test
public void testOverridingImportedSymbolId() {
    SymbolTable importedTable = registerImportedV1();
    final int import1id = systemMaxId() + 1;
    final int import1DupId = systemMaxId() + importedTable.getMaxId() + 1;
    String importingText = "$ion_1_0 " + LocalSymbolTablePrefix + "{" + "  imports:[{name:'''imported''', version:1, max_id:2}]," + "  symbols:[ '''imported 1''' ]," + "}\n" + "'imported 1'\n" + "$" + import1id;
    Iterator<IonValue> scanner = system().iterate(importingText);
    IonValue value = scanner.next();
    checkSymbol("imported 1", import1id, value);
    SymbolTable symtab = value.getSymbolTable();
    checkLocalTable(symtab);
    checkSymbol("imported 1", import1id, symtab);
    checkSymbol("imported 1", import1DupId, /* dupe */
    true, symtab);
    // Here the input text is $NNN  but it comes back correctly.
    value = scanner.next();
    checkSymbol("imported 1", import1id, value);
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 27 with IonValue

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

the class SymbolTableTest method testImportWithZeroMaxId.

// TODO test getUsedTable(null)
// TODO test getImportedTable(null)
@Test
public void testImportWithZeroMaxId() throws Exception {
    registerImportedV1();
    String text = LocalSymbolTablePrefix + "{" + "  imports:[{name:\"imported\", version:1, max_id:0}]," + "  symbols:['''local''']" + "}\n" + "null";
    IonValue v = oneValue(text);
    SymbolTable symbolTable = v.getSymbolTable();
    SymbolTable imported = checkFirstImport("imported", 1, EMPTY_STRING_ARRAY, symbolTable);
    assertTrue(imported.isSubstitute());
    checkUnknownSymbol("imported 1", 1, imported);
    checkSymbol("local", systemMaxId() + 1, symbolTable);
    checkUnknownSymbol("imported 1", UNKNOWN_SYMBOL_ID, symbolTable);
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 28 with IonValue

use of com.amazon.ion.IonValue 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 29 with IonValue

use of com.amazon.ion.IonValue 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 30 with IonValue

use of com.amazon.ion.IonValue 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)

Aggregations

IonValue (com.amazon.ion.IonValue)185 Test (org.junit.Test)115 IonSequence (com.amazon.ion.IonSequence)61 SymbolTable (com.amazon.ion.SymbolTable)21 IonDatagram (com.amazon.ion.IonDatagram)20 IonStruct (com.amazon.ion.IonStruct)18 IonInt (com.amazon.ion.IonInt)16 IOException (java.io.IOException)14 IonReader (com.amazon.ion.IonReader)13 IonSystem (com.amazon.ion.IonSystem)12 Result (software.amazon.qldb.Result)11 SymbolToken (com.amazon.ion.SymbolToken)10 ArrayList (java.util.ArrayList)10 IonString (com.amazon.ion.IonString)9 IonException (com.amazon.ion.IonException)7 IonType (com.amazon.ion.IonType)6 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)6 Event (com.amazon.tools.events.Event)5 com.amazon.ion.impl._Private_IonValue (com.amazon.ion.impl._Private_IonValue)4 EventType (com.amazon.tools.events.EventType)4