Skip to content

Commit 0f3b336

Browse files
committed
Add org.apache.commons.csv.CSVParserTest.testGetOneLineOneParser(). See discussion in [CSV-110].
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1585491 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8e18054 commit 0f3b336

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.io.File;
3232
import java.io.IOException;
3333
import java.io.InputStreamReader;
34+
import java.io.PipedReader;
35+
import java.io.PipedWriter;
3436
import java.io.Reader;
3537
import java.io.StringReader;
3638
import java.io.StringWriter;
@@ -69,6 +71,8 @@ public class CSVParserTest {
6971

7072
private static final String CSV_INPUT_1 = "a,b,c,d";
7173

74+
private static final String CSV_INPUT_2 = "a,b,1 2";
75+
7276
private static final String[][] RESULT = {
7377
{"a", "b", "c", "d"},
7478
{"a", "b", "1 2"},
@@ -530,6 +534,29 @@ public void testGetOneLineCustomCollection() throws IOException {
530534
parser.close();
531535
}
532536

537+
/**
538+
* Tests reusing a parser to process new string records one at a time as they are being discovered. See [CSV-110].
539+
*
540+
* @throws IOException
541+
*/
542+
@Test
543+
public void testGetOneLineOneParser() throws IOException {
544+
PipedWriter writer = new PipedWriter();
545+
PipedReader reader = new PipedReader(writer);
546+
final CSVFormat format = CSVFormat.DEFAULT;
547+
final CSVParser parser = new CSVParser(reader, format);
548+
try {
549+
writer.append(CSV_INPUT_1 + format.getRecordSeparator());
550+
final CSVRecord record1 = parser.nextRecord();
551+
assertArrayEquals(RESULT[0], record1.values());
552+
writer.append(CSV_INPUT_2 + format.getRecordSeparator());
553+
final CSVRecord record2 = parser.nextRecord();
554+
assertArrayEquals(RESULT[1], record2.values());
555+
} finally {
556+
parser.close();
557+
}
558+
}
559+
533560
@Test
534561
public void testGetRecordNumberWithCR() throws Exception {
535562
this.validateRecordNumbers(String.valueOf(CR));

0 commit comments

Comments
 (0)