Search in sources :

Example 1 with AsyncReaderWrapper

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

the class AsyncCharEscapingTest method _testSimpleEscaping.

private void _testSimpleEscaping(int offset, int readSize) throws Exception {
    byte[] doc = _jsonDoc(aposToQuotes("['LF=\\n']"));
    AsyncReaderWrapper r = asyncForBytes(JSON_F, readSize, doc, offset);
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    assertToken(JsonToken.VALUE_STRING, r.nextToken());
    assertEquals("LF=\n", r.currentText());
    r.close();
    // Note: must split Strings, so that javac won't try to handle
    // escape and inline null char
    doc = _jsonDoc(aposToQuotes("['NULL:\\u0000!']"));
    r = asyncForBytes(JSON_F, readSize, doc, offset);
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    assertToken(JsonToken.VALUE_STRING, r.nextToken());
    assertEquals("NULL:\0!", r.currentText());
    r.close();
    // Then just a single char escaping
    doc = _jsonDoc(aposToQuotes("['\\u0123']"));
    r = asyncForBytes(JSON_F, readSize, doc, offset);
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    assertToken(JsonToken.VALUE_STRING, r.nextToken());
    assertEquals("\u0123", r.currentText());
    r.close();
    // And then double sequence
    doc = _jsonDoc(aposToQuotes("['\\u0041\\u0043']"));
    r = asyncForBytes(JSON_F, readSize, doc, offset);
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    assertToken(JsonToken.VALUE_STRING, r.nextToken());
    assertEquals("AC", r.currentText());
    r.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 2 with AsyncReaderWrapper

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

the class AsyncCharEscapingTest method _testMissingLinefeedEscaping.

private void _testMissingLinefeedEscaping(byte[] doc, int offset, int readSize) throws Exception {
    AsyncReaderWrapper r = asyncForBytes(JSON_F, readSize, doc, offset);
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    try {
        // This may or may not trigger exception
        JsonToken t = r.nextToken();
        assertToken(JsonToken.VALUE_STRING, t);
        fail("Expected an exception for un-escaped linefeed in string value");
    } catch (JsonParseException jex) {
        verifyException(jex, "has to be escaped");
    }
    r.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 3 with AsyncReaderWrapper

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

the class AsyncFieldNamesTest method _testEscapedFieldNames.

private void _testEscapedFieldNames(byte[] doc, String expName, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(JSON_F, readSize, doc, offset);
    assertNull(r.currentToken());
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals(expName, r.currentName());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    r.close();
    assertNull(r.nextToken());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 4 with AsyncReaderWrapper

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

the class AsyncFieldNamesTest method _testEscapedAposFieldNames.

private void _testEscapedAposFieldNames(byte[] doc, String expName, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(JSON_APOS_F, readSize, doc, offset);
    assertNull(r.currentToken());
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals(expName, r.currentName());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    r.close();
    assertNull(r.nextToken());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 5 with AsyncReaderWrapper

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

the class AsyncMissingValuesInArrayTest method testArrayInnerComma.

// Could test, but this case is covered by other tests anyway
/*
    @Test
    public void testArrayBasic() throws Exception {
        String json = "[\"a\", \"b\"]";

        AsyncReaderWrapper p = createParser(factory, json);

    assertEquals(JsonToken.START_ARRAY, p.nextToken());

    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("a", p.currentText());

    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("b", p.currentText());

    assertEquals(JsonToken.END_ARRAY, p.nextToken());
    assertEnd(p);
  }
  */
@Test
public void testArrayInnerComma() throws Exception {
    String json = "[\"a\",, \"b\"]";
    AsyncReaderWrapper p = createParser(factory, json);
    assertEquals(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("a", p.currentText());
    if (!features.contains(Feature.ALLOW_MISSING_VALUES)) {
        assertUnexpected(p, ',');
        return;
    }
    assertToken(JsonToken.VALUE_NULL, p.nextToken());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("b", p.currentText());
    assertEquals(JsonToken.END_ARRAY, p.nextToken());
    assertEnd(p);
}
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