Skip to content

Commit e647706

Browse files
committed
1 parent 3a659da commit e647706

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/parse/BasicParserTest.java

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,22 @@ public void testEmptyStrings() throws IOException
151151
assertNull(p.nextToken());
152152
p.close();
153153
}
154-
154+
155155
// Test for ASCII String values longer than 64 bytes; separate
156156
// since handling differs
157157
public void testLongAsciiString() throws IOException
158158
{
159-
final String DIGITS = "1234567890";
160-
String LONG = DIGITS + DIGITS + DIGITS + DIGITS;
161-
LONG = LONG + LONG + LONG + LONG;
162-
byte[] data = _smileDoc(quote(LONG));
159+
final String DIGITS = "1234567890";
160+
String LONG = DIGITS + DIGITS + DIGITS + DIGITS;
161+
LONG = LONG + LONG + LONG + LONG;
162+
byte[] data = _smileDoc(quote(LONG));
163163

164-
SmileParser p = _smileParser(data);
165-
assertNull(p.getCurrentToken());
166-
assertToken(JsonToken.VALUE_STRING, p.nextToken());
167-
assertEquals(LONG, p.getText());
168-
assertNull(p.nextToken());
169-
p.close();
164+
SmileParser p = _smileParser(data);
165+
assertNull(p.getCurrentToken());
166+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
167+
assertEquals(LONG, p.getText());
168+
assertNull(p.nextToken());
169+
p.close();
170170
}
171171

172172
//Test for non-ASCII String values longer than 64 bytes; separate
@@ -192,22 +192,37 @@ public void testLongUnicodeString() throws IOException
192192
p.close();
193193
}
194194

195+
// Simple test for encoding where "Unicode" string value is
196+
// actually ascii (which is fine, encoders need not ensure it is not,
197+
// it's just not guaranteeing content IS ascii)
198+
public void testShortAsciiAsUnicodeString() throws IOException
199+
{
200+
byte[] data = new byte[] {
201+
(byte) 0x82, 0x64, 0x61, 0x74, 0x61
202+
};
203+
try (SmileParser p = _smileParser(data)) {
204+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
205+
assertEquals("data", p.getText());
206+
assertNull(p.nextToken());
207+
}
208+
}
209+
195210
public void testTrivialObject() throws IOException
196211
{
197-
byte[] data = _smileDoc("{\"abc\":13}");
198-
SmileParser p = _smileParser(data);
199-
assertNull(p.getCurrentToken());
212+
byte[] data = _smileDoc("{\"abc\":13}");
213+
SmileParser p = _smileParser(data);
214+
assertNull(p.getCurrentToken());
200215

201-
assertToken(JsonToken.START_OBJECT, p.nextToken());
202-
assertToken(JsonToken.FIELD_NAME, p.nextToken());
203-
assertEquals("abc", p.getCurrentName());
204-
assertEquals("abc", p.getText());
205-
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
206-
assertEquals(13, p.getIntValue());
207-
assertToken(JsonToken.END_OBJECT, p.nextToken());
208-
p.close();
216+
assertToken(JsonToken.START_OBJECT, p.nextToken());
217+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
218+
assertEquals("abc", p.getCurrentName());
219+
assertEquals("abc", p.getText());
220+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
221+
assertEquals(13, p.getIntValue());
222+
assertToken(JsonToken.END_OBJECT, p.nextToken());
223+
p.close();
209224
}
210-
225+
211226
public void testSimpleObject() throws IOException
212227
{
213228
byte[] data = _smileDoc("{\"a\":8, \"b\" : [ true ], \"c\" : { }, \"d\":{\"e\":null}}");

0 commit comments

Comments
 (0)