This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-csv.git
commit d729b442e4bbdf6c603e3e64955d27352744cc29 Author: Gary Gregory <[email protected]> AuthorDate: Sat Jun 13 12:37:26 2026 +0000 Sort members --- .../java/org/apache/commons/csv/CSVParserTest.java | 28 +++++++-------- .../org/apache/commons/csv/CSVPrinterTest.java | 40 +++++++++++----------- .../java/org/apache/commons/csv/LexerTest.java | 24 ++++++------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index cccbef4e..dca37fc5 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -1668,20 +1668,6 @@ class CSVParserTest { } } - /** - * Tests <a href="https://issues.apache.org/jira/browse/CSV-324">CSV-324</a>. - */ - @Test - void testPartialMultiCharacterDelimiterAtEOF() throws IOException { - final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").get(); - try (CSVParser parser = format.parse(new StringReader("a[|]b[|"))) { - final CSVRecord record = parser.nextRecord(); - assertEquals("a", record.get(0)); - assertEquals("b[|", record.get(1)); - assertEquals(2, record.size()); - } - } - /** * A truncated escaped multi-character delimiter at EOF must stay literal data and not be completed from a stale * escape delimiter look-ahead. @@ -1696,6 +1682,20 @@ class CSVParserTest { } } + /** + * Tests <a href="https://issues.apache.org/jira/browse/CSV-324">CSV-324</a>. + */ + @Test + void testPartialMultiCharacterDelimiterAtEOF() throws IOException { + final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").get(); + try (CSVParser parser = format.parse(new StringReader("a[|]b[|"))) { + final CSVRecord record = parser.nextRecord(); + assertEquals("a", record.get(0)); + assertEquals("b[|", record.get(1)); + assertEquals(2, record.size()); + } + } + @Test void testProvidedHeader() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java index 79ce987b..b5878221 100644 --- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java @@ -423,26 +423,6 @@ class CSVPrinterTest { } } - @Test - void testQuoteCharEscapedWithQuoteModeNone() throws IOException { - final CSVFormat format = CSVFormat.DEFAULT.builder().setQuote('"').setEscape('?').setQuoteMode(QuoteMode.NONE).get(); - final StringWriter sw = new StringWriter(); - try (CSVPrinter printer = new CSVPrinter(sw, format)) { - printer.printRecord("\"abc", "x\"y"); - printer.printRecord(new StringReader("\"abc"), new StringReader("x\"y")); - } - assertEquals("?\"abc,x?\"y" + RECORD_SEPARATOR + "?\"abc,x?\"y" + RECORD_SEPARATOR, sw.toString()); - // The emitted records must read back as the original values. - try (CSVParser parser = CSVParser.parse(sw.toString(), format)) { - final List<CSVRecord> records = parser.getRecords(); - assertEquals(2, records.size()); - for (final CSVRecord record : records) { - assertEquals("\"abc", record.get(0)); - assertEquals("x\"y", record.get(1)); - } - } - } - @Test void testDelimiterEscaped() throws IOException { final StringWriter sw = new StringWriter(); @@ -1818,6 +1798,26 @@ class CSVPrinterTest { } } + @Test + void testQuoteCharEscapedWithQuoteModeNone() throws IOException { + final CSVFormat format = CSVFormat.DEFAULT.builder().setQuote('"').setEscape('?').setQuoteMode(QuoteMode.NONE).get(); + final StringWriter sw = new StringWriter(); + try (CSVPrinter printer = new CSVPrinter(sw, format)) { + printer.printRecord("\"abc", "x\"y"); + printer.printRecord(new StringReader("\"abc"), new StringReader("x\"y")); + } + assertEquals("?\"abc,x?\"y" + RECORD_SEPARATOR + "?\"abc,x?\"y" + RECORD_SEPARATOR, sw.toString()); + // The emitted records must read back as the original values. + try (CSVParser parser = CSVParser.parse(sw.toString(), format)) { + final List<CSVRecord> records = parser.getRecords(); + assertEquals(2, records.size()); + for (final CSVRecord record : records) { + assertEquals("\"abc", record.get(0)); + assertEquals("x\"y", record.get(1)); + } + } + } + @Test void testQuoteCommaFirstChar() throws IOException { final StringWriter sw = new StringWriter(); diff --git a/src/test/java/org/apache/commons/csv/LexerTest.java b/src/test/java/org/apache/commons/csv/LexerTest.java index da60df07..244079df 100644 --- a/src/test/java/org/apache/commons/csv/LexerTest.java +++ b/src/test/java/org/apache/commons/csv/LexerTest.java @@ -409,18 +409,6 @@ class LexerTest { } } - /** - * Tests <a href="https://issues.apache.org/jira/browse/CSV-324">CSV-324</a>. - */ - @Test - void testPartialMultiCharacterDelimiterAtEOF() throws IOException { - final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").get(); - try (Lexer lexer = createLexer("a[|]b[|", format)) { - assertNextToken(TOKEN, "a", lexer); - assertNextToken(EOF, "b[|", lexer); - } - } - /** * A truncated escaped multi-character delimiter at EOF must not be accepted by reusing the previous escape delimiter * look-ahead in {@link Lexer#isEscapeDelimiter()}. @@ -433,6 +421,18 @@ class LexerTest { } } + /** + * Tests <a href="https://issues.apache.org/jira/browse/CSV-324">CSV-324</a>. + */ + @Test + void testPartialMultiCharacterDelimiterAtEOF() throws IOException { + final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").get(); + try (Lexer lexer = createLexer("a[|]b[|", format)) { + assertNextToken(TOKEN, "a", lexer); + assertNextToken(EOF, "b[|", lexer); + } + } + @Test void testReadEscapeBackspace() throws IOException { try (Lexer lexer = createLexer("b", CSVFormat.DEFAULT.withEscape('\b'))) {
