improve CSVFormat test coverage (#63)

* improve CSVFormat test coverage

* remove print in test
This commit is contained in:
Chen 2020-03-23 23:09:09 +08:00 committed by GitHub
parent c2f46df203
commit 83d6f8117a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 deletions

View File

@ -36,6 +36,9 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Reader;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
@ -1175,4 +1178,31 @@ public class CSVFormatTest {
assertEquals(System.getProperty("line.separator"), formatWithRecordSeparator.getRecordSeparator());
}
@Test
public void testPrintWithEscapesEndWithCRLF() throws IOException {
final Reader in = new StringReader("x,y,x\r\na,?b,c\r\n");
final Appendable out = new StringBuilder();
final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF);
format.print(in,out,true);
assertEquals("x?,y?,x?r?na?,??b?,c?r?n", out.toString());
}
@Test
public void testPrintWithEscapesEndWithoutCRLF() throws IOException {
final Reader in = new StringReader("x,y,x");
final Appendable out = new StringBuilder();
final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF);
format.print(in,out,true);
assertEquals("x?,y?,x", out.toString());
}
@Test
public void testFormatToString() throws IOException {
final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',')
.withQuoteMode(QuoteMode.MINIMAL).withRecordSeparator(CRLF).withQuote('"')
.withNullString("").withIgnoreHeaderCase(true)
.withHeaderComments("This is HeaderComments").withHeader("col1","col2","col3");
assertEquals("Delimiter=<,> Escape=<?> QuoteChar=<\"> QuoteMode=<MINIMAL> NullString=<> RecordSeparator=<" +CRLF+
"> IgnoreHeaderCase:ignored SkipHeaderRecord:false HeaderComments:[This is HeaderComments] Header:[col1, col2, col3]", format.toString());
}
}