Skip to content

Commit 83d6f81

Browse files
authored
improve CSVFormat test coverage (apache#63)
* improve CSVFormat test coverage * remove print in test
1 parent c2f46df commit 83d6f81

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
import java.io.ByteArrayOutputStream;
3737
import java.io.ObjectInputStream;
3838
import java.io.ObjectOutputStream;
39+
import java.io.Reader;
40+
import java.io.IOException;
41+
import java.io.StringReader;
3942
import java.lang.reflect.Method;
4043
import java.lang.reflect.Modifier;
4144
import java.util.Arrays;
@@ -1175,4 +1178,31 @@ public void testWithSystemRecordSeparator() {
11751178
assertEquals(System.getProperty("line.separator"), formatWithRecordSeparator.getRecordSeparator());
11761179
}
11771180

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+
}
11781208
}

0 commit comments

Comments
 (0)