@@ -472,4 +472,47 @@ public void testProvidedHeader() throws Exception {
472472
473473 assertFalse (records .hasNext ());
474474 }
475+
476+ @ Test
477+ public void testGetLineNumberWithLF () throws Exception {
478+ CSVParser parser = new CSVParser ("a\n b\n c" , CSVFormat .DEFAULT .withLineSeparator ("\n " ));
479+
480+ assertEquals (0 , parser .getLineNumber ());
481+ assertNotNull (parser .getRecord ());
482+ assertEquals (1 , parser .getLineNumber ());
483+ assertNotNull (parser .getRecord ());
484+ assertEquals (2 , parser .getLineNumber ());
485+ assertNotNull (parser .getRecord ());
486+ assertEquals (2 , parser .getLineNumber ());
487+ assertNull (parser .getRecord ());
488+ }
489+
490+ @ Test
491+ public void testGetLineNumberWithCRLF () throws Exception {
492+ CSVParser parser = new CSVParser ("a\r \n b\r \n c" , CSVFormat .DEFAULT .withLineSeparator ("\r \n " ));
493+
494+ assertEquals (0 , parser .getLineNumber ());
495+ assertNotNull (parser .getRecord ());
496+ assertEquals (1 , parser .getLineNumber ());
497+ assertNotNull (parser .getRecord ());
498+ assertEquals (2 , parser .getLineNumber ());
499+ assertNotNull (parser .getRecord ());
500+ assertEquals (2 , parser .getLineNumber ());
501+ assertNull (parser .getRecord ());
502+ }
503+
504+ @ Test
505+ @ Ignore ("Line counting doesn't work with CR alone as the line separator, see CSV-75" )
506+ public void testGetLineNumberWithCR () throws Exception {
507+ CSVParser parser = new CSVParser ("a\r b\r c" , CSVFormat .DEFAULT .withLineSeparator ("\r " ));
508+
509+ assertEquals (0 , parser .getLineNumber ());
510+ assertNotNull (parser .getRecord ());
511+ assertEquals (1 , parser .getLineNumber ());
512+ assertNotNull (parser .getRecord ());
513+ assertEquals (2 , parser .getLineNumber ());
514+ assertNotNull (parser .getRecord ());
515+ assertEquals (2 , parser .getLineNumber ());
516+ assertNull (parser .getRecord ());
517+ }
475518}
0 commit comments