Search in sources :

Example 31 with AsyncReaderWrapper

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

the class AsyncNonStdParsingTest method _testSimpleUnquoted.

private void _testSimpleUnquoted(JsonFactory f, int offset, int readSize) throws Exception {
    String doc = "{ a : 1, _foo:true, $:\"money!\", \" \":null }";
    AsyncReaderWrapper p = createParser(f, doc, offset, readSize);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("a", p.currentName());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("_foo", p.currentName());
    assertToken(JsonToken.VALUE_TRUE, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("$", p.currentName());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("money!", p.currentText());
    // and then regular quoted one should still work too:
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals(" ", p.currentName());
    assertToken(JsonToken.VALUE_NULL, p.nextToken());
    assertToken(JsonToken.END_OBJECT, p.nextToken());
    p.close();
    // Another thing, as per [jackson-cre#102]: numbers
    p = createParser(f, "{ 123:true,4:false }", offset, readSize);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("123", p.currentName());
    assertToken(JsonToken.VALUE_TRUE, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("4", p.currentName());
    assertToken(JsonToken.VALUE_FALSE, p.nextToken());
    assertToken(JsonToken.END_OBJECT, p.nextToken());
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 32 with AsyncReaderWrapper

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

the class AsyncNonStdParsingTest method _testAposQuotingEnabled.

private void _testAposQuotingEnabled(JsonFactory f, int offset, int readSize) throws Exception {
    String UNINAME = String.format("Uni%c-key-%c", UNICODE_2BYTES, UNICODE_3BYTES);
    String UNIVALUE = String.format("Uni%c-value-%c", UNICODE_3BYTES, UNICODE_2BYTES);
    String JSON = String.format("{ 'a' : 1, \"foobar\": 'b', '_abcde1234':'d', '\"' : '\"\"', '':'', '%s':'%s'}", UNINAME, UNIVALUE);
    AsyncReaderWrapper p = createParser(f, JSON, offset, readSize);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("a", p.currentText());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals("1", p.currentText());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("foobar", p.currentText());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("b", p.currentText());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("_abcde1234", p.currentText());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("d", p.currentText());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("\"", p.currentText());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("\"\"", p.currentText());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("", p.currentText());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("", p.currentText());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals(UNINAME, p.currentText());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals(UNIVALUE, p.currentText());
    assertToken(JsonToken.END_OBJECT, p.nextToken());
    p.close();
    JSON = "{'b':1,'array':[{'b':3}],'ob':{'b':4,'x':0,'y':'" + UNICODE_SEGMENT + "','a':false }}";
    p = createParser(f, JSON, offset, readSize);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("b", p.currentName());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("b", p.currentName());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(3, p.getIntValue());
    assertToken(JsonToken.END_OBJECT, p.nextToken());
    assertToken(JsonToken.END_ARRAY, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("b", p.currentName());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(4, p.getIntValue());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("x", p.currentName());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(0, p.getIntValue());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("y", p.currentName());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals(UNICODE_SEGMENT, p.currentText());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("a", p.currentName());
    assertToken(JsonToken.VALUE_FALSE, p.nextToken());
    assertToken(JsonToken.END_OBJECT, p.nextToken());
    assertToken(JsonToken.END_OBJECT, p.nextToken());
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 33 with AsyncReaderWrapper

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

the class AsyncNonStdParsingTest method _testNonStandarBackslashQuoting.

private void _testNonStandarBackslashQuoting(int offset, int readSize) throws Exception {
    // first: verify that we get an exception
    JsonFactory f = new JsonFactory();
    assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
    final String JSON = quote("\\'");
    AsyncReaderWrapper p = createParser(f, JSON, offset, readSize);
    try {
        p.nextToken();
        p.currentText();
        fail("Should have thrown an exception for doc <" + JSON + ">");
    } catch (JsonParseException e) {
        verifyException(e, "unrecognized character escape");
    } finally {
        p.close();
    }
    // and then verify it's ok...
    f = f.rebuild().enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER).build();
    assertTrue(f.isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
    p = createParser(f, JSON, offset, readSize);
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("'", p.currentText());
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 34 with AsyncReaderWrapper

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

the class AsyncNonStdParsingTest method _testSingleQuotesDefault.

private void _testSingleQuotesDefault(JsonFactory f, int offset, int readSize) throws Exception {
    // First, let's see that by default they are not allowed
    String JSON = "[ 'text' ]";
    AsyncReaderWrapper p = createParser(f, JSON, offset, readSize);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    try {
        p.nextToken();
        fail("Expected exception");
    } catch (JsonParseException e) {
        verifyException(e, "Unexpected character ('''");
    } finally {
        p.close();
    }
    JSON = "{ 'a':1 }";
    p = createParser(f, JSON, offset, readSize);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        p.nextToken();
        fail("Expected exception");
    } catch (JsonParseException e) {
        verifyException(e, "Unexpected character ('''");
    } finally {
        p.close();
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 35 with AsyncReaderWrapper

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

the class AsyncCommentParsingTest method _testYAMLComments.

private void _testYAMLComments(JsonFactory f, int bytesPerRead) throws Exception {
    final String DOC = "# foo\n" + " {\"a\" # xyz\n" + " : # foo\n" + " 1, # more\n" + "\"b\": [ \n" + " #all!\n" + " 3 #yay!\n" + "] # foobar\n" + "} # x";
    AsyncReaderWrapper p = _createParser(f, DOC, bytesPerRead);
    assertEquals(JsonToken.START_OBJECT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("a", p.currentName());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(1, p.getIntValue());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("b", p.currentName());
    assertEquals(JsonToken.START_ARRAY, p.nextToken());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(3, p.getIntValue());
    assertEquals(JsonToken.END_ARRAY, p.nextToken());
    assertEquals(JsonToken.END_OBJECT, p.nextToken());
    assertNull(p.nextToken());
    p.close();
}
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