Skip to content

Commit 7d2ec7a

Browse files
committed
CSV-85 Allow comments to be returned in CSVRecord
Added test for comment before header git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1307078 13f79535-47bb-0310-9956-ffa450edef68
1 parent 29c80da commit 7d2ec7a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,23 @@ public void testHeader() throws Exception {
466466
assertFalse(records.hasNext());
467467
}
468468

469+
@Test
470+
public void testHeaderComment() throws Exception {
471+
Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
472+
473+
Iterator<CSVRecord> records = CSVFormat.DEFAULT.withCommentStart('#').withHeader().parse(in).iterator();
474+
475+
for (int i = 0; i < 2; i++) {
476+
assertTrue(records.hasNext());
477+
CSVRecord record = records.next();
478+
assertEquals(record.get(0), record.get("a"));
479+
assertEquals(record.get(1), record.get("b"));
480+
assertEquals(record.get(2), record.get("c"));
481+
}
482+
483+
assertFalse(records.hasNext());
484+
}
485+
469486
@Test
470487
public void testProvidedHeader() throws Exception {
471488
Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");

0 commit comments

Comments
 (0)