Search in sources :

Example 6 with SymbolToken

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

the class SharedSymbolTableTest method testFindSymbolToken.

// -------------------------------------------------------------------------
// find()
@Test
public void testFindSymbolToken() {
    SymbolTable st = makeAbcTable();
    SymbolToken tok = st.find(OTHER_A);
    assertSame(A, tok.getText());
    assertEquals(st.getImportedMaxId() + 1, tok.getSid());
    tok = st.find("not there");
    assertNull(tok);
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 7 with SymbolToken

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

the class IonAssert method assertStructEquals.

private static void assertStructEquals(String path, IonStruct expected, IonStruct actual) {
    int expectedSize = expected.size();
    int actualSize = actual.size();
    if (expectedSize != actualSize) {
        fail(String.format("%s size, expected:%s actual:%s", path, expectedSize, actualSize));
    }
    Map<SymbolToken, List<IonValue>> expectedFields = sortFields(expected);
    Map<SymbolToken, List<IonValue>> actualFields = sortFields(actual);
    for (Entry<SymbolToken, List<IonValue>> expectedEntry : expectedFields.entrySet()) {
        SymbolToken token = expectedEntry.getKey();
        String fieldPath = path + '.' + printSymbol(token);
        List<IonValue> actualList = actualFields.get(token);
        if (actualList == null) {
            fail(String.format("Missing field %s, expected: %s actual: %s", fieldPath, expected, actual));
        }
        assertFieldEquals(fieldPath, expectedEntry.getValue(), actual, actualList);
    }
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolToken(com.amazon.ion.SymbolToken) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with SymbolToken

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

the class IonAssert method checkSymbol.

/**
 * @param expectedText null means null.symbol
 */
public static void checkSymbol(String expectedText, IonReader in) {
    assertEquals("getType", IonType.SYMBOL, in.getType());
    assertEquals("isNullValue", expectedText == null, in.isNullValue());
    assertEquals("stringValue", expectedText, in.stringValue());
    SymbolToken symTok = in.symbolValue();
    if (expectedText == null) {
        assertEquals("symbolValue", null, symTok);
    } else {
        assertEquals("symbolValue.text", expectedText, symTok.getText());
    }
}
Also used : SymbolToken(com.amazon.ion.SymbolToken)

Example 9 with SymbolToken

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

the class IonReaderBinaryIncrementalTest method nonStringInSymbolsListCreatesNullSlot.

@Test
public void nonStringInSymbolsListCreatesNullSlot() throws Exception {
    IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {

        @Override
        public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
            SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
            writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
            writer.stepIn(IonType.LIST);
            writer.writeString(null);
            writer.writeString("abc");
            writer.writeInt(123);
            writer.stepOut();
            writer.stepOut();
            writer.writeSymbolToken(10);
            writer.writeSymbolToken(11);
            writer.writeSymbolToken(12);
        }
    });
    assertEquals(IonType.SYMBOL, reader.next());
    SymbolToken symbolValue = reader.symbolValue();
    assertNull(symbolValue.getText());
    assertEquals(0, symbolValue.getSid());
    assertEquals(IonType.SYMBOL, reader.next());
    symbolValue = reader.symbolValue();
    assertEquals("abc", symbolValue.getText());
    assertEquals(IonType.SYMBOL, reader.next());
    symbolValue = reader.symbolValue();
    assertNull(symbolValue.getText());
    assertEquals(0, symbolValue.getSid());
    reader.close();
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) com.amazon.ion.impl.bin._Private_IonRawWriter(com.amazon.ion.impl.bin._Private_IonRawWriter) SymbolTable(com.amazon.ion.SymbolTable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with SymbolToken

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

the class IonWriterTestCase method testWritingClearedAnnotations.

/**
 * Test case to ensure that {@link IonWriter#setTypeAnnotations(String...)}
 * and {@link IonWriter#setTypeAnnotationSymbols(SymbolToken...)} clearing
 * of type annotations behavior is correct.
 */
@Test
public void testWritingClearedAnnotations() throws Exception {
    iw = makeWriter();
    IonDatagram expected = system().newDatagram();
    // ===== Test on IonWriter.setTypeAnnotationSymbols(...) =====
    // empty SymbolToken[]
    iw.setTypeAnnotationSymbols(new SymbolToken[0]);
    iw.writeNull();
    IonValue v = expected.add().newNull();
    v.clearTypeAnnotations();
    // null SymbolToken[]
    iw.setTypeAnnotationSymbols((SymbolToken[]) null);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    // empty SymbolToken[]
    iw.setTypeAnnotationSymbols(new SymbolToken[0]);
    // expected: the pending "b" annotation is cleared
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    // null SymbolToken[]
    iw.setTypeAnnotationSymbols((SymbolToken[]) null);
    // expected: the pending "b" annotation is cleared
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    // ===== Test on IonWriter.setTypeAnnotations(...) =====
    // empty String[]
    iw.setTypeAnnotations(new String[0]);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    // null String[]
    iw.setTypeAnnotations((String[]) null);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    // empty String[]
    iw.setTypeAnnotations(new String[0]);
    // expected: the pending "b" annotation is cleared
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    // null String[]
    iw.setTypeAnnotations((String[]) null);
    // expected: the pending "b" annotation is cleared
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    assertEquals(expected, reload());
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolToken(com.amazon.ion.SymbolToken) com.amazon.ion.impl._Private_Utils.newSymbolToken(com.amazon.ion.impl._Private_Utils.newSymbolToken) FakeSymbolToken(com.amazon.ion.FakeSymbolToken) IonDatagram(com.amazon.ion.IonDatagram) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Aggregations

SymbolToken (com.amazon.ion.SymbolToken)68 SymbolTable (com.amazon.ion.SymbolTable)14 com.amazon.ion.impl._Private_Utils.newSymbolToken (com.amazon.ion.impl._Private_Utils.newSymbolToken)13 IonType (com.amazon.ion.IonType)10 IonValue (com.amazon.ion.IonValue)10 IonException (com.amazon.ion.IonException)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 IonStruct (com.amazon.ion.IonStruct)4 IOException (java.io.IOException)4 Event (com.amazon.tools.events.Event)3 EventType (com.amazon.tools.events.EventType)3 FakeSymbolToken (com.amazon.ion.FakeSymbolToken)2 IonDatagram (com.amazon.ion.IonDatagram)2 IonSequence (com.amazon.ion.IonSequence)2 IonString (com.amazon.ion.IonString)2 UnknownSymbolException (com.amazon.ion.UnknownSymbolException)2 SavePoint (com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint)2 ImportDescriptor (com.amazon.tools.events.ImportDescriptor)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2