commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r1305689 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
Date Tue, 27 Mar 2012 00:20:21 GMT
Author: ebourg
Date: Tue Mar 27 00:20:21 2012
New Revision: 1305689

URL: http://svn.apache.org/viewvc?rev=1305689&view=rev
Log:
Added tests for line counting by the parser (CSV-75)

Modified:
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java?rev=1305689&r1=1305688&r2=1305689&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java Tue Mar
27 00:20:21 2012
@@ -472,4 +472,47 @@ public class CSVParserTest {
 
         assertFalse(records.hasNext());
     }
+
+    @Test
+    public void testGetLineNumberWithLF() throws Exception {
+        CSVParser parser = new CSVParser("a\nb\nc", CSVFormat.DEFAULT.withLineSeparator("\n"));
+        
+        assertEquals(0, parser.getLineNumber());
+        assertNotNull(parser.getRecord());
+        assertEquals(1, parser.getLineNumber());
+        assertNotNull(parser.getRecord());
+        assertEquals(2, parser.getLineNumber());
+        assertNotNull(parser.getRecord());
+        assertEquals(2, parser.getLineNumber());
+        assertNull(parser.getRecord());
+    }
+
+    @Test
+    public void testGetLineNumberWithCRLF() throws Exception {
+        CSVParser parser = new CSVParser("a\r\nb\r\nc", CSVFormat.DEFAULT.withLineSeparator("\r\n"));
+        
+        assertEquals(0, parser.getLineNumber());
+        assertNotNull(parser.getRecord());
+        assertEquals(1, parser.getLineNumber());
+        assertNotNull(parser.getRecord());
+        assertEquals(2, parser.getLineNumber());
+        assertNotNull(parser.getRecord());
+        assertEquals(2, parser.getLineNumber());
+        assertNull(parser.getRecord());
+    }
+
+    @Test
+    @Ignore("Line counting doesn't work with CR alone as the line separator, see CSV-75")
+    public void testGetLineNumberWithCR() throws Exception {
+        CSVParser parser = new CSVParser("a\rb\rc", CSVFormat.DEFAULT.withLineSeparator("\r"));
+        
+        assertEquals(0, parser.getLineNumber());
+        assertNotNull(parser.getRecord());
+        assertEquals(1, parser.getLineNumber());
+        assertNotNull(parser.getRecord());
+        assertEquals(2, parser.getLineNumber());
+        assertNotNull(parser.getRecord());
+        assertEquals(2, parser.getLineNumber());
+        assertNull(parser.getRecord());
+    }
 }



Mime
View raw message