Search in sources :

Example 26 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncInvalidCharsTest method _testHandlingOfInvalidSpace.

private void _testHandlingOfInvalidSpace(int offset, int readSize) throws Exception {
    final String doc = "{ \u0008 \"a\":1}";
    AsyncReaderWrapper p = asyncForBytes(JSON_F, readSize, _jsonDoc(doc), offset);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        p.nextToken();
        fail("Should have failed");
    } catch (JsonParseException e) {
        verifyException(e, "Illegal character");
        // and correct error code
        verifyException(e, "code 8");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 27 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncInvalidCharsTest method _testUTF8BomFail.

private void _testUTF8BomFail(int offset, int readSize, int okBytes, String verify) throws Exception {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    bytes.write(0xEF);
    if (okBytes > 1) {
        bytes.write(0xBB);
    }
    bytes.write("[ 1 ]".getBytes("UTF-8"));
    byte[] doc = bytes.toByteArray();
    AsyncReaderWrapper p = asyncForBytes(JSON_F, readSize, doc, offset);
    try {
        assertEquals(JsonToken.START_ARRAY, p.nextToken());
        fail("Should not pass");
    } catch (JsonParseException e) {
        verifyException(e, verify);
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 28 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncMissingValuesInObjectTest method testObjectTrailingComma.

@Test
public void testObjectTrailingComma() throws Exception {
    String json = "{\"a\": true, \"b\": false,}";
    AsyncReaderWrapper p = createParser(factory, json);
    assertEquals(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("a", p.currentText());
    assertToken(JsonToken.VALUE_TRUE, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("b", p.currentText());
    assertToken(JsonToken.VALUE_FALSE, p.nextToken());
    if (features.contains(Feature.ALLOW_TRAILING_COMMA)) {
        assertToken(JsonToken.END_OBJECT, p.nextToken());
        assertEnd(p);
    } else {
        assertUnexpected(p, '}');
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) Test(org.junit.Test)

Example 29 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncMissingValuesInObjectTest method testObjectInnerComma.

@Test
public void testObjectInnerComma() throws Exception {
    String json = "{\"a\": true,, \"b\": false}";
    AsyncReaderWrapper p = createParser(factory, json);
    assertEquals(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("a", p.currentText());
    assertToken(JsonToken.VALUE_TRUE, p.nextToken());
    assertUnexpected(p, ',');
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) Test(org.junit.Test)

Example 30 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncMissingValuesInObjectTest method testObjectBasic.

@Test
public void testObjectBasic() throws Exception {
    String json = "{\"a\": true, \"b\": false}";
    AsyncReaderWrapper p = createParser(factory, json);
    assertEquals(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("a", p.currentText());
    assertToken(JsonToken.VALUE_TRUE, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("b", p.currentText());
    assertToken(JsonToken.VALUE_FALSE, p.nextToken());
    assertEquals(JsonToken.END_OBJECT, p.nextToken());
    assertEnd(p);
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) Test(org.junit.Test)

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