Skip to content

Commit 5a9436d

Browse files
committed
[CSV-121] Exception that the header contains duplicate names when the column names are empty. Add a test that shows that ONE missing header is OK.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1602166 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1282503 commit 5a9436d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,22 @@ public void testHeader() throws Exception {
633633
assertFalse(records.hasNext());
634634
}
635635

636+
@Test
637+
public void testHeaderMissing() throws Exception {
638+
final Reader in = new StringReader("a,,c\n1,2,3\nx,y,z");
639+
640+
final Iterator<CSVRecord> records = CSVFormat.DEFAULT.withHeader().parse(in).iterator();
641+
642+
for (int i = 0; i < 2; i++) {
643+
assertTrue(records.hasNext());
644+
final CSVRecord record = records.next();
645+
assertEquals(record.get(0), record.get("a"));
646+
assertEquals(record.get(2), record.get("c"));
647+
}
648+
649+
assertFalse(records.hasNext());
650+
}
651+
636652
@Test
637653
public void testHeaderComment() throws Exception {
638654
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");

0 commit comments

Comments
 (0)