commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1306651 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
Date Thu, 29 Mar 2012 00:05:46 GMT
Author: sebb
Date: Thu Mar 29 00:05:45 2012
New Revision: 1306651

URL: http://svn.apache.org/viewvc?rev=1306651&view=rev
Log:
Test with empty lines

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=1306651&r1=1306650&r2=1306651&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 Thu Mar
29 00:05:45 2012
@@ -89,6 +89,42 @@ public class CSVLexerTest {
 
     }
 
+    // multiline including comments (and empty lines)
+    @Test
+    public void testNextToken2EmptyLines() throws IOException {
+        final String code = 
+                "1,2,3,\n"+                // 1
+                "a,b x,c#no-comment\n"+    // 2
+                "#foo\n"+                  // 3
+                "\n"+                      // 4
+                "d,e,#no-comment\n"+       // 5
+                "# penultimate comment\n"+ // 6
+                "# Final comment\n";       // 7
+        CSVFormat format = CSVFormat.DEFAULT.withCommentStart('#').withEmptyLinesIgnored(false);
+        assertFalse("Should not ignore empty lines", format.isEmptyLinesIgnored());
+        
+        Lexer parser = getLexer(code, format);
+
+
+        assertTokenEquals(TOKEN, "1", parser.nextToken(new Token()));
+        assertTokenEquals(TOKEN, "2", parser.nextToken(new Token()));
+        assertTokenEquals(TOKEN, "3", parser.nextToken(new Token()));
+        assertTokenEquals(EORECORD, "", parser.nextToken(new Token()));             // 1
+        assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
+        assertTokenEquals(TOKEN, "b x", parser.nextToken(new Token()));
+        assertTokenEquals(EORECORD, "c#no-comment", parser.nextToken(new Token())); // 2
+        assertTokenEquals(COMMENT, "", parser.nextToken(new Token()));              // 3
+        assertTokenEquals(EORECORD, "", parser.nextToken(new Token()));             // 4
+        assertTokenEquals(TOKEN, "d", parser.nextToken(new Token()));
+        assertTokenEquals(TOKEN, "e", parser.nextToken(new Token()));
+        assertTokenEquals(EORECORD, "#no-comment", parser.nextToken(new Token()));  // 5
+        assertTokenEquals(COMMENT, "", parser.nextToken(new Token()));              // 6
+        assertTokenEquals(COMMENT, "", parser.nextToken(new Token()));              // 7
+        assertTokenEquals(EOF, "", parser.nextToken(new Token()));
+        assertTokenEquals(EOF, "", parser.nextToken(new Token()));
+
+    }
+
     // simple token with escaping
     @Test
     public void testNextToken3() throws IOException {



Mime
View raw message