commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaco...@apache.org
Subject svn commit: r1065519 - /commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/CSVPrinterTest.java
Date Mon, 31 Jan 2011 08:34:21 GMT
Author: jacopoc
Date: Mon Jan 31 08:34:21 2011
New Revision: 1065519

URL: http://svn.apache.org/viewvc?rev=1065519&view=rev
Log:
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.

Modified:
    commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/CSVPrinterTest.java

Modified: commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/CSVPrinterTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/CSVPrinterTest.java?rev=1065519&r1=1065518&r2=1065519&view=diff
==============================================================================
--- commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/CSVPrinterTest.java (original)
+++ commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/CSVPrinterTest.java Mon Jan
31 08:34:21 2011
@@ -57,6 +57,38 @@ public class CSVPrinterTest extends Test
     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);



Mime
View raw message