Search in sources :

Example 81 with AsyncReaderWrapper

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

the class AsyncScalarArrayTest method _testFloats.

private void _testFloats(JsonFactory f, float[] 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_FLOAT, r.nextToken());
        assertEquals(values[i], r.getFloatValue());
        // json can't distinguish floats from doubles so
        assertEquals(NumberType.DOUBLE, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 82 with AsyncReaderWrapper

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

the class AsyncScalarArrayTest method _testBigDecimals.

private void _testBigDecimals(JsonFactory f, BigDecimal[] values, byte[] doc, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, doc, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    for (int i = 0; i < values.length; ++i) {
        BigDecimal expValue = values[i];
        assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
        assertEquals(expValue, r.getDecimalValue());
        assertEquals(NumberType.BIG_DECIMAL, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) BigDecimal(java.math.BigDecimal)

Example 83 with AsyncReaderWrapper

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

the class AsyncScalarArrayTest method _testDoubles.

private void _testDoubles(JsonFactory f, double[] 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_FLOAT, r.nextToken());
        assertEquals(String.format("Entry #%d: %s (textual '%s')", i, values[i], r.currentText()), values[i], r.getDoubleValue());
        assertEquals(NumberType.DOUBLE, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 84 with AsyncReaderWrapper

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

the class AsyncScalarArrayTest method _testBigIntegers.

private void _testBigIntegers(JsonFactory f, BigInteger[] 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) {
        BigInteger expValue = values[i];
        assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
        assertEquals(expValue, r.getBigIntegerValue());
        assertEquals(NumberType.BIG_INTEGER, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) BigInteger(java.math.BigInteger)

Example 85 with AsyncReaderWrapper

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

the class AsyncScalarArrayTest method _testLong.

private void _testLong(JsonFactory f, long[] 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.getLongValue());
        assertEquals(NumberType.LONG, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
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