You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2013/03/23 14:07:05 UTC
svn commit: r1460138 -
/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
Author: britter
Date: Sat Mar 23 13:07:04 2013
New Revision: 1460138
URL: http://svn.apache.org/r1460138
Log:
Add some unit tests for escape handling in preparation for CSV-58
Modified:
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java?rev=1460138&r1=1460137&r2=1460138&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java Sat Mar 23 13:07:04 2013
@@ -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());
+ }
}