This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-csv.git
commit 3c16933fca2f94a4e9158a4d7099aa44d8e9a755 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jul 3 09:24:38 2021 -0400 Sort members. --- .../java/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 d7fcf73..01a8ba8 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -259,6 +259,18 @@ public class CSVParserTest { } @Test + public void testCSV235() throws IOException { + final String dqString = "\"aaa\",\"b\"\"bb\",\"ccc\""; // "aaa","b""bb","ccc" + final Iterator<CSVRecord> 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)) { final List<CSVRecord> list = parser.getRecords(); @@ -296,14 +308,21 @@ 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", CSVFormat.DEFAULT.withHeader().withAllowDuplicateHeaderNames(false))); } @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 @@ -315,13 +334,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" }; final String[][] res = { { "hello", "" } // CSV format ignores empty lines @@ -1066,6 +1078,14 @@ public class CSVParserTest { } @Test + public void testRepeatedHeadersAreReturnedInCSVRecordHeaderNames() throws IOException { + final Reader in = new StringReader("header1,header2,header1\n1,2,3\n4,5,6"); + final Iterator<CSVRecord> 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(); try (final CSVPrinter printer = new CSVPrinter(out, CSVFormat.DEFAULT)) { @@ -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<CSVRecord> 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<CSVRecord> 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))) {