Skip to content

Commit a381d53

Browse files
author
Ranjith Rp
committed
adding junits to show how ignoreQuoteInToken is used
1 parent ad01ee1 commit a381d53

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,12 @@ public void testWithIgnoreEmptyLines() throws Exception {
10511051
assertFalse(CSVFormat.DEFAULT.withIgnoreEmptyLines(false).getIgnoreEmptyLines());
10521052
assertTrue(CSVFormat.DEFAULT.withIgnoreEmptyLines().getIgnoreEmptyLines());
10531053
}
1054+
1055+
@Test
1056+
public void testWithIgnoreQuotesInToken() throws Exception {
1057+
assertFalse(CSVFormat.DEFAULT.withIgnoreQuotesInToken(false).getIgnoreQuotesInToken());
1058+
assertTrue(CSVFormat.DEFAULT.withIgnoreQuotesInToken().getIgnoreQuotesInToken());
1059+
}
10541060

10551061

10561062
@Test

src/test/java/org/apache/commons/csv/LexerTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@
3131
import static org.junit.Assert.assertFalse;
3232
import static org.junit.Assert.assertThat;
3333
import static org.junit.Assert.assertTrue;
34+
import static org.junit.Assert.fail;
3435

3536
import java.io.IOException;
3637
import java.io.StringReader;
3738

39+
import org.junit.Assert;
3840
import org.junit.Before;
3941
import org.junit.Test;
42+
import org.junit.internal.runners.statements.Fail;
4043

4144
/**
4245
*
@@ -68,6 +71,30 @@ public void testSurroundingSpacesAreDeleted() throws IOException {
6871
assertThat(parser.nextToken(new Token()), matches(EOF, ""));
6972
}
7073
}
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+
}
7198

7299
@Test
73100
public void testSurroundingTabsAreDeleted() throws IOException {

0 commit comments

Comments
 (0)