Sort members.

This commit is contained in:
Gary Gregory 2019-09-04 10:32:51 -04:00
parent f62fd132d0
commit 1a7c614082
1 changed files with 65 additions and 65 deletions

View File

@ -287,6 +287,19 @@ public class CSVPrinterTest {
} }
} }
@Test
public void testCSV135() throws IOException {
List<String> l = new LinkedList<String>();
l.add("\"\""); // ""
l.add("\\\\"); // \\
l.add("\\\"\\"); // \"\
tryFormat(l, null, null, "\"\",\\\\,\\\"\\"); // "",\\,\"\ (unchanged)
tryFormat(l, '"', null, "\"\"\"\"\"\",\\\\,\"\\\"\"\\\""); // """""",\\,"\""\" (quoted, and embedded DQ doubled)
tryFormat(l, null, '\\', "\"\",\\\\\\\\,\\\\\"\\\\"); // "",\\\\,\\"\\ (escapes escaped, not quoted)
tryFormat(l, '"', '\\', "\"\\\"\\\"\",\"\\\\\\\\\",\"\\\\\\\"\\\\\""); // "\"\"","\\\\","\\\"\\" (quoted, and embedded DQ & escape escaped)
tryFormat(l, '"', '"', "\"\"\"\"\"\",\\\\,\"\\\"\"\\\""); // """""",\\,"\""\" (quoted, embedded DQ escaped)
}
@Test @Test
public void testDelimeterQuoted() throws IOException { public void testDelimeterQuoted() throws IOException {
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
@ -721,6 +734,15 @@ public class CSVPrinterTest {
} }
} }
@Test
public void testMongoDbTsvBasic() throws IOException {
final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.MONGODB_TSV)) {
printer.printRecord("a", "b");
assertEquals("a\tb" + recordSeparator, sw.toString());
}
}
@Test @Test
public void testMongoDbTsvCommaInValue() throws IOException { public void testMongoDbTsvCommaInValue() throws IOException {
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
@ -739,15 +761,6 @@ public class CSVPrinterTest {
} }
} }
@Test
public void testMongoDbTsvBasic() throws IOException {
final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.MONGODB_TSV)) {
printer.printRecord("a", "b");
assertEquals("a\tb" + recordSeparator, sw.toString());
}
}
@Test @Test
public void testMultiLineComment() throws IOException { public void testMultiLineComment() throws IOException {
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
@ -1243,6 +1256,48 @@ public class CSVPrinterTest {
} }
} }
/**
* Test to target the use of {@link IOUtils#copy(java.io.Reader, Appendable)} which directly
* buffers the value from the Reader to the Appendable.
*
* <p>Requires the format to have no quote or escape character, value to be a
* {@link java.io.Reader Reader} and the output <i>MUST NOT</i> be a
* {@link java.io.Writer Writer} but some other Appendable.</p>
*
* @throws IOException Not expected to happen
*/
@Test
public void testPrintReaderWithoutQuoteToAppendable() throws IOException {
final StringBuilder sb = new StringBuilder();
final String content = "testValue";
try (final CSVPrinter printer = new CSVPrinter(sb, CSVFormat.DEFAULT.withQuote(null))) {
final StringReader value = new StringReader(content);
printer.print(value);
}
assertEquals(content, sb.toString());
}
/**
* Test to target the use of {@link IOUtils#copyLarge(java.io.Reader, Writer)} which directly
* buffers the value from the Reader to the Writer.
*
* <p>Requires the format to have no quote or escape character, value to be a
* {@link java.io.Reader Reader} and the output <i>MUST</i> be a
* {@link java.io.Writer Writer}.</p>
*
* @throws IOException Not expected to happen
*/
@Test
public void testPrintReaderWithoutQuoteToWriter() throws IOException {
final StringWriter sw = new StringWriter();
final String content = "testValue";
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null))) {
final StringReader value = new StringReader(content);
printer.print(value);
}
assertEquals(content, sw.toString());
}
@Test @Test
public void testPrintRecordsWithEmptyVector() throws IOException { public void testPrintRecordsWithEmptyVector() throws IOException {
final PrintStream out = System.out; final PrintStream out = System.out;
@ -1386,6 +1441,7 @@ public class CSVPrinterTest {
doRandom(CSVFormat.TDF, ITERATIONS_FOR_RANDOM_TEST); doRandom(CSVFormat.TDF, ITERATIONS_FOR_RANDOM_TEST);
} }
@Test @Test
public void testSingleLineComment() throws IOException { public void testSingleLineComment() throws IOException {
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
@ -1417,7 +1473,6 @@ public class CSVPrinterTest {
} }
} }
@Test @Test
public void testSkipHeaderRecordTrue() throws IOException { public void testSkipHeaderRecordTrue() throws IOException {
// functionally identical to testHeaderNotSet, used to test CSV-153 // functionally identical to testHeaderNotSet, used to test CSV-153
@ -1471,48 +1526,6 @@ public class CSVPrinterTest {
return CSVParser.parse(expected, format).getRecords().get(0).values(); return CSVParser.parse(expected, format).getRecords().get(0).values();
} }
/**
* Test to target the use of {@link IOUtils#copyLarge(java.io.Reader, Writer)} which directly
* buffers the value from the Reader to the Writer.
*
* <p>Requires the format to have no quote or escape character, value to be a
* {@link java.io.Reader Reader} and the output <i>MUST</i> be a
* {@link java.io.Writer Writer}.</p>
*
* @throws IOException Not expected to happen
*/
@Test
public void testPrintReaderWithoutQuoteToWriter() throws IOException {
final StringWriter sw = new StringWriter();
final String content = "testValue";
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null))) {
final StringReader value = new StringReader(content);
printer.print(value);
}
assertEquals(content, sw.toString());
}
/**
* Test to target the use of {@link IOUtils#copy(java.io.Reader, Appendable)} which directly
* buffers the value from the Reader to the Appendable.
*
* <p>Requires the format to have no quote or escape character, value to be a
* {@link java.io.Reader Reader} and the output <i>MUST NOT</i> be a
* {@link java.io.Writer Writer} but some other Appendable.</p>
*
* @throws IOException Not expected to happen
*/
@Test
public void testPrintReaderWithoutQuoteToAppendable() throws IOException {
final StringBuilder sb = new StringBuilder();
final String content = "testValue";
try (final CSVPrinter printer = new CSVPrinter(sb, CSVFormat.DEFAULT.withQuote(null))) {
final StringReader value = new StringReader(content);
printer.print(value);
}
assertEquals(content, sb.toString());
}
private void tryFormat(List<String> l, Character quote, Character escape, String expected) throws IOException { private void tryFormat(List<String> l, Character quote, Character escape, String expected) throws IOException {
CSVFormat format = CSVFormat.DEFAULT.withQuote(quote).withEscape(escape).withRecordSeparator(null); CSVFormat format = CSVFormat.DEFAULT.withQuote(quote).withEscape(escape).withRecordSeparator(null);
Appendable out = new StringBuilder(); Appendable out = new StringBuilder();
@ -1521,17 +1534,4 @@ public class CSVPrinterTest {
printer.close(); printer.close();
assertEquals(expected, out.toString()); assertEquals(expected, out.toString());
} }
@Test
public void testCSV135() throws IOException {
List<String> l = new LinkedList<String>();
l.add("\"\""); // ""
l.add("\\\\"); // \\
l.add("\\\"\\"); // \"\
tryFormat(l, null, null, "\"\",\\\\,\\\"\\"); // "",\\,\"\ (unchanged)
tryFormat(l, '"', null, "\"\"\"\"\"\",\\\\,\"\\\"\"\\\""); // """""",\\,"\""\" (quoted, and embedded DQ doubled)
tryFormat(l, null, '\\', "\"\",\\\\\\\\,\\\\\"\\\\"); // "",\\\\,\\"\\ (escapes escaped, not quoted)
tryFormat(l, '"', '\\', "\"\\\"\\\"\",\"\\\\\\\\\",\"\\\\\\\"\\\\\""); // "\"\"","\\\\","\\\"\\" (quoted, and embedded DQ & escape escaped)
tryFormat(l, '"', '"', "\"\"\"\"\"\",\\\\,\"\\\"\"\\\""); // """""",\\,"\""\" (quoted, embedded DQ escaped)
}
} }