|
33 | 33 | import java.util.Arrays; |
34 | 34 | import java.util.Date; |
35 | 35 | import java.util.Iterator; |
| 36 | +import java.util.LinkedList; |
36 | 37 | import java.util.List; |
37 | 38 | import java.util.Random; |
38 | 39 |
|
@@ -231,6 +232,68 @@ private Connection geH2Connection() throws SQLException, ClassNotFoundException |
231 | 232 | return DriverManager.getConnection("jdbc:h2:mem:my_test;", "sa", ""); |
232 | 233 | } |
233 | 234 |
|
| 235 | + @Test |
| 236 | + public void testJira135All() throws IOException { |
| 237 | + CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote('"').withEscape('\\'); |
| 238 | + StringWriter sw = new StringWriter(); |
| 239 | + CSVPrinter printer = new CSVPrinter(sw, format); |
| 240 | + List<String> list = new LinkedList<String>(); |
| 241 | + list.add("\""); |
| 242 | + list.add("\n"); |
| 243 | + list.add("\\"); |
| 244 | + printer.printRecord(list); |
| 245 | + printer.close(); |
| 246 | + final String expected = "\"\\\"\",\"\\n\",\"\\\"" + format.getRecordSeparator(); |
| 247 | + assertEquals(expected, sw.toString()); |
| 248 | + String[] record0 = toFirstRecordValues(expected, format); |
| 249 | + assertArrayEquals(expectNulls(list.toArray(), format), record0); |
| 250 | + } |
| 251 | + |
| 252 | + @Test |
| 253 | + public void testJira135_part3() throws IOException { |
| 254 | + CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote('"').withEscape('\\'); |
| 255 | + StringWriter sw = new StringWriter(); |
| 256 | + CSVPrinter printer = new CSVPrinter(sw, format); |
| 257 | + List<String> list = new LinkedList<String>(); |
| 258 | + list.add("\\"); |
| 259 | + printer.printRecord(list); |
| 260 | + printer.close(); |
| 261 | + final String expected = "\"\\\\\"" + format.getRecordSeparator(); |
| 262 | + assertEquals(expected, sw.toString()); |
| 263 | + String[] record0 = toFirstRecordValues(expected, format); |
| 264 | + assertArrayEquals(expectNulls(list.toArray(), format), record0); |
| 265 | + } |
| 266 | + |
| 267 | + @Test |
| 268 | + public void testJira135_part2() throws IOException { |
| 269 | + CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote('"').withEscape('\\'); |
| 270 | + StringWriter sw = new StringWriter(); |
| 271 | + CSVPrinter printer = new CSVPrinter(sw, format); |
| 272 | + List<String> list = new LinkedList<String>(); |
| 273 | + list.add("\n"); |
| 274 | + printer.printRecord(list); |
| 275 | + printer.close(); |
| 276 | + final String expected = "\"\\n\"" + format.getRecordSeparator(); |
| 277 | + assertEquals(expected, sw.toString()); |
| 278 | + String[] record0 = toFirstRecordValues(expected, format); |
| 279 | + assertArrayEquals(expectNulls(list.toArray(), format), record0); |
| 280 | + } |
| 281 | + |
| 282 | + @Test |
| 283 | + public void testJira135_part1() throws IOException { |
| 284 | + CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote('"').withEscape('\\'); |
| 285 | + StringWriter sw = new StringWriter(); |
| 286 | + CSVPrinter printer = new CSVPrinter(sw, format); |
| 287 | + List<String> list = new LinkedList<String>(); |
| 288 | + list.add("\""); |
| 289 | + printer.printRecord(list); |
| 290 | + printer.close(); |
| 291 | + final String expected = "\"\\\"\"" + format.getRecordSeparator(); |
| 292 | + assertEquals(expected, sw.toString()); |
| 293 | + String[] record0 = toFirstRecordValues(expected, format); |
| 294 | + assertArrayEquals(expectNulls(list.toArray(), format), record0); |
| 295 | + } |
| 296 | + |
234 | 297 | @Test |
235 | 298 | public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLException { |
236 | 299 | final StringWriter sw = new StringWriter(); |
|
0 commit comments