Skip to content

Commit fa93b47

Browse files
authored
Create AsyncNonStandardNumberParsingTest.java (#787)
1 parent 6d9f5b8 commit fa93b47

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.fasterxml.jackson.core.json.async;
2+
3+
import com.fasterxml.jackson.core.JsonFactory;
4+
import com.fasterxml.jackson.core.JsonToken;
5+
import com.fasterxml.jackson.core.async.AsyncTestBase;
6+
import com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper;
7+
8+
import java.io.IOException;
9+
10+
public class AsyncNonStandardNumberParsingTest extends AsyncTestBase
11+
{
12+
private final JsonFactory DEFAULT_F = new JsonFactory();
13+
14+
public void testHexadecimal() throws Exception
15+
{
16+
final String JSON = "[ 0xc0ffee ]";
17+
18+
// without enabling, should get an exception
19+
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
20+
assertToken(JsonToken.START_ARRAY, p.nextToken());
21+
try {
22+
p.nextToken();
23+
fail("Expected exception");
24+
} catch (Exception e) {
25+
verifyException(e, "Unexpected character ('x'");
26+
} finally {
27+
p.close();
28+
}
29+
}
30+
31+
public void testHexadecimalBigX() throws Exception
32+
{
33+
final String JSON = "[ 0XC0FFEE ]";
34+
35+
// without enabling, should get an exception
36+
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
37+
assertToken(JsonToken.START_ARRAY, p.nextToken());
38+
try {
39+
p.nextToken();
40+
fail("Expected exception");
41+
} catch (Exception e) {
42+
verifyException(e, "Unexpected character ('X'");
43+
} finally {
44+
p.close();
45+
}
46+
}
47+
48+
public void testNegativeHexadecimal() throws Exception
49+
{
50+
final String JSON = "[ -0xc0ffee ]";
51+
52+
// without enabling, should get an exception
53+
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
54+
assertToken(JsonToken.START_ARRAY, p.nextToken());
55+
try {
56+
p.nextToken();
57+
fail("Expected exception");
58+
} catch (Exception e) {
59+
verifyException(e, "Unexpected character ('x'");
60+
} finally {
61+
p.close();
62+
}
63+
}
64+
65+
//next 2 tests do not work as expected
66+
/*
67+
public void testFloatMarker() throws Exception
68+
{
69+
final String JSON = "[ -0.123f ]";
70+
71+
// without enabling, should get an exception
72+
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
73+
assertToken(JsonToken.START_ARRAY, p.nextToken());
74+
try {
75+
p.nextToken();
76+
fail("Expected exception");
77+
} catch (Exception e) {
78+
verifyException(e, "Unexpected character ('f'");
79+
} finally {
80+
p.close();
81+
}
82+
}
83+
84+
public void testDoubleMarker() throws Exception
85+
{
86+
final String JSON = "[ -0.123d ]";
87+
88+
// without enabling, should get an exception
89+
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
90+
assertToken(JsonToken.START_ARRAY, p.nextToken());
91+
try {
92+
p.nextToken();
93+
fail("Expected exception");
94+
} catch (Exception e) {
95+
verifyException(e, "Unexpected character ('d'");
96+
} finally {
97+
p.close();
98+
}
99+
}
100+
*/
101+
102+
private AsyncReaderWrapper createParser(JsonFactory f, String doc, int readBytes) throws IOException
103+
{
104+
return asyncForBytes(f, readBytes, _jsonDoc(doc), 1);
105+
}
106+
}

0 commit comments

Comments
 (0)