Add API org.apache.commons.csv.CSVParser.getRecords(T).

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1584903 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2014-04-04 20:44:46 +00:00
parent 6b3afdc93d
commit c2ed3be44d
1 changed files with 19 additions and 0 deletions

View File

@ -38,6 +38,7 @@ import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -66,6 +67,8 @@ public class CSVParserTest {
// + " \"foo\n,,\n\"\",,\n\\\"\",d,e\n"; // + " \"foo\n,,\n\"\",,\n\\\"\",d,e\n";
+ " \"foo\n,,\n\"\",,\n\"\"\",d,e\n"; // changed to use standard CSV escaping + " \"foo\n,,\n\"\",,\n\"\"\",d,e\n"; // changed to use standard CSV escaping
private static final String CSV_INPUT_1 = "a,b,c,d";
private static final String[][] RESULT = { private static final String[][] RESULT = {
{"a", "b", "c", "d"}, {"a", "b", "c", "d"},
{"a", "b", "1 2"}, {"a", "b", "1 2"},
@ -511,6 +514,22 @@ public class CSVParserTest {
this.validateLineNumbers(String.valueOf(LF)); this.validateLineNumbers(String.valueOf(LF));
} }
@Test
public void testGetOneLine() throws IOException {
final CSVParser parser = CSVParser.parse(CSV_INPUT_1, CSVFormat.DEFAULT);
final CSVRecord record = parser.getRecords().get(0);
assertArrayEquals(RESULT[0], record.values());
parser.close();
}
@Test
public void testGetOneLineCustomCollection() throws IOException {
final CSVParser parser = CSVParser.parse(CSV_INPUT_1, CSVFormat.DEFAULT);
final CSVRecord record = parser.getRecords(new LinkedList<CSVRecord>()).getFirst();
assertArrayEquals(RESULT[0], record.values());
parser.close();
}
@Test @Test
public void testGetRecordNumberWithCR() throws Exception { public void testGetRecordNumberWithCR() throws Exception {
this.validateRecordNumbers(String.valueOf(CR)); this.validateRecordNumbers(String.valueOf(CR));