Test cases for the scenarios described in SANDBOX-161:
* Double quotes (") should be escaped using two double quotes (""), rather than a backslash (\"). * Embedded line breaks are allowed and don't need to be escaped... just enclose the field in double quotes. * Because backslashes are not used to escape double quotes or line breaks, the backslashes themselves do not need to be escaped. git-svn-id: https://svn.apache.org/repos/asf/commons/sandbox/csv/trunk@1065519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6b422c82bd
commit
822e653a0e
|
@ -57,6 +57,38 @@ public class CSVPrinterTest extends TestCase {
|
|||
assertEquals("\"a, b\",\"b \"" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
public void testPrinter4() throws IOException {
|
||||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.DEFAULT_STRATEGY);
|
||||
String[] line1 = {"a", "b\"c"};
|
||||
printer.println(line1);
|
||||
assertEquals("a,\"b\"\"c\"" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
public void testPrinter5() throws IOException {
|
||||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.DEFAULT_STRATEGY);
|
||||
String[] line1 = {"a", "b\nc"};
|
||||
printer.println(line1);
|
||||
assertEquals("a,\"b\nc\"" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
public void testPrinter6() throws IOException {
|
||||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.DEFAULT_STRATEGY);
|
||||
String[] line1 = {"a", "b\r\nc"};
|
||||
printer.println(line1);
|
||||
assertEquals("a,\"b\r\nc\"" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
public void testPrinter7() throws IOException {
|
||||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.DEFAULT_STRATEGY);
|
||||
String[] line1 = {"a", "b\\c"};
|
||||
printer.println(line1);
|
||||
assertEquals("a,b\\c" + lineSeparator, sw.toString());
|
||||
}
|
||||
|
||||
public void testExcelPrinter1() throws IOException {
|
||||
StringWriter sw = new StringWriter();
|
||||
CSVPrinter printer = new CSVPrinter(sw, CSVStrategy.EXCEL_STRATEGY);
|
||||
|
|
Loading…
Reference in New Issue