mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-07 11:10:08 +08:00
test(#871-strictMode): add two more test which validate error correctness
This commit is contained in:
@@ -48,6 +48,42 @@ public class JSONParserConfigurationTest {
|
|||||||
strictModeInputTestCases.forEach(testCase -> new JSONArray(testCase, jsonParserConfiguration));
|
strictModeInputTestCases.forEach(testCase -> new JSONArray(testCase, jsonParserConfiguration));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInvalidInputArray_testStrictModeTrue_shouldThrowInvalidCharacterErrorMessage() {
|
||||||
|
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||||
|
.withStrictMode(true);
|
||||||
|
|
||||||
|
String testCase = "[1,2];[3,4]";
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInvalidInputArray_testStrictModeTrue_shouldThrowValueNotSurroundedByQuotesErrorMessage() {
|
||||||
|
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||||
|
.withStrictMode(true);
|
||||||
|
|
||||||
|
String testCase = "[{\"test\": implied}]";
|
||||||
|
JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase,
|
||||||
|
JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||||
|
|
||||||
|
assertEquals("Value is not surrounded by quotes: implied", je.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInvalidInputArray_testStrictModeTrue_shouldThrowKeyNotSurroundedByQuotesErrorMessage() {
|
||||||
|
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||||
|
.withStrictMode(true);
|
||||||
|
|
||||||
|
String testCase = "[{test: implied}]";
|
||||||
|
JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase,
|
||||||
|
JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||||
|
|
||||||
|
assertEquals("Key is not surrounded by quotes: test", je.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void verifyDuplicateKeyThenMaxDepth() {
|
public void verifyDuplicateKeyThenMaxDepth() {
|
||||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||||
|
Reference in New Issue
Block a user