Search in sources :

Example 16 with AsyncReaderWrapper

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

the class AsyncSimpleObjectTest method _testNumbers.

private void _testNumbers(JsonFactory f, 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_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("i1", r.currentText());
    assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
    assertEquals(NumberType.INT, r.getNumberType());
    assertEquals(NUMBER_EXP_I, r.getIntValue());
    assertEquals((double) NUMBER_EXP_I, r.getDoubleValue());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("doubley", r.currentText());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
    assertEquals(NumberType.DOUBLE, r.getNumberType());
    assertEquals(NUMBER_EXP_D, r.getDoubleValue());
    assertEquals((long) NUMBER_EXP_D, r.getLongValue());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("biggieDecimal", r.currentText());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
    // can't really tell double/BigDecimal apart in plain json
    assertEquals(NumberType.DOUBLE, r.getNumberType());
    assertEquals(NUMBER_EXP_BD, r.getDecimalValue());
    assertEquals("" + NUMBER_EXP_BD, r.currentText());
    assertToken(JsonToken.END_OBJECT, 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 17 with AsyncReaderWrapper

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

the class AsyncTokenErrorTest method testMangledNonRootInts.

public void testMangledNonRootInts() throws Exception {
    AsyncReaderWrapper p = _createParser("[ 123true ]");
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t);
    } catch (JsonParseException e) {
        verifyException(e, "expected space");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 18 with AsyncReaderWrapper

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

the class AsyncNumberLeadingZeroesTest method _testLeadingZeroesFloat.

public void _testLeadingZeroesFloat(String valueStr, double value) throws Exception {
    // first: verify that we get an exception
    JsonFactory f = new JsonFactory();
    assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS));
    String JSON = valueStr;
    AsyncReaderWrapper p = createParser(f, JSON);
    try {
        p.nextToken();
        p.currentText();
        fail("Should have thrown an exception for doc <" + JSON + ">");
    } catch (JsonParseException e) {
        verifyException(e, "invalid numeric value");
    } finally {
        p.close();
    }
    // and then verify it's ok when enabled
    f = f.rebuild().enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS).build();
    assertTrue(f.isEnabled(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS));
    p = createParser(f, JSON);
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(String.valueOf(value), p.currentText());
    assertEquals(value, p.getDoubleValue());
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 19 with AsyncReaderWrapper

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

the class AsyncRootNumbersTest method _testRootDoubles.

private void _testRootDoubles(double value, JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    assertNull(r.currentToken());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
    assertEquals(value, r.getDoubleValue());
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 20 with AsyncReaderWrapper

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

the class AsyncScalarArrayTest method _testTokens.

private void _testTokens(JsonFactory f, 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());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.VALUE_FALSE, r.nextToken());
    assertEquals("false", r.currentText());
    assertEquals("false", r.currentTextViaCharacters());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.VALUE_NULL, r.nextToken());
    assertEquals("null", r.currentText());
    assertEquals("null", r.currentTextViaCharacters());
    assertToken(JsonToken.VALUE_FALSE, r.nextToken());
    assertToken(JsonToken.VALUE_NULL, r.nextToken());
    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