commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1460138 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
Date Sat, 23 Mar 2013 13:07:05 GMT
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());
+    }
 }



Mime
View raw message