Skip to content

Commit 3c2291c

Browse files
committed
expand comment marker test to contrast printed comment with quoted value
1 parent a99f260 commit 3c2291c

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,15 +1835,24 @@ void testQuoteCommentMarkerFirstChar() throws IOException {
18351835
final StringWriter sw = new StringWriter();
18361836
final String col1 = ";comment-like";
18371837
try (CSVPrinter printer = new CSVPrinter(sw, format)) {
1838+
// A real comment is written with the marker, unquoted.
1839+
printer.printComment("a real comment");
1840+
// A value starting with the marker is quoted, so it does not read back as a comment.
18381841
printer.printRecord(col1, "b");
1842+
// The marker past the first character does not start a comment, so only the leading-marker value is quoted.
1843+
printer.printRecord("a;b", ";c");
18391844
}
1840-
assertEquals("\";comment-like\",b" + RECORD_SEPARATOR, sw.toString());
1841-
// A value starting with the comment marker must read back as data, not a dropped comment line.
1845+
assertEquals("; a real comment" + RECORD_SEPARATOR +
1846+
"\";comment-like\",b" + RECORD_SEPARATOR +
1847+
"a;b,\";c\"" + RECORD_SEPARATOR, sw.toString());
1848+
// The comment is dropped on read; both data records survive intact.
18421849
try (CSVParser parser = CSVParser.parse(sw.toString(), format)) {
18431850
final List<CSVRecord> records = parser.getRecords();
1844-
assertEquals(1, records.size());
1851+
assertEquals(2, records.size());
18451852
assertEquals(col1, records.get(0).get(0));
18461853
assertEquals("b", records.get(0).get(1));
1854+
assertEquals("a;b", records.get(1).get(0));
1855+
assertEquals(";c", records.get(1).get(1));
18471856
}
18481857
}
18491858

0 commit comments

Comments
 (0)