|
53 | 53 | */ |
54 | 54 | public class CSVPrinterTest { |
55 | 55 |
|
| 56 | + private static final char QUOTE_CH = '\''; |
56 | 57 | private static final int ITERATIONS_FOR_RANDOM_TEST = 50000; |
57 | 58 |
|
58 | 59 | private static String printable(final String s) { |
@@ -290,35 +291,46 @@ public void testEOLQuoted() throws IOException { |
290 | 291 | } |
291 | 292 |
|
292 | 293 | @Test |
293 | | - public void testEscapeBackslash() throws IOException { |
| 294 | + public void testEscapeBackslash1() throws IOException { |
294 | 295 | StringWriter sw = new StringWriter(); |
295 | | - final char quoteChar = '\''; |
296 | | - final String eol = "\r\n"; |
297 | | - try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) { |
| 296 | + try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { |
298 | 297 | printer.print("\\"); |
299 | 298 | } |
300 | 299 | assertEquals("'\\'", sw.toString()); |
| 300 | + } |
301 | 301 |
|
302 | | - sw = new StringWriter(); |
303 | | - try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) { |
| 302 | + @Test |
| 303 | + public void testEscapeBackslash2() throws IOException { |
| 304 | + StringWriter sw = new StringWriter(); |
| 305 | + try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { |
304 | 306 | printer.print("\\\r"); |
305 | 307 | } |
306 | 308 | assertEquals("'\\\r'", sw.toString()); |
307 | 309 |
|
308 | | - sw = new StringWriter(); |
309 | | - try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) { |
| 310 | + } |
| 311 | + |
| 312 | + @Test |
| 313 | + public void testEscapeBackslash3() throws IOException { |
| 314 | + StringWriter sw = new StringWriter(); |
| 315 | + try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { |
310 | 316 | printer.print("X\\\r"); |
311 | 317 | } |
312 | 318 | assertEquals("'X\\\r'", sw.toString()); |
| 319 | + } |
313 | 320 |
|
314 | | - sw = new StringWriter(); |
315 | | - try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) { |
316 | | - printer.printRecord(new Object[] { "\\\r" }); |
| 321 | + @Test |
| 322 | + public void testEscapeBackslash4() throws IOException { |
| 323 | + StringWriter sw = new StringWriter(); |
| 324 | + try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { |
| 325 | + printer.print("\\\\"); |
317 | 326 | } |
318 | | - assertEquals("'\\\r'" + eol, sw.toString()); |
| 327 | + assertEquals("'\\\\'", sw.toString()); |
| 328 | + } |
319 | 329 |
|
320 | | - sw = new StringWriter(); |
321 | | - try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(quoteChar))) { |
| 330 | + @Test |
| 331 | + public void testEscapeBackslash5() throws IOException { |
| 332 | + StringWriter sw = new StringWriter(); |
| 333 | + try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { |
322 | 334 | printer.print("\\\\"); |
323 | 335 | } |
324 | 336 | assertEquals("'\\\\'", sw.toString()); |
|
0 commit comments