@@ -258,6 +258,18 @@ public void testClose() throws Exception {
258258 assertThrows (NoSuchElementException .class , records ::next );
259259 }
260260
261+ @ Test
262+ public void testCSV235 () throws IOException {
263+ final String dqString = "\" aaa\" ,\" b\" \" bb\" ,\" ccc\" " ; // "aaa","b""bb","ccc"
264+ final Iterator <CSVRecord > records = CSVFormat .RFC4180 .parse (new StringReader (dqString )).iterator ();
265+ final CSVRecord record = records .next ();
266+ assertFalse (records .hasNext ());
267+ assertEquals (3 , record .size ());
268+ assertEquals ("aaa" , record .get (0 ));
269+ assertEquals ("b\" bb" , record .get (1 ));
270+ assertEquals ("ccc" , record .get (2 ));
271+ }
272+
261273 @ Test
262274 public void testCSV57 () throws Exception {
263275 try (final CSVParser parser = CSVParser .parse ("" , CSVFormat .DEFAULT )) {
@@ -295,15 +307,22 @@ public void testDefaultFormat() throws IOException {
295307 }
296308 }
297309
310+ @ Test
311+ public void testDuplicateHeadersAllowedByDefault () throws Exception {
312+ CSVParser .parse ("a,b,a\n 1,2,3\n x,y,z" , CSVFormat .DEFAULT .withHeader ());
313+ }
314+
298315 @ Test
299316 public void testDuplicateHeadersNotAllowed () {
300317 assertThrows (IllegalArgumentException .class , () -> CSVParser .parse ("a,b,a\n 1,2,3\n x,y,z" ,
301318 CSVFormat .DEFAULT .withHeader ().withAllowDuplicateHeaderNames (false )));
302319 }
303320
304321 @ Test
305- public void testDuplicateHeadersAllowedByDefault () throws Exception {
306- CSVParser .parse ("a,b,a\n 1,2,3\n x,y,z" , CSVFormat .DEFAULT .withHeader ());
322+ public void testEmptyFile () throws Exception {
323+ try (final CSVParser parser = CSVParser .parse ("" , CSVFormat .DEFAULT )) {
324+ assertNull (parser .nextRecord ());
325+ }
307326 }
308327
309328 @ Test
@@ -314,13 +333,6 @@ public void testEmptyFileHeaderParsing() throws Exception {
314333 }
315334 }
316335
317- @ Test
318- public void testEmptyFile () throws Exception {
319- try (final CSVParser parser = CSVParser .parse ("" , CSVFormat .DEFAULT )) {
320- assertNull (parser .nextRecord ());
321- }
322- }
323-
324336 @ Test
325337 public void testEmptyLineBehaviorCSV () throws Exception {
326338 final String [] codes = { "hello,\r \n \r \n \r \n " , "hello,\n \n \n " , "hello,\" \" \r \n \r \n \r \n " , "hello,\" \" \n \n \n " };
@@ -1065,6 +1077,14 @@ public void testProvidedHeaderAuto() throws Exception {
10651077 assertFalse (records .hasNext ());
10661078 }
10671079
1080+ @ Test
1081+ public void testRepeatedHeadersAreReturnedInCSVRecordHeaderNames () throws IOException {
1082+ final Reader in = new StringReader ("header1,header2,header1\n 1,2,3\n 4,5,6" );
1083+ final Iterator <CSVRecord > records = CSVFormat .DEFAULT .withFirstRecordAsHeader ().withTrim ().parse (in ).iterator ();
1084+ final CSVRecord record = records .next ();
1085+ assertEquals (Arrays .asList ("header1" , "header2" , "header1" ), record .getParser ().getHeaderNames ());
1086+ }
1087+
10681088 @ Test
10691089 public void testRoundtrip () throws Exception {
10701090 final StringWriter out = new StringWriter ();
@@ -1163,26 +1183,6 @@ public void testTrim() throws Exception {
11631183 assertEquals (3 , record .size ());
11641184 }
11651185
1166- @ Test
1167- public void testRepeatedHeadersAreReturnedInCSVRecordHeaderNames () throws IOException {
1168- final Reader in = new StringReader ("header1,header2,header1\n 1,2,3\n 4,5,6" );
1169- final Iterator <CSVRecord > records = CSVFormat .DEFAULT .withFirstRecordAsHeader ().withTrim ().parse (in ).iterator ();
1170- final CSVRecord record = records .next ();
1171- assertEquals (Arrays .asList ("header1" , "header2" , "header1" ), record .getParser ().getHeaderNames ());
1172- }
1173-
1174- @ Test
1175- public void testCSV235 () throws IOException {
1176- final String dqString = "\" aaa\" ,\" b\" \" bb\" ,\" ccc\" " ; // "aaa","b""bb","ccc"
1177- final Iterator <CSVRecord > records = CSVFormat .RFC4180 .parse (new StringReader (dqString )).iterator ();
1178- final CSVRecord record = records .next ();
1179- assertFalse (records .hasNext ());
1180- assertEquals (3 , record .size ());
1181- assertEquals ("aaa" , record .get (0 ));
1182- assertEquals ("b\" bb" , record .get (1 ));
1183- assertEquals ("ccc" , record .get (2 ));
1184- }
1185-
11861186 private void validateLineNumbers (final String lineSeparator ) throws IOException {
11871187 try (final CSVParser parser = CSVParser .parse ("a" + lineSeparator + "b" + lineSeparator + "c" ,
11881188 CSVFormat .DEFAULT .withRecordSeparator (lineSeparator ))) {
0 commit comments