Search in sources :

Example 76 with AsyncReaderWrapper

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

the class AsyncTokenErrorTest method testMangledRootFloats.

public void testMangledRootFloats() throws Exception {
    // Also test with floats
    AsyncReaderWrapper p = _createParser("1.5false");
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t + "; number: " + p.getNumberValue());
    } catch (JsonParseException e) {
        verifyException(e, "expected space");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 77 with AsyncReaderWrapper

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

the class AsyncTokenErrorTest method _doTestInvalidKeyword.

private void _doTestInvalidKeyword(String value) throws IOException {
    String doc = "{ \"key1\" : " + value + " }";
    AsyncReaderWrapper p = _createParser(doc);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    // get the exception early or late...
    try {
        assertToken(JsonToken.FIELD_NAME, p.nextToken());
        p.nextToken();
        fail("Expected an exception for malformed value keyword");
    } catch (JsonParseException jex) {
        verifyException(jex, "Unrecognized token");
        verifyException(jex, value);
    } finally {
        p.close();
    }
    // Try as root-level value as well:
    // may need space after for DataInput
    doc = value + " ";
    p = _createParser(doc);
    try {
        p.nextToken();
        fail("Expected an exception for malformed value keyword");
    } catch (JsonParseException jex) {
        verifyException(jex, "Unrecognized token");
        verifyException(jex, value);
    } finally {
        p.close();
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 78 with AsyncReaderWrapper

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

the class AsyncNumberLeadingZeroesTest method _testLeadingZeroesInt.

public void _testLeadingZeroesInt(String valueStr, int 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_INT, p.nextToken());
    assertEquals(value, p.getIntValue());
    assertEquals(String.valueOf(value), p.currentText());
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 79 with AsyncReaderWrapper

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

the class AsyncRootNumbersTest method _testRootInts.

private void _testRootInts(int 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_INT, r.nextToken());
    assertEquals(value, r.getIntValue());
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 80 with AsyncReaderWrapper

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

the class AsyncScalarArrayTest method _testInts.

private void _testInts(JsonFactory f, int[] 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.getIntValue());
        assertEquals(NumberType.INT, r.getNumberType());
        // and then couple of special modes, just to get better test coverage
        String asStr = String.valueOf(values[i]);
        assertEquals(asStr, r.currentText());
        StringWriter sw = new StringWriter();
        assertEquals(asStr.length(), r.parser().getText(sw));
        assertEquals(asStr, sw.toString());
    }
    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