@@ -342,6 +342,15 @@ public void testRandom() throws Exception {
342342 doRandom (CSVFormat .MYSQL , iter );
343343 }
344344
345+ @ Test
346+ public void testPlainQuoted () throws IOException {
347+ final StringWriter sw = new StringWriter ();
348+ final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .newBuilder ().withQuoteChar ('\'' ).build ());
349+ printer .print ("abc" );
350+ assertEquals ("abc" , sw .toString ());
351+ printer .close ();
352+ }
353+
345354 @ Test
346355 public void testSingleLineComment () throws IOException {
347356 final StringWriter sw = new StringWriter ();
@@ -352,4 +361,64 @@ public void testSingleLineComment() throws IOException {
352361 printer .close ();
353362 }
354363
364+ @ Test
365+ public void testSingleQuoteQuoted () throws IOException {
366+ final StringWriter sw = new StringWriter ();
367+ final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .newBuilder ().withQuoteChar ('\'' ).build ());
368+ printer .print ("a'b'c" );
369+ printer .print ("xyz" );
370+ assertEquals ("'a''b''c',xyz" , sw .toString ());
371+ printer .close ();
372+ }
373+
374+ @ Test
375+ public void testDelimeterQuoted () throws IOException {
376+ final StringWriter sw = new StringWriter ();
377+ final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .newBuilder ().withQuoteChar ('\'' ).build ());
378+ printer .print ("a,b,c" );
379+ printer .print ("xyz" );
380+ assertEquals ("'a,b,c',xyz" , sw .toString ());
381+ printer .close ();
382+ }
383+
384+ @ Test
385+ public void testPlainEscaped () throws IOException {
386+ final StringWriter sw = new StringWriter ();
387+ final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .newBuilder ().withQuoteChar (null ).withEscape ('!' ).build ());
388+ printer .print ("abc" );
389+ printer .print ("xyz" );
390+ assertEquals ("abc,xyz" , sw .toString ());
391+ printer .close ();
392+ }
393+
394+ @ Test
395+ public void testDelimiterEscaped () throws IOException {
396+ final StringWriter sw = new StringWriter ();
397+ final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .newBuilder ().withQuoteChar (null ).withEscape ('!' ).build ());
398+ printer .print ("a,b,c" );
399+ printer .print ("xyz" );
400+ assertEquals ("a!,b!,c,xyz" , sw .toString ());
401+ printer .close ();
402+ }
403+
404+ @ Test
405+ public void testPlainPlain () throws IOException {
406+ final StringWriter sw = new StringWriter ();
407+ final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .newBuilder ().withQuoteChar (null ).build ());
408+ printer .print ("abc" );
409+ printer .print ("xyz" );
410+ assertEquals ("abc,xyz" , sw .toString ());
411+ printer .close ();
412+ }
413+
414+ @ Test
415+ public void testDelimiterPlain () throws IOException {
416+ final StringWriter sw = new StringWriter ();
417+ final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .newBuilder ().withQuoteChar (null ).build ());
418+ printer .print ("a,b,c" );
419+ printer .print ("xyz" );
420+ assertEquals ("a,b,c,xyz" , sw .toString ());
421+ printer .close ();
422+ }
423+
355424}
0 commit comments