use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncSimpleObjectTest method _testNumbers.
private void _testNumbers(JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
// start with "no token"
assertNull(r.currentToken());
assertToken(JsonToken.START_OBJECT, r.nextToken());
assertToken(JsonToken.FIELD_NAME, r.nextToken());
assertEquals("i1", r.currentText());
assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
assertEquals(NumberType.INT, r.getNumberType());
assertEquals(NUMBER_EXP_I, r.getIntValue());
assertEquals((double) NUMBER_EXP_I, r.getDoubleValue());
assertToken(JsonToken.FIELD_NAME, r.nextToken());
assertEquals("doubley", r.currentText());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
assertEquals(NumberType.DOUBLE, r.getNumberType());
assertEquals(NUMBER_EXP_D, r.getDoubleValue());
assertEquals((long) NUMBER_EXP_D, r.getLongValue());
assertToken(JsonToken.FIELD_NAME, r.nextToken());
assertEquals("biggieDecimal", r.currentText());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
// can't really tell double/BigDecimal apart in plain json
assertEquals(NumberType.DOUBLE, r.getNumberType());
assertEquals(NUMBER_EXP_BD, r.getDecimalValue());
assertEquals("" + NUMBER_EXP_BD, r.currentText());
assertToken(JsonToken.END_OBJECT, r.nextToken());
// and end up with "no token" as well
assertNull(r.nextToken());
assertTrue(r.isClosed());
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncTokenErrorTest method testMangledNonRootInts.
public void testMangledNonRootInts() throws Exception {
AsyncReaderWrapper p = _createParser("[ 123true ]");
assertToken(JsonToken.START_ARRAY, p.nextToken());
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: " + t);
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncNumberLeadingZeroesTest method _testLeadingZeroesFloat.
public void _testLeadingZeroesFloat(String valueStr, double value) throws Exception {
// first: verify that we get an exception
JsonFactory f = new JsonFactory();
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS));
String JSON = valueStr;
AsyncReaderWrapper p = createParser(f, JSON);
try {
p.nextToken();
p.currentText();
fail("Should have thrown an exception for doc <" + JSON + ">");
} catch (JsonParseException e) {
verifyException(e, "invalid numeric value");
} finally {
p.close();
}
// and then verify it's ok when enabled
f = f.rebuild().enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS).build();
assertTrue(f.isEnabled(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS));
p = createParser(f, JSON);
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(String.valueOf(value), p.currentText());
assertEquals(value, p.getDoubleValue());
p.close();
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncRootNumbersTest method _testRootDoubles.
private void _testRootDoubles(double value, JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
assertNull(r.currentToken());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
assertEquals(value, r.getDoubleValue());
assertNull(r.nextToken());
assertTrue(r.isClosed());
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncScalarArrayTest method _testTokens.
private void _testTokens(JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
// start with "no token"
assertNull(r.currentToken());
assertToken(JsonToken.START_ARRAY, r.nextToken());
assertToken(JsonToken.VALUE_TRUE, r.nextToken());
assertToken(JsonToken.VALUE_FALSE, r.nextToken());
assertEquals("false", r.currentText());
assertEquals("false", r.currentTextViaCharacters());
assertToken(JsonToken.VALUE_TRUE, r.nextToken());
assertToken(JsonToken.VALUE_NULL, r.nextToken());
assertEquals("null", r.currentText());
assertEquals("null", r.currentTextViaCharacters());
assertToken(JsonToken.VALUE_FALSE, r.nextToken());
assertToken(JsonToken.VALUE_NULL, r.nextToken());
assertToken(JsonToken.END_ARRAY, r.nextToken());
// and end up with "no token" as well
assertNull(r.nextToken());
assertTrue(r.isClosed());
}
Aggregations