mirror of
https://github.com/stleary/JSON-java.git
synced 2026-01-25 00:00:38 -05:00
Revert "Merge pull request #888 from rikkarth/fix/887"
This reverts commit14f71274f7, reversing changes made to054786e300.
This commit is contained in:
@@ -46,85 +46,6 @@ public class JSONParserConfigurationTest {
|
||||
() -> new JSONArray(testCase, jsonParserConfiguration)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyArray_testStrictModeTrue_shouldNotThrowJsonException() {
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||
.withStrictMode(true);
|
||||
|
||||
String testCase = "[]";
|
||||
|
||||
JSONArray jsonArray = new JSONArray(testCase, jsonParserConfiguration);
|
||||
|
||||
assertEquals(testCase, jsonArray.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenValidDoubleArray_testStrictModeTrue_shouldNotThrowJsonException() {
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||
.withStrictMode(true);
|
||||
|
||||
String testCase = "[[\"c\"], [10.2], [true, false, true]]";
|
||||
|
||||
JSONArray jsonArray = new JSONArray(testCase, jsonParserConfiguration);
|
||||
JSONArray arrayShouldContainStringAt0 = jsonArray.getJSONArray(0);
|
||||
JSONArray arrayShouldContainNumberAt0 = jsonArray.getJSONArray(1);
|
||||
JSONArray arrayShouldContainBooleanAt0 = jsonArray.getJSONArray(2);
|
||||
|
||||
assertTrue(arrayShouldContainStringAt0.get(0) instanceof String);
|
||||
assertTrue(arrayShouldContainNumberAt0.get(0) instanceof Number);
|
||||
assertTrue(arrayShouldContainBooleanAt0.get(0) instanceof Boolean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenValidEmptyArrayInsideArray_testStrictModeTrue_shouldNotThrowJsonException(){
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||
.withStrictMode(true);
|
||||
|
||||
String testCase = "[[]]";
|
||||
|
||||
JSONArray jsonArray = new JSONArray(testCase, jsonParserConfiguration);
|
||||
|
||||
assertEquals(testCase, jsonArray.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenValidEmptyArrayInsideArray_testStrictModeFalse_shouldNotThrowJsonException(){
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||
.withStrictMode(false);
|
||||
|
||||
String testCase = "[[]]";
|
||||
|
||||
JSONArray jsonArray = new JSONArray(testCase, jsonParserConfiguration);
|
||||
|
||||
assertEquals(testCase, jsonArray.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenInvalidString_testStrictModeTrue_shouldThrowJsonException() {
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||
.withStrictMode(true);
|
||||
|
||||
String testCase = "[badString]";
|
||||
|
||||
JSONException je = assertThrows(JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||
|
||||
assertEquals("Value 'badString' is not surrounded by quotes at 10 [character 11 line 1]", je.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowNullInStrictMode() {
|
||||
String expected = "[null]";
|
||||
JSONArray jsonArray = new JSONArray(expected, new JSONParserConfiguration().withStrictMode(true));
|
||||
assertEquals(expected, jsonArray.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNumericArray() {
|
||||
String expected = "[10]";
|
||||
JSONArray jsonArray = new JSONArray(expected, new JSONParserConfiguration().withStrictMode(true));
|
||||
assertEquals(expected, jsonArray.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCompliantJSONArrayFile_testStrictModeTrue_shouldNotThrowAnyException() throws IOException {
|
||||
try (Stream<String> lines = Files.lines(Paths.get("src/test/resources/compliantJsonArray.json"))) {
|
||||
@@ -157,7 +78,7 @@ public class JSONParserConfigurationTest {
|
||||
JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase,
|
||||
JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||
|
||||
assertEquals("invalid character ';' found after end of array at 6 [character 7 line 1]", je.getMessage());
|
||||
assertEquals("invalid character found after end of array: ; at 6 [character 7 line 1]", je.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,7 +91,7 @@ public class JSONParserConfigurationTest {
|
||||
JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase,
|
||||
JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||
|
||||
assertEquals("invalid character ';' found after end of array at 10 [character 11 line 1]", je.getMessage());
|
||||
assertEquals("invalid character found after end of array: ; at 10 [character 11 line 1]", je.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,7 +104,7 @@ public class JSONParserConfigurationTest {
|
||||
JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase,
|
||||
JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||
|
||||
assertEquals("Value 'implied' is not surrounded by quotes at 17 [character 18 line 1]", je.getMessage());
|
||||
assertEquals("Value is not surrounded by quotes: implied", je.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -216,7 +137,7 @@ public class JSONParserConfigurationTest {
|
||||
() -> new JSONArray(testCaseFour, jsonParserConfiguration));
|
||||
|
||||
assertEquals(
|
||||
"Value 'test' is not surrounded by quotes at 13 [character 14 line 1]",
|
||||
"Field contains unbalanced quotes. Starts with \" but ends with single quote. at 6 [character 7 line 1]",
|
||||
jeOne.getMessage());
|
||||
assertEquals(
|
||||
"Single quote wrap not allowed in strict mode at 2 [character 3 line 1]",
|
||||
@@ -242,7 +163,7 @@ public class JSONParserConfigurationTest {
|
||||
JSONException jeTwo = assertThrows(JSONException.class,
|
||||
() -> new JSONArray(testCaseTwo, jsonParserConfiguration));
|
||||
|
||||
assertEquals("Unterminated string. Character with int code 0 is not allowed within a quoted string. at 15 [character 16 line 1]", jeOne.getMessage());
|
||||
assertEquals("Expected a ',' or ']' at 10 [character 11 line 1]", jeOne.getMessage());
|
||||
assertEquals("Unterminated string. Character with int code 0 is not allowed within a quoted string. at 15 [character 16 line 1]", jeTwo.getMessage());
|
||||
}
|
||||
|
||||
@@ -256,7 +177,7 @@ public class JSONParserConfigurationTest {
|
||||
JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase,
|
||||
JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||
|
||||
assertEquals("Value 'test' is not surrounded by quotes at 6 [character 7 line 1]", je.getMessage());
|
||||
assertEquals(String.format("Value is not surrounded by quotes: %s", "test"), je.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -287,20 +208,6 @@ public class JSONParserConfigurationTest {
|
||||
*/
|
||||
private List<String> getNonCompliantJSONList() {
|
||||
return Arrays.asList(
|
||||
"[1],",
|
||||
"[1,]",
|
||||
"[[1]\"sa\",[2]]a",
|
||||
"[1],\"dsa\": \"test\"",
|
||||
"[[a]]",
|
||||
"[]asdf",
|
||||
"[]]",
|
||||
"[]}",
|
||||
"[][",
|
||||
"[]{",
|
||||
"[],",
|
||||
"[]:",
|
||||
"[],[",
|
||||
"[],{",
|
||||
"[1,2];[3,4]",
|
||||
"[test]",
|
||||
"[{'testSingleQuote': 'testSingleQuote'}]",
|
||||
|
||||
Reference in New Issue
Block a user