Add some unit tests for escape handling in preparation for CSV-58
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1460138 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c4014b6b38
commit
2e543f41f3
|
@ -17,6 +17,11 @@
|
|||
|
||||
package org.apache.commons.csv;
|
||||
|
||||
import static org.apache.commons.csv.Constants.BACKSPACE;
|
||||
import static org.apache.commons.csv.Constants.CR;
|
||||
import static org.apache.commons.csv.Constants.FF;
|
||||
import static org.apache.commons.csv.Constants.LF;
|
||||
import static org.apache.commons.csv.Constants.TAB;
|
||||
import static org.apache.commons.csv.Token.Type.COMMENT;
|
||||
import static org.apache.commons.csv.Token.Type.EOF;
|
||||
import static org.apache.commons.csv.Token.Type.EORECORD;
|
||||
|
@ -282,4 +287,29 @@ public class CSVLexerTest {
|
|||
assertTokenEquals(TOKEN, "five", parser.nextToken(new Token()));
|
||||
assertTokenEquals(EOF, "six", parser.nextToken(new Token()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscaping() throws Exception {
|
||||
final String code = "plain," +
|
||||
"CR!" + CR + "Escaped," +
|
||||
"LF!" + LF +"Escaped," +
|
||||
"TAB!" + TAB +"Escaped," +
|
||||
"BACKSPACE!" + BACKSPACE +"Escaped," +
|
||||
"FF!" + FF +"Escaped";
|
||||
final Lexer lexer = getLexer(code, CSVFormat.newBuilder().withEscape('!').build());
|
||||
assertTokenEquals(TOKEN, "plain", lexer.nextToken(new Token()));
|
||||
assertTokenEquals(TOKEN, "CR" + CR + "Escaped", lexer.nextToken(new Token()));
|
||||
assertTokenEquals(TOKEN, "LF" + LF + "Escaped", lexer.nextToken(new Token()));
|
||||
assertTokenEquals(TOKEN, "TAB" + TAB + "Escaped", lexer.nextToken(new Token()));
|
||||
assertTokenEquals(TOKEN, "BACKSPACE" + BACKSPACE + "Escaped", lexer.nextToken(new Token()));
|
||||
assertTokenEquals(EOF, "FF" + FF + "Escaped", lexer.nextToken(new Token()));
|
||||
}
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void testEscapingAtEOF() throws Exception {
|
||||
final String code = "escaping at EOF is evil!";
|
||||
final Lexer lexer = getLexer(code, CSVFormat.newBuilder().withEscape('!').build());
|
||||
|
||||
lexer.nextToken(new Token());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue