saleemno1 commented on code in PR #625:
URL: https://github.com/apache/commons-csv/pull/625#discussion_r3622207032
##########
src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java:
##########
@@ -240,4 +240,72 @@ void testReadLookahead2() throws Exception {
assertEquals('d', br.getLastChar());
}
}
+
+ @Test
+ void testReadAndPeekArrayFromChunkedReader() throws Exception {
+ try (ExtendedBufferedReader br = new ExtendedBufferedReader(new
ChunkedReader("abcdef"))) {
+ final char[] peeked = new char[3];
+ assertEquals(3, br.peek(peeked));
+ assertArrayEquals(new char[] { 'a', 'b', 'c' }, peeked);
+ final char[] read = new char[3];
+ assertEquals(3, br.read(read, 0, 3));
+ assertArrayEquals(new char[] { 'a', 'b', 'c' }, read);
+ }
+ }
+
+ @Test
+ void testReadArrayPastEndOfChunkedReader() throws Exception {
+ try (ExtendedBufferedReader br = new ExtendedBufferedReader(new
ChunkedReader("ab"))) {
+ final char[] read = new char[4];
+ assertEquals(2, br.read(read, 0, 4));
+ assertEquals('a', read[0]);
+ assertEquals('b', read[1]);
+ assertEquals(EOF, br.read(read, 0, 4));
+ }
+ }
+
+ @Test
+ void testPeekArrayPastEndOfChunkedReader() throws Exception {
+ try (ExtendedBufferedReader br = new ExtendedBufferedReader(new
ChunkedReader("ab"))) {
+ final char[] peeked = new char[4];
+ assertEquals(2, br.peek(peeked));
+ assertEquals('a', peeked[0]);
+ assertEquals('b', peeked[1]);
+ }
+ }
+
+ /**
+ * A reader that returns one character per call and never reports itself
ready, like a socket or pipe that delivers data in chunks.
+ */
+ private static final class ChunkedReader extends java.io.Reader {
Review Comment:
Done. It's now a small `ChunkedReader extends StringReader` that overrides
`read(char[], int, int)` to hand back one char and `ready()` to return false,
which is a lot less code than the raw `Reader`.
##########
src/test/java/org/apache/commons/csv/CSVParserTest.java:
##########
@@ -1709,6 +1709,47 @@ void testParseWithDelimiterStringWithEscape() throws
IOException {
}
}
+ @Test
+ void testParseWithDelimiterStringFromChunkedReader() throws IOException {
+ // A reader that hands out one character at a time and never reports
itself ready, like a socket or pipe.
+ final Reader chunked = new Reader() {
Review Comment:
Right, they were the same thing. Pulled it out into a package-private
`ChunkedReader` in the test tree so both this test and
ExtendedBufferedReaderTest use it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]