You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/05/07 01:54:45 UTC
svn commit: r1479730 -
/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
Author: sebb
Date: Mon May 6 23:54:45 2013
New Revision: 1479730
URL: http://svn.apache.org/r1479730
Log:
Add some more tests
Modified:
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java?rev=1479730&r1=1479729&r2=1479730&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java Mon May 6 23:54:45 2013
@@ -343,6 +343,15 @@ public class CSVPrinterTest {
}
@Test
+ public void testPlainQuoted() throws IOException {
+ final StringWriter sw = new StringWriter();
+ final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar('\'').build());
+ printer.print("abc");
+ assertEquals("abc", sw.toString());
+ printer.close();
+ }
+
+ @Test
public void testSingleLineComment() throws IOException {
final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withCommentStart('#').build());
@@ -352,4 +361,64 @@ public class CSVPrinterTest {
printer.close();
}
+ @Test
+ public void testSingleQuoteQuoted() throws IOException {
+ final StringWriter sw = new StringWriter();
+ final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar('\'').build());
+ printer.print("a'b'c");
+ printer.print("xyz");
+ assertEquals("'a''b''c',xyz", sw.toString());
+ printer.close();
+ }
+
+ @Test
+ public void testDelimeterQuoted() throws IOException {
+ final StringWriter sw = new StringWriter();
+ final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar('\'').build());
+ printer.print("a,b,c");
+ printer.print("xyz");
+ assertEquals("'a,b,c',xyz", sw.toString());
+ printer.close();
+ }
+
+ @Test
+ public void testPlainEscaped() throws IOException {
+ final StringWriter sw = new StringWriter();
+ final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar(null).withEscape('!').build());
+ printer.print("abc");
+ printer.print("xyz");
+ assertEquals("abc,xyz", sw.toString());
+ printer.close();
+ }
+
+ @Test
+ public void testDelimiterEscaped() throws IOException {
+ final StringWriter sw = new StringWriter();
+ final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar(null).withEscape('!').build());
+ printer.print("a,b,c");
+ printer.print("xyz");
+ assertEquals("a!,b!,c,xyz", sw.toString());
+ printer.close();
+ }
+
+ @Test
+ public void testPlainPlain() throws IOException {
+ final StringWriter sw = new StringWriter();
+ final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar(null).build());
+ printer.print("abc");
+ printer.print("xyz");
+ assertEquals("abc,xyz", sw.toString());
+ printer.close();
+ }
+
+ @Test
+ public void testDelimiterPlain() throws IOException {
+ final StringWriter sw = new StringWriter();
+ final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar(null).build());
+ printer.print("a,b,c");
+ printer.print("xyz");
+ assertEquals("a,b,c,xyz", sw.toString());
+ printer.close();
+ }
+
}