|
36 | 36 | import java.io.ByteArrayOutputStream; |
37 | 37 | import java.io.ObjectInputStream; |
38 | 38 | import java.io.ObjectOutputStream; |
| 39 | +import java.io.Reader; |
| 40 | +import java.io.IOException; |
| 41 | +import java.io.StringReader; |
39 | 42 | import java.lang.reflect.Method; |
40 | 43 | import java.lang.reflect.Modifier; |
41 | 44 | import java.util.Arrays; |
@@ -1175,4 +1178,31 @@ public void testWithSystemRecordSeparator() { |
1175 | 1178 | assertEquals(System.getProperty("line.separator"), formatWithRecordSeparator.getRecordSeparator()); |
1176 | 1179 | } |
1177 | 1180 |
|
| 1181 | + @Test |
| 1182 | + public void testPrintWithEscapesEndWithCRLF() throws IOException { |
| 1183 | + final Reader in = new StringReader("x,y,x\r\na,?b,c\r\n"); |
| 1184 | + final Appendable out = new StringBuilder(); |
| 1185 | + final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF); |
| 1186 | + format.print(in,out,true); |
| 1187 | + assertEquals("x?,y?,x?r?na?,??b?,c?r?n", out.toString()); |
| 1188 | + } |
| 1189 | + |
| 1190 | + @Test |
| 1191 | + public void testPrintWithEscapesEndWithoutCRLF() throws IOException { |
| 1192 | + final Reader in = new StringReader("x,y,x"); |
| 1193 | + final Appendable out = new StringBuilder(); |
| 1194 | + final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF); |
| 1195 | + format.print(in,out,true); |
| 1196 | + assertEquals("x?,y?,x", out.toString()); |
| 1197 | + } |
| 1198 | + |
| 1199 | + @Test |
| 1200 | + public void testFormatToString() throws IOException { |
| 1201 | + final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',') |
| 1202 | + .withQuoteMode(QuoteMode.MINIMAL).withRecordSeparator(CRLF).withQuote('"') |
| 1203 | + .withNullString("").withIgnoreHeaderCase(true) |
| 1204 | + .withHeaderComments("This is HeaderComments").withHeader("col1","col2","col3"); |
| 1205 | + assertEquals("Delimiter=<,> Escape=<?> QuoteChar=<\"> QuoteMode=<MINIMAL> NullString=<> RecordSeparator=<" +CRLF+ |
| 1206 | + "> IgnoreHeaderCase:ignored SkipHeaderRecord:false HeaderComments:[This is HeaderComments] Header:[col1, col2, col3]", format.toString()); |
| 1207 | + } |
1178 | 1208 | } |
0 commit comments