From c26c858b2ec5a12a9d5067e1aae3ae967fef9c7c Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Tue, 19 Jan 2016 06:20:08 +0000 Subject: [PATCH] Update copyright for 2016 in NOTICE.txt git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1725424 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/csv/CSVPrinterTest.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java index 2057c40c..bda7e1c0 100644 --- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java @@ -33,6 +33,7 @@ import java.sql.Statement; import java.util.Arrays; import java.util.Date; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Random; @@ -231,6 +232,68 @@ public class CSVPrinterTest { return DriverManager.getConnection("jdbc:h2:mem:my_test;", "sa", ""); } + @Test + public void testJira135All() throws IOException { + CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote('"').withEscape('\\'); + StringWriter sw = new StringWriter(); + CSVPrinter printer = new CSVPrinter(sw, format); + List list = new LinkedList(); + list.add("\""); + list.add("\n"); + list.add("\\"); + printer.printRecord(list); + printer.close(); + final String expected = "\"\\\"\",\"\\n\",\"\\\"" + format.getRecordSeparator(); + assertEquals(expected, sw.toString()); + String[] record0 = toFirstRecordValues(expected, format); + assertArrayEquals(expectNulls(list.toArray(), format), record0); + } + + @Test + public void testJira135_part3() throws IOException { + CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote('"').withEscape('\\'); + StringWriter sw = new StringWriter(); + CSVPrinter printer = new CSVPrinter(sw, format); + List list = new LinkedList(); + list.add("\\"); + printer.printRecord(list); + printer.close(); + final String expected = "\"\\\\\"" + format.getRecordSeparator(); + assertEquals(expected, sw.toString()); + String[] record0 = toFirstRecordValues(expected, format); + assertArrayEquals(expectNulls(list.toArray(), format), record0); + } + + @Test + public void testJira135_part2() throws IOException { + CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote('"').withEscape('\\'); + StringWriter sw = new StringWriter(); + CSVPrinter printer = new CSVPrinter(sw, format); + List list = new LinkedList(); + list.add("\n"); + printer.printRecord(list); + printer.close(); + final String expected = "\"\\n\"" + format.getRecordSeparator(); + assertEquals(expected, sw.toString()); + String[] record0 = toFirstRecordValues(expected, format); + assertArrayEquals(expectNulls(list.toArray(), format), record0); + } + + @Test + public void testJira135_part1() throws IOException { + CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote('"').withEscape('\\'); + StringWriter sw = new StringWriter(); + CSVPrinter printer = new CSVPrinter(sw, format); + List list = new LinkedList(); + list.add("\""); + printer.printRecord(list); + printer.close(); + final String expected = "\"\\\"\"" + format.getRecordSeparator(); + assertEquals(expected, sw.toString()); + String[] record0 = toFirstRecordValues(expected, format); + assertArrayEquals(expectNulls(list.toArray(), format), record0); + } + @Test public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLException { final StringWriter sw = new StringWriter();