use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class BinaryWriterTest method testInternUnlockedSymtab.
@Test
public void testInternUnlockedSymtab() throws Exception {
iw = makeWriter();
iw.writeSymbol("force a local symtab");
SymbolTable symtab = iw.getSymbolTable();
assertTrue(!symtab.isReadOnly());
assertTrue(symtab.isLocalTable());
symtab.intern("d");
iw.stepIn(IonType.STRUCT);
{
// this causes e to be interned
iw.setFieldName("e");
iw.writeInt(1);
// d was already interned
iw.setFieldName("d");
iw.writeInt(2);
}
iw.stepOut();
symtab.makeReadOnly();
assertTrue(symtab.isReadOnly());
SymbolToken d = symtab.find("d");
SymbolToken e = symtab.find("e");
assertEquals("d", d.assumeText());
assertEquals("e", e.assumeText());
// verify that manually interning d first worked
assertTrue(d.getSid() < e.getSid());
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonAssert method checkSymbol.
/**
* @param expectedText null means absent
*/
public static void checkSymbol(IonReader in, String expectedText, int expectedSid) {
assertSame(IonType.SYMBOL, in.getType());
assertFalse(in.isNullValue());
if (expectedText == null) {
try {
in.stringValue();
fail("Expected " + UnknownSymbolException.class);
} catch (UnknownSymbolException e) {
assertEquals(expectedSid, e.getSid());
}
} else {
assertEquals("IonReader.stringValue()", expectedText, in.stringValue());
}
SymbolToken sym = in.symbolValue();
IonTestCase.checkSymbol(expectedText, expectedSid, sym);
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonAssert method sortFields.
/**
* Problematic with unknown field names.
* See {@link Equivalence} for another use of this idiom.
*/
private static HashMap<SymbolToken, List<IonValue>> sortFields(IonStruct s) {
HashMap<SymbolToken, List<IonValue>> sorted = new HashMap<SymbolToken, List<IonValue>>();
for (IonValue v : s) {
SymbolToken tok = v.getFieldNameSymbol();
if (!sorted.containsKey(tok)) {
sorted.put(tok, new ArrayList<IonValue>());
}
sorted.get(tok).add(v);
}
return sorted;
}
Aggregations