From 3c16933fca2f94a4e9158a4d7099aa44d8e9a755 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 3 Jul 2021 09:24:38 -0400 Subject: [PATCH] Sort members. --- .../org/apache/commons/csv/CSVParserTest.java | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index d7fcf73c..01a8ba8b 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -258,6 +258,18 @@ public class CSVParserTest { assertThrows(NoSuchElementException.class, records::next); } + @Test + public void testCSV235() throws IOException { + final String dqString = "\"aaa\",\"b\"\"bb\",\"ccc\""; // "aaa","b""bb","ccc" + final Iterator records = CSVFormat.RFC4180.parse(new StringReader(dqString)).iterator(); + final CSVRecord record = records.next(); + assertFalse(records.hasNext()); + assertEquals(3, record.size()); + assertEquals("aaa", record.get(0)); + assertEquals("b\"bb", record.get(1)); + assertEquals("ccc", record.get(2)); + } + @Test public void testCSV57() throws Exception { try (final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT)) { @@ -295,6 +307,11 @@ public class CSVParserTest { } } + @Test + public void testDuplicateHeadersAllowedByDefault() throws Exception { + CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader()); + } + @Test public void testDuplicateHeadersNotAllowed() { assertThrows(IllegalArgumentException.class, () -> CSVParser.parse("a,b,a\n1,2,3\nx,y,z", @@ -302,8 +319,10 @@ public class CSVParserTest { } @Test - public void testDuplicateHeadersAllowedByDefault() throws Exception { - CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader()); + public void testEmptyFile() throws Exception { + try (final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT)) { + assertNull(parser.nextRecord()); + } } @Test @@ -314,13 +333,6 @@ public class CSVParserTest { } } - @Test - public void testEmptyFile() throws Exception { - try (final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT)) { - assertNull(parser.nextRecord()); - } - } - @Test public void testEmptyLineBehaviorCSV() throws Exception { 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 class CSVParserTest { assertFalse(records.hasNext()); } + @Test + public void testRepeatedHeadersAreReturnedInCSVRecordHeaderNames() throws IOException { + final Reader in = new StringReader("header1,header2,header1\n1,2,3\n4,5,6"); + final Iterator records = CSVFormat.DEFAULT.withFirstRecordAsHeader().withTrim().parse(in).iterator(); + final CSVRecord record = records.next(); + assertEquals(Arrays.asList("header1", "header2", "header1"), record.getParser().getHeaderNames()); + } + @Test public void testRoundtrip() throws Exception { final StringWriter out = new StringWriter(); @@ -1163,26 +1183,6 @@ public class CSVParserTest { assertEquals(3, record.size()); } - @Test - public void testRepeatedHeadersAreReturnedInCSVRecordHeaderNames() throws IOException { - final Reader in = new StringReader("header1,header2,header1\n1,2,3\n4,5,6"); - final Iterator records = CSVFormat.DEFAULT.withFirstRecordAsHeader().withTrim().parse(in).iterator(); - final CSVRecord record = records.next(); - assertEquals(Arrays.asList("header1", "header2", "header1"), record.getParser().getHeaderNames()); - } - - @Test - public void testCSV235() throws IOException { - final String dqString = "\"aaa\",\"b\"\"bb\",\"ccc\""; // "aaa","b""bb","ccc" - final Iterator records = CSVFormat.RFC4180.parse(new StringReader(dqString)).iterator(); - final CSVRecord record = records.next(); - assertFalse(records.hasNext()); - assertEquals(3, record.size()); - assertEquals("aaa", record.get(0)); - assertEquals("b\"bb", record.get(1)); - assertEquals("ccc", record.get(2)); - } - private void validateLineNumbers(final String lineSeparator) throws IOException { try (final CSVParser parser = CSVParser.parse("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.DEFAULT.withRecordSeparator(lineSeparator))) {