Add more test cases for unquoted text in objects and arrays.

This commit is contained in:
Éamonn McManus
2023-09-28 11:05:50 -07:00
parent 16967f322e
commit dbb113176b
2 changed files with 38 additions and 2 deletions

View File

@@ -118,7 +118,7 @@ public class JSONArrayTest {
* Expects a JSONException.
*/
@Test
public void emptStr() {
public void emptyStr() {
String str = "";
try {
assertNull("Should throw an exception", new JSONArray(str));
@@ -460,6 +460,20 @@ public class JSONArrayTest {
Util.checkJSONArrayMaps(jsonArray);
}
/**
* The JSON parser is permissive of unambiguous unquoted keys and values.
* Such JSON text should be allowed, even if it does not strictly conform
* to the spec. However, after being parsed, toString() should emit strictly
* conforming JSON text.
*/
@Test
public void unquotedText() {
String str = "[value1, something!, (parens), foo@bar.com, 23, 23+45]";
JSONArray jsonArray = new JSONArray(str);
List<Object> expected = Arrays.asList("value1", "something!", "(parens)", "foo@bar.com", 23, "23+45");
assertEquals(expected, jsonArray.toList());
}
/**
* Exercise JSONArray.join() by converting a JSONArray into a
* comma-separated string. Since this is very nearly a JSON document,