feat(#871-strictMode): removed allowSingleQuotes

test(#871-strictMode): adjusted related tests, add more test cases for non-compliant quotes in strict mode
This commit is contained in:
rikkarth
2024-03-30 18:44:51 +00:00
parent c0918c2428
commit 46534b56ad
3 changed files with 18 additions and 37 deletions

View File

@@ -118,24 +118,36 @@ public class JSONParserConfigurationTest {
}
@Test
public void givenUnbalancedQuotes_testStrictModeTrueAndAllowSingleQuotes_shouldThrowJsonExceptionWtihConcreteErrorDescription() {
public void givenNonCompliantQuotes_testStrictModeTrue_shouldThrowJsonExceptionWithConcreteErrorDescription() {
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
.withStrictMode(true).allowSingleQuotes(true);
.withStrictMode(true);
String testCaseOne = "[\"abc', \"test\"]";
String testCaseTwo = "['abc\", \"test\"]";
String testCaseThree = "['abc']";
String testCaseFour = "[{'testField': \"testValue\"}]";
JSONException jeOne = assertThrows(JSONException.class,
() -> new JSONArray(testCaseOne, jsonParserConfiguration));
JSONException jeTwo = assertThrows(JSONException.class,
() -> new JSONArray(testCaseTwo, jsonParserConfiguration));
JSONException jeThree = assertThrows(JSONException.class,
() -> new JSONArray(testCaseThree, jsonParserConfiguration));
JSONException jeFour = assertThrows(JSONException.class,
() -> new JSONArray(testCaseFour, jsonParserConfiguration));
assertEquals(
"Field contains unbalanced quotes. Starts with \" but ends with single quote. at 6 [character 7 line 1]",
jeOne.getMessage());
assertEquals(
"Field contains unbalanced quotes. Starts with ' but ends with double quote. at 6 [character 7 line 1]",
"Single quote wrap not allowed in strict mode at 2 [character 3 line 1]",
jeTwo.getMessage());
assertEquals(
"Single quote wrap not allowed in strict mode at 2 [character 3 line 1]",
jeThree.getMessage());
assertEquals(
"Single quote wrap not allowed in strict mode at 3 [character 4 line 1]",
jeFour.getMessage());
}
@Test