@@ -89,6 +89,42 @@ public void testNextToken2() throws IOException {
8989
9090 }
9191
92+ // multiline including comments (and empty lines)
93+ @ Test
94+ public void testNextToken2EmptyLines () throws IOException {
95+ final String code =
96+ "1,2,3,\n " + // 1
97+ "a,b x,c#no-comment\n " + // 2
98+ "#foo\n " + // 3
99+ "\n " + // 4
100+ "d,e,#no-comment\n " + // 5
101+ "# penultimate comment\n " + // 6
102+ "# Final comment\n " ; // 7
103+ CSVFormat format = CSVFormat .DEFAULT .withCommentStart ('#' ).withEmptyLinesIgnored (false );
104+ assertFalse ("Should not ignore empty lines" , format .isEmptyLinesIgnored ());
105+
106+ Lexer parser = getLexer (code , format );
107+
108+
109+ assertTokenEquals (TOKEN , "1" , parser .nextToken (new Token ()));
110+ assertTokenEquals (TOKEN , "2" , parser .nextToken (new Token ()));
111+ assertTokenEquals (TOKEN , "3" , parser .nextToken (new Token ()));
112+ assertTokenEquals (EORECORD , "" , parser .nextToken (new Token ())); // 1
113+ assertTokenEquals (TOKEN , "a" , parser .nextToken (new Token ()));
114+ assertTokenEquals (TOKEN , "b x" , parser .nextToken (new Token ()));
115+ assertTokenEquals (EORECORD , "c#no-comment" , parser .nextToken (new Token ())); // 2
116+ assertTokenEquals (COMMENT , "" , parser .nextToken (new Token ())); // 3
117+ assertTokenEquals (EORECORD , "" , parser .nextToken (new Token ())); // 4
118+ assertTokenEquals (TOKEN , "d" , parser .nextToken (new Token ()));
119+ assertTokenEquals (TOKEN , "e" , parser .nextToken (new Token ()));
120+ assertTokenEquals (EORECORD , "#no-comment" , parser .nextToken (new Token ())); // 5
121+ assertTokenEquals (COMMENT , "" , parser .nextToken (new Token ())); // 6
122+ assertTokenEquals (COMMENT , "" , parser .nextToken (new Token ())); // 7
123+ assertTokenEquals (EOF , "" , parser .nextToken (new Token ()));
124+ assertTokenEquals (EOF , "" , parser .nextToken (new Token ()));
125+
126+ }
127+
92128 // simple token with escaping
93129 @ Test
94130 public void testNextToken3 () throws IOException {
0 commit comments