|
31 | 31 | import static org.junit.Assert.assertFalse; |
32 | 32 | import static org.junit.Assert.assertThat; |
33 | 33 | import static org.junit.Assert.assertTrue; |
| 34 | +import static org.junit.Assert.fail; |
34 | 35 |
|
35 | 36 | import java.io.IOException; |
36 | 37 | import java.io.StringReader; |
37 | 38 |
|
| 39 | +import org.junit.Assert; |
38 | 40 | import org.junit.Before; |
39 | 41 | import org.junit.Test; |
| 42 | +import org.junit.internal.runners.statements.Fail; |
40 | 43 |
|
41 | 44 | /** |
42 | 45 | * |
@@ -68,6 +71,30 @@ public void testSurroundingSpacesAreDeleted() throws IOException { |
68 | 71 | assertThat(parser.nextToken(new Token()), matches(EOF, "")); |
69 | 72 | } |
70 | 73 | } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testIgnoreQuotesInTokenTrue() throws IOException { |
| 77 | + final String code = "abc,\"xyz\" 123 bar,3,11961034,\"First author, Second Author\""; |
| 78 | + try (final Lexer parser = createLexer(code, CSVFormat.DEFAULT.withIgnoreQuotesInToken())) { |
| 79 | + assertThat(parser.nextToken(new Token()), matches(TOKEN, "abc")); |
| 80 | + assertThat(parser.nextToken(new Token()), matches(TOKEN, "xyz 123 bar")); |
| 81 | + assertThat(parser.nextToken(new Token()), matches(TOKEN, "3")); |
| 82 | + assertThat(parser.nextToken(new Token()), matches(TOKEN, "11961034")); |
| 83 | + assertThat(parser.nextToken(new Token()), matches(EOF, "First author, Second Author")); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + public void testIgnoreQuotesInTokenFalse() throws IOException { |
| 89 | + final String code = "abc,\"xyz\" 123 bar,3,11961034,\"First author, Second Author\""; |
| 90 | + try (final Lexer parser = createLexer(code, CSVFormat.DEFAULT)) { |
| 91 | + assertThat(parser.nextToken(new Token()), matches(TOKEN, "abc")); |
| 92 | + assertThat(parser.nextToken(new Token()), matches(TOKEN, "xyz 123 bar")); |
| 93 | + fail(); |
| 94 | + } catch (IOException e) { |
| 95 | + assertTrue(e.getMessage().equals("(line 1) invalid char between encapsulated token and delimiter")); |
| 96 | + } |
| 97 | + } |
71 | 98 |
|
72 | 99 | @Test |
73 | 100 | public void testSurroundingTabsAreDeleted() throws IOException { |
|
0 commit comments