diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index d7173a73..3db28fcd 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -36,6 +36,9 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.io.Reader; +import java.io.IOException; +import java.io.StringReader; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; @@ -1175,4 +1178,31 @@ public class CSVFormatTest { assertEquals(System.getProperty("line.separator"), formatWithRecordSeparator.getRecordSeparator()); } + @Test + public void testPrintWithEscapesEndWithCRLF() throws IOException { + final Reader in = new StringReader("x,y,x\r\na,?b,c\r\n"); + final Appendable out = new StringBuilder(); + final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF); + format.print(in,out,true); + assertEquals("x?,y?,x?r?na?,??b?,c?r?n", out.toString()); + } + + @Test + public void testPrintWithEscapesEndWithoutCRLF() throws IOException { + final Reader in = new StringReader("x,y,x"); + final Appendable out = new StringBuilder(); + final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF); + format.print(in,out,true); + assertEquals("x?,y?,x", out.toString()); + } + + @Test + public void testFormatToString() throws IOException { + final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',') + .withQuoteMode(QuoteMode.MINIMAL).withRecordSeparator(CRLF).withQuote('"') + .withNullString("").withIgnoreHeaderCase(true) + .withHeaderComments("This is HeaderComments").withHeader("col1","col2","col3"); + assertEquals("Delimiter=<,> Escape= QuoteChar=<\"> QuoteMode= NullString=<> RecordSeparator=<" +CRLF+ + "> IgnoreHeaderCase:ignored SkipHeaderRecord:false HeaderComments:[This is HeaderComments] Header:[col1, col2, col3]", format.toString()); + } }