Skip to content

Commit d5ab0aa

Browse files
committed
Added test case for converting String to numerals
1 parent f1b0210 commit d5ab0aa

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎src/test/java/org/json/junit/JSONStringTest.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,22 @@ public void testNullStringValue() throws Exception {
339339
}
340340
}
341341

342+
/**
343+
* Test for parsing long numerals from String format
344+
*
345+
*/
346+
347+
@Test
348+
public void testStringLongValue() throws Exception {
349+
JSONObject json = new JSONObject("{\"number_1\":\"01234\", \"number_2\": \"332211\"}");
350+
351+
assertEquals(1234L, json.getLong("number_1"));
352+
assertEquals(1234L, json.optLong("number_1"));
353+
assertEquals(332211L, json.getLong("number_2"));
354+
assertEquals(332211L, json.optLong("number_2"));
355+
}
356+
357+
342358
/**
343359
* A JSONString that returns a valid JSON string value.
344360
*/

0 commit comments

Comments
 (0)