Search in sources :

Example 56 with AsyncReaderWrapper

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

the class AsyncRootValuesTest method _testMixedRootSequence.

private void _testMixedRootSequence(JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    assertNull(r.currentToken());
    // { "a":4 }
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("a", r.currentName());
    assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
    assertEquals(4, r.getIntValue());
    assertToken(JsonToken.END_OBJECT, r.nextToken());
    // [ 12, -987, false]
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
    assertEquals(12, r.getIntValue());
    assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
    assertEquals(-987, r.getIntValue());
    assertToken(JsonToken.VALUE_FALSE, r.nextToken());
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
    assertEquals(12356, r.getIntValue());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 57 with AsyncReaderWrapper

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

the class AsyncScopeMatchingTest method testMismatchArrayToObject.

public void testMismatchArrayToObject() throws Exception {
    final String JSON = "[ 1, 2 }";
    AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc(JSON), 0);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    try {
        p.nextToken();
        fail("Expected an exception for incorrectly closed ARRAY");
    } catch (JsonParseException pe) {
        verifyException(pe, "Unexpected close marker '}': expected ']'");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 58 with AsyncReaderWrapper

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

the class AsyncScopeMatchingTest method testUnclosedArray.

public void testUnclosedArray(int mode) throws Exception {
    AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc("[ 1, 2 "), 0);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(2, p.getIntValue());
    try {
        p.nextToken();
        fail("Expected an exception for unclosed ARRAY (mode: " + mode + ")");
    } catch (JsonParseException pe) {
        verifyException(pe, "expected close marker for ARRAY");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 59 with AsyncReaderWrapper

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

the class AsyncScopeMatchingTest method testEOFInName.

public void testEOFInName(int mode) throws Exception {
    final String JSON = "{ \"abcd";
    AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc(JSON), 0);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        p.nextToken();
        fail("Expected an exception for EOF");
    } catch (JsonParseException pe) {
        verifyException(pe, "Unexpected end-of-input");
    } catch (IOException ie) {
        // DataInput behaves bit differently
        if (mode == MODE_DATA_INPUT) {
            verifyException(ie, "end-of-input");
            return;
        }
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) IOException(java.io.IOException)

Example 60 with AsyncReaderWrapper

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

the class AsyncMissingValuesInObjectTest method testObjectTrailingCommas.

@Test
public void testObjectTrailingCommas() 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());
    assertUnexpected(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