commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1460364 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
Date Sun, 24 Mar 2013 13:29:23 GMT
Author: britter
Date: Sun Mar 24 13:29:22 2013
New Revision: 1460364

URL: http://svn.apache.org/r1460364
Log:
Split up escape testing into separate methods, add escaping tests that should work after CSV-58
is resolved (currently ignored)

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=1460364&r1=1460363&r2=1460364&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 Sun Mar
24 13:29:22 2013
@@ -34,6 +34,7 @@ import static org.junit.Assert.fail;
 import java.io.IOException;
 import java.io.StringReader;
 
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -289,20 +290,56 @@ public class CSVLexerTest {
     }
 
     @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()));
+    public void testEscapedCR() throws Exception {
+        final Lexer lexer = getLexer("character\\" + CR + "Escaped", CSVFormat.newBuilder().withEscape('\\').build());
+        assertTokenEquals(EOF, "character" + CR + "Escaped", lexer.nextToken(new Token()));
+    }
+
+    @Test
+    public void testEscapedLF() throws Exception {
+        final Lexer lexer = getLexer("character\\" + LF + "Escaped", CSVFormat.newBuilder().withEscape('\\').build());
+        assertTokenEquals(EOF, "character" + LF + "Escaped", lexer.nextToken(new Token()));
+    }
+
+    @Test
+    public void testEscapedTab() throws Exception {
+        final Lexer lexer = getLexer("character\\" + TAB + "Escaped", CSVFormat.newBuilder().withEscape('\\').build());
+        assertTokenEquals(EOF, "character" + TAB + "Escaped", lexer.nextToken(new Token()));
+    }
+
+    @Test
+    public void testEscapeBackspace() throws Exception {
+        final Lexer lexer = getLexer("character\\" + BACKSPACE + "Escaped", CSVFormat.newBuilder().withEscape('\\').build());
+        assertTokenEquals(EOF, "character" + BACKSPACE + "Escaped", lexer.nextToken(new Token()));
+    }
+
+    @Test
+    public void testEscapeFF() throws Exception {
+        final Lexer lexer = getLexer("character\\" + FF + "Escaped", CSVFormat.newBuilder().withEscape('\\').build());
+        assertTokenEquals(EOF, "character" + FF + "Escaped", lexer.nextToken(new Token()));
+    }
+
+    @Test
+    public void testEscapedMySqlNullValue() throws Exception {
+        // MySQL uses \N to symbolize null values. We have to restore this
+        final Lexer lexer = getLexer("character\\\\NEscaped", CSVFormat.newBuilder().withEscape('\\').build());
+        assertTokenEquals(EOF, "character\\NEscaped", lexer.nextToken(new Token()));
+    }
+
+    // FIXME this should work after CSV-58 is resolved. Currently the result will be "characteraEscaped"
+    @Test
+    @Ignore
+    public void testEscapedCharacter() throws Exception {
+        final Lexer lexer = getLexer("character\\aEscaped", CSVFormat.newBuilder().withEscape('\\').build());
+        assertTokenEquals(EOF, "character\\aEscaped", lexer.nextToken(new Token()));
+    }
+
+    // FIXME this should work after CSV-58 is resolved. Currentyl the result will be "characterCREscaped"
+    @Test
+    @Ignore
+    public void testEscapedControlCharacter() throws Exception {
+        final Lexer lexer = getLexer("character!rEscaped", CSVFormat.newBuilder().withEscape('!').build());
+        assertTokenEquals(EOF, "character!rEscaped", lexer.nextToken(new Token()));
     }
 
     @Test(expected = IOException.class)



Mime
View raw message