@@ -147,28 +147,66 @@ public void testNextToken2EmptyLines() throws IOException {
147147
148148 }
149149
150- // simple token with escaping
150+ // simple token with escaping not enabled
151151 @ Test
152152 public void testNextToken3 () throws IOException {
153153 /* file: a,\,,b
154154 * \,,
155155 */
156- String code = "a,\\ ,,b\n \\ ,," ;
157- CSVFormat format = CSVFormat .DEFAULT .withCommentStart ('#' );
156+ String code = "a,\\ ,,b\\ \n \\ ,," ;
157+ CSVFormat format = CSVFormat .DEFAULT ;
158+ assertFalse (format .isEscaping ());
158159 Lexer parser = getLexer (code , format );
159160
160161 assertTokenEquals (TOKEN , "a" , parser .nextToken (new Token ()));
161162 // an unquoted single backslash is not an escape char
162163 assertTokenEquals (TOKEN , "\\ " , parser .nextToken (new Token ()));
163164 assertTokenEquals (TOKEN , "" , parser .nextToken (new Token ()));
164- assertTokenEquals (EORECORD , "b" , parser .nextToken (new Token ()));
165+ assertTokenEquals (EORECORD , "b\\ " , parser .nextToken (new Token ()));
165166 // an unquoted single backslash is not an escape char
166167 assertTokenEquals (TOKEN , "\\ " , parser .nextToken (new Token ()));
167168 assertTokenEquals (TOKEN , "" , parser .nextToken (new Token ()));
168169 assertTokenEquals (EOF , "" , parser .nextToken (new Token ()));
169170 }
170171
171- // encapsulator tokenizer (sinle line)
172+ // simple token with escaping enabled
173+ @ Test
174+ public void testNextToken3Escaping () throws IOException {
175+ /* file: a,\,,b
176+ * \,,
177+ */
178+ String code = "a,\\ ,,b\\ \\ \n \\ ,,\\ \n c,d\\ \n " ;
179+ CSVFormat format = CSVFormat .DEFAULT .withEscape ('\\' );
180+ assertTrue (format .isEscaping ());
181+ Lexer parser = getLexer (code , format );
182+
183+ assertTokenEquals (TOKEN , "a" , parser .nextToken (new Token ()));
184+ assertTokenEquals (TOKEN , "," , parser .nextToken (new Token ()));
185+ assertTokenEquals (EORECORD , "b\\ " , parser .nextToken (new Token ()));
186+ assertTokenEquals (TOKEN , "," , parser .nextToken (new Token ()));
187+ assertTokenEquals (TOKEN , "\n c" , parser .nextToken (new Token ()));
188+ assertTokenEquals (EOF , "d\n " , parser .nextToken (new Token ()));
189+ assertTokenEquals (EOF , "" , parser .nextToken (new Token ()));
190+ }
191+
192+ // simple token with escaping enabled
193+ @ Test
194+ public void testNextToken3BadEscaping () throws IOException {
195+ String code = "a,b,c\\ " ;
196+ CSVFormat format = CSVFormat .DEFAULT .withEscape ('\\' );
197+ assertTrue (format .isEscaping ());
198+ Lexer parser = getLexer (code , format );
199+
200+ assertTokenEquals (TOKEN , "a" , parser .nextToken (new Token ()));
201+ assertTokenEquals (TOKEN , "b" , parser .nextToken (new Token ()));
202+ try {
203+ Token tkn = parser .nextToken (new Token ());
204+ fail ("Expected IOE, found " +tkn );
205+ } catch (IOException e ) {
206+ }
207+ }
208+
209+ // encapsulator tokenizer (single line)
172210 @ Test
173211 public void testNextToken4 () throws IOException {
174212 /* file: a,"foo",b
0 commit comments