You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/03/29 02:02:35 UTC
svn commit: r1306649 - in /commons/proper/csv/trunk/src:
main/java/org/apache/commons/csv/ExtendedBufferedReader.java
test/java/org/apache/commons/csv/CSVLexerTest.java
Author: sebb
Date: Thu Mar 29 00:02:35 2012
New Revision: 1306649
URL: http://svn.apache.org/viewvc?rev=1306649&view=rev
Log:
Fix readLine() so can still detect start of line next time round
Also fix broken test: format was set to ignore empty lines, yet it checked for one
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java?rev=1306649&r1=1306648&r2=1306649&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java Thu Mar 29 00:02:35 2012
@@ -123,9 +123,7 @@ class ExtendedBufferedReader extends Buf
String line = super.readLine();
if (line != null) {
- if (line.length() > 0) {
- lastChar = line.charAt(line.length() - 1);
- }
+ lastChar = '\n'; // needed for detecting start of line
lineCounter++;
} else {
lastChar = END_OF_STREAM;
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=1306649&r1=1306648&r2=1306649&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:02:35 2012
@@ -57,13 +57,15 @@ public class CSVLexerTest {
@Test
public void testNextToken2() throws IOException {
final String code =
- "1,2,3,\n"+
- "a,b x,c#no-comment\n"+
- "#foo\n"+
- "\n"+
- "d,e,#no-comment\n"+
- "# Final comment\n";
+ "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('#');
+ assertTrue("Should ignore empty lines", format.isEmptyLinesIgnored());
Lexer parser = getLexer(code, format);
@@ -71,16 +73,17 @@ public class CSVLexerTest {
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()));
+ 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()));
- assertTokenEquals(COMMENT, "", parser.nextToken(new Token()));
- assertTokenEquals(EORECORD, "", parser.nextToken(new Token()));
+ assertTokenEquals(EORECORD, "c#no-comment", parser.nextToken(new Token())); // 2
+ assertTokenEquals(COMMENT, "", parser.nextToken(new Token())); // 3
+ // 4 empty line, ignored // 4
assertTokenEquals(TOKEN, "d", parser.nextToken(new Token()));
assertTokenEquals(TOKEN, "e", parser.nextToken(new Token()));
- assertTokenEquals(EORECORD, "#no-comment", parser.nextToken(new Token()));
- assertTokenEquals(COMMENT, "", 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()));