use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncTokenErrorTest method testMangledRootFloats.
public void testMangledRootFloats() throws Exception {
// Also test with floats
AsyncReaderWrapper p = _createParser("1.5false");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: " + t + "; number: " + p.getNumberValue());
} 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 AsyncTokenErrorTest method _doTestInvalidKeyword.
private void _doTestInvalidKeyword(String value) throws IOException {
String doc = "{ \"key1\" : " + value + " }";
AsyncReaderWrapper p = _createParser(doc);
assertToken(JsonToken.START_OBJECT, p.nextToken());
// get the exception early or late...
try {
assertToken(JsonToken.FIELD_NAME, p.nextToken());
p.nextToken();
fail("Expected an exception for malformed value keyword");
} catch (JsonParseException jex) {
verifyException(jex, "Unrecognized token");
verifyException(jex, value);
} finally {
p.close();
}
// Try as root-level value as well:
// may need space after for DataInput
doc = value + " ";
p = _createParser(doc);
try {
p.nextToken();
fail("Expected an exception for malformed value keyword");
} catch (JsonParseException jex) {
verifyException(jex, "Unrecognized token");
verifyException(jex, value);
} finally {
p.close();
}
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncNumberLeadingZeroesTest method _testLeadingZeroesInt.
public void _testLeadingZeroesInt(String valueStr, int 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_INT, p.nextToken());
assertEquals(value, p.getIntValue());
assertEquals(String.valueOf(value), p.currentText());
p.close();
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncRootNumbersTest method _testRootInts.
private void _testRootInts(int 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_INT, r.nextToken());
assertEquals(value, r.getIntValue());
assertNull(r.nextToken());
assertTrue(r.isClosed());
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncScalarArrayTest method _testInts.
private void _testInts(JsonFactory f, int[] values, 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());
for (int i = 0; i < values.length; ++i) {
assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
assertEquals(values[i], r.getIntValue());
assertEquals(NumberType.INT, r.getNumberType());
// and then couple of special modes, just to get better test coverage
String asStr = String.valueOf(values[i]);
assertEquals(asStr, r.currentText());
StringWriter sw = new StringWriter();
assertEquals(asStr.length(), r.parser().getText(sw));
assertEquals(asStr, sw.toString());
}
assertToken(JsonToken.END_ARRAY, r.nextToken());
// and end up with "no token" as well
assertNull(r.nextToken());
assertTrue(r.isClosed());
}
Aggregations