Search in sources :

Example 41 with AsyncReaderWrapper

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();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) Test(org.junit.Test)

Example 42 with AsyncReaderWrapper

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();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) Test(org.junit.Test)

Example 43 with AsyncReaderWrapper

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();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) Test(org.junit.Test)

Example 44 with AsyncReaderWrapper

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();
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) IOException(java.io.IOException)

Example 45 with AsyncReaderWrapper

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();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Aggregations

AsyncReaderWrapper (com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)87 Test (org.junit.Test)10 JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)5 BigDecimal (java.math.BigDecimal)4 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 NonBlockingJsonParserBase (com.fasterxml.jackson.core.json.async.NonBlockingJsonParserBase)2 ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2