mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Added unit tests for escaped quotes.
This commit is contained in:
parent
8f16e065c5
commit
e00191798e
1 changed files with 56 additions and 1 deletions
|
@ -105,6 +105,61 @@ public class CDLTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to create a JSONArray with unbalanced quotes and a properly escaped doubled quote.
|
||||
* Expects a JSONException.
|
||||
*/
|
||||
@Test
|
||||
public void unbalancedEscapedQuote(){
|
||||
String badLine = "Col1, Col2\n\"Val1, \"\"Val2\"\"";
|
||||
try {
|
||||
CDL.toJSONArray(badLine);
|
||||
assertTrue("Expecting an exception", false);
|
||||
} catch (JSONException e) {
|
||||
assertTrue("Expecting an exception message",
|
||||
"Missing close quote '\"'. at 27 [character 16 line 3]".
|
||||
equals(e.getMessage()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that there is no error for a single escaped quote within a properly embedded quote.
|
||||
*/
|
||||
@Test
|
||||
public void singleEscapedQuote(){
|
||||
String singleEscape = "Col1, Col2\nVal1, \"\"\"Val2\"";
|
||||
JSONArray jsonArray = CDL.toJSONArray(singleEscape);
|
||||
|
||||
String cdlStr = CDL.toString(jsonArray);
|
||||
assertTrue(cdlStr.contains("Col1"));
|
||||
assertTrue(cdlStr.contains("Col2"));
|
||||
assertTrue(cdlStr.contains("Val1"));
|
||||
assertTrue(cdlStr.contains("\"Val2"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to create a JSONArray with an escape quote and no enclosing quotes.
|
||||
* Expects a JSONException.
|
||||
*/
|
||||
@Test
|
||||
public void badEscapedQuote(){
|
||||
String badLine = "Col1, Col2\nVal1, \"\"Val2";
|
||||
|
||||
try {
|
||||
CDL.toJSONArray(badLine);
|
||||
assertTrue("Expecting an exception", false);
|
||||
} catch (JSONException e) {
|
||||
System.out.println("Message" + e.getMessage());
|
||||
assertTrue("Expecting an exception message",
|
||||
"Bad character 'V' (86). at 20 [character 9 line 3]".
|
||||
equals(e.getMessage()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* call toString with a null array
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue