Add some more tests

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1479730 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2013-05-06 23:54:45 +00:00
parent 02c1b35939
commit 0fabee5f24
1 changed files with 69 additions and 0 deletions

View File

@ -342,6 +342,15 @@ public class CSVPrinterTest {
doRandom(CSVFormat.MYSQL, iter);
}
@Test
public void testPlainQuoted() throws IOException {
final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar('\'').build());
printer.print("abc");
assertEquals("abc", sw.toString());
printer.close();
}
@Test
public void testSingleLineComment() throws IOException {
final StringWriter sw = new StringWriter();
@ -352,4 +361,64 @@ public class CSVPrinterTest {
printer.close();
}
@Test
public void testSingleQuoteQuoted() throws IOException {
final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar('\'').build());
printer.print("a'b'c");
printer.print("xyz");
assertEquals("'a''b''c',xyz", sw.toString());
printer.close();
}
@Test
public void testDelimeterQuoted() throws IOException {
final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar('\'').build());
printer.print("a,b,c");
printer.print("xyz");
assertEquals("'a,b,c',xyz", sw.toString());
printer.close();
}
@Test
public void testPlainEscaped() throws IOException {
final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar(null).withEscape('!').build());
printer.print("abc");
printer.print("xyz");
assertEquals("abc,xyz", sw.toString());
printer.close();
}
@Test
public void testDelimiterEscaped() throws IOException {
final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar(null).withEscape('!').build());
printer.print("a,b,c");
printer.print("xyz");
assertEquals("a!,b!,c,xyz", sw.toString());
printer.close();
}
@Test
public void testPlainPlain() throws IOException {
final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar(null).build());
printer.print("abc");
printer.print("xyz");
assertEquals("abc,xyz", sw.toString());
printer.close();
}
@Test
public void testDelimiterPlain() throws IOException {
final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuoteChar(null).build());
printer.print("a,b,c");
printer.print("xyz");
assertEquals("a,b,c,xyz", sw.toString());
printer.close();
}
}