use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncMissingValuesInArrayTest method testArrayTrailingComma.
@Test
public void testArrayTrailingComma() throws Exception {
String json = "[\"a\", \"b\",]";
AsyncReaderWrapper p = createParser(factory, json);
assertEquals(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("a", p.currentText());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("b", p.currentText());
// ALLOW_TRAILING_COMMA takes priority over ALLOW_MISSING_VALUES
if (features.contains(Feature.ALLOW_TRAILING_COMMA)) {
assertToken(JsonToken.END_ARRAY, p.nextToken());
assertEnd(p);
} else if (features.contains(Feature.ALLOW_MISSING_VALUES)) {
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertToken(JsonToken.END_ARRAY, p.nextToken());
assertEnd(p);
} else {
assertUnexpected(p, ']');
}
p.close();
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncMissingValuesInArrayTest method testArrayTrailingCommas.
@Test
public void testArrayTrailingCommas() throws Exception {
String json = "[\"a\", \"b\",,]";
AsyncReaderWrapper p = createParser(factory, json);
assertEquals(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("a", p.currentText());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("b", p.currentText());
// ALLOW_TRAILING_COMMA takes priority over ALLOW_MISSING_VALUES
if (features.contains(Feature.ALLOW_MISSING_VALUES) && features.contains(Feature.ALLOW_TRAILING_COMMA)) {
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertToken(JsonToken.END_ARRAY, p.nextToken());
assertEnd(p);
} else if (features.contains(Feature.ALLOW_MISSING_VALUES)) {
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertToken(JsonToken.END_ARRAY, p.nextToken());
assertEnd(p);
} else {
assertUnexpected(p, ',');
}
p.close();
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncMissingValuesInArrayTest method testArrayLeadingComma.
@Test
public void testArrayLeadingComma() throws Exception {
String json = "[,\"a\", \"b\"]";
AsyncReaderWrapper p = createParser(factory, json);
assertEquals(JsonToken.START_ARRAY, p.nextToken());
if (!features.contains(Feature.ALLOW_MISSING_VALUES)) {
assertUnexpected(p, ',');
return;
}
assertToken(JsonToken.VALUE_NULL, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("a", p.currentText());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("b", p.currentText());
assertEquals(JsonToken.END_ARRAY, p.nextToken());
assertEnd(p);
p.close();
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncNonStdNumbersTest method testDisallowNaN.
public void testDisallowNaN() throws Exception {
final String JSON = "[ NaN]";
assertFalse(DEFAULT_F.isEnabled(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS));
// without enabling, should get an exception
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
assertToken(JsonToken.START_ARRAY, p.nextToken());
try {
p.nextToken();
fail("Expected exception");
} catch (Exception e) {
verifyException(e, "non-standard");
} finally {
p.close();
}
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncNonStdNumbersTest method _testAllowInf.
private void _testAllowInf(JsonFactory f, String doc, int readBytes) throws Exception {
// 06-Jun-2017, tatu: Leave out "-INF" and "+INF" for now due to overlap with
// somewhat more standard (wrt JDK) "-Infinity" and "+Infinity"
AsyncReaderWrapper p = createParser(f, doc, readBytes);
assertToken(JsonToken.START_ARRAY, p.nextToken());
double d;
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
d = p.getDoubleValue();
assertEquals("Infinity", p.currentText());
assertTrue(Double.isInfinite(d));
assertTrue(d == Double.POSITIVE_INFINITY);
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
d = p.getDoubleValue();
assertEquals("+Infinity", p.currentText());
assertTrue(Double.isInfinite(d));
assertTrue(d == Double.POSITIVE_INFINITY);
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
d = p.getDoubleValue();
assertEquals("-Infinity", p.currentText());
assertTrue(Double.isInfinite(d));
assertTrue(d == Double.NEGATIVE_INFINITY);
assertToken(JsonToken.END_ARRAY, p.nextToken());
p.close();
// finally, should also work with skipping
f = f.rebuild().enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS).build();
p = createParser(f, doc, readBytes);
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertToken(JsonToken.END_ARRAY, p.nextToken());
p.close();
}
Aggregations