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