Sort members.

This commit is contained in:
Gary Gregory 2021-07-03 09:24:38 -04:00
parent d1601d3fec
commit 3c16933fca

View File

@ -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<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)) {
@ -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<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();
@ -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))) {