-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4eff590
commit 32437c0
Showing
8 changed files
with
235 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/SkipBlankLines15Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package com.fasterxml.jackson.dataformat.csv.deser; | ||
|
||
import com.fasterxml.jackson.databind.ObjectReader; | ||
import com.fasterxml.jackson.dataformat.csv.CsvParser; | ||
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
// for [dataformats-text#15]: Allow skipping of empty lines | ||
public class SkipBlankLines15Test extends ModuleTestBase { | ||
|
||
private static final String CSV_WITH_EMPTY_LINE = "1,\"xyz\"\n\ntrue,\n"; | ||
private static final String CSV_WITH_BLANK_LINE = "1,\"xyz\"\n \ntrue,\n"; | ||
private static final String CSV_WITH_BLANK_LINE_AND_COMMENT = "1,\"xyz\"\n \n #comment\n\ntrue,\n"; | ||
private static final String CSV_WITH_FIRST_BLANK_LINE = "\n1,\"xyz\"\ntrue,\n"; | ||
private static final String CSV_WITH_TRAILING_BLANK_LINES = "1,\"xyz\"\ntrue,\n \n\n"; | ||
|
||
public void testCsvWithEmptyLineSkipBlankLinesFeatureDisabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray().readValue(CSV_WITH_EMPTY_LINE); | ||
// First, verify default behavior: | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row(""), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
public void testCsvWithEmptyLineSkipBlankLinesFeatureEnabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.with(CsvParser.Feature.SKIP_EMPTY_LINES) | ||
.readValue(CSV_WITH_EMPTY_LINE); | ||
// empty line is skipped | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
|
||
public void testCsvWithBlankLineSkipBlankLinesFeatureDisabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.readValue(CSV_WITH_BLANK_LINE); | ||
// First, verify default behavior: | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row(" "), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
public void testCsvWithBlankLineSkipBlankLinesFeatureEnabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.with(CsvParser.Feature.SKIP_EMPTY_LINES) | ||
.readValue(CSV_WITH_BLANK_LINE); | ||
// blank line is skipped | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureDisabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.readValue(CSV_WITH_BLANK_LINE_AND_COMMENT); | ||
// First, verify default behavior: | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row(" "), | ||
row(" #comment"), | ||
row(""), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.with(CsvParser.Feature.SKIP_EMPTY_LINES) | ||
.readValue(CSV_WITH_BLANK_LINE_AND_COMMENT); | ||
// blank/empty lines are skipped | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row(" #comment"), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabledAndAllowComments() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.with(CsvParser.Feature.SKIP_EMPTY_LINES) | ||
.with(CsvParser.Feature.ALLOW_COMMENTS) | ||
.readValue(CSV_WITH_BLANK_LINE_AND_COMMENT); | ||
// blank/empty/comment lines are skipped | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
public void testCsvWithFirstBlankLineSkipBlankLinesFeatureDisabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.readValue(CSV_WITH_FIRST_BLANK_LINE); | ||
// First, verify default behavior: | ||
assertArrayEquals(expected( | ||
row(""), | ||
row("1", "xyz"), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
public void testCsvWithFirstBlankLineSkipBlankLinesFeatureEnabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.with(CsvParser.Feature.SKIP_EMPTY_LINES) | ||
.readValue(CSV_WITH_FIRST_BLANK_LINE); | ||
// blank line is skipped | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
|
||
public void testCsvWithTrailingBlankLineSkipBlankLinesFeatureDisabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.readValue(CSV_WITH_TRAILING_BLANK_LINES); | ||
// First, verify default behavior: | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row("true", ""), | ||
row(" "), | ||
row("") | ||
), rows); | ||
} | ||
|
||
public void testCsvWithTrailingBlankLineSkipBlankLinesFeatureEnabled() throws Exception { | ||
String[][] rows = mapperForCsvAsArray() | ||
.with(CsvParser.Feature.SKIP_EMPTY_LINES) | ||
.readValue(CSV_WITH_FIRST_BLANK_LINE); | ||
// blank lines are skipped | ||
assertArrayEquals(expected( | ||
row("1", "xyz"), | ||
row("true", "") | ||
), rows); | ||
} | ||
|
||
private ObjectReader mapperForCsvAsArray() { | ||
// when wrapped as an array, we'll get array of Lists: | ||
return mapperForCsv() | ||
.readerFor(String[][].class) | ||
.with(CsvParser.Feature.WRAP_AS_ARRAY); | ||
} | ||
|
||
private String[][] expected(String[]... rowInputs) { | ||
return rowInputs; | ||
} | ||
|
||
private String[] row(String... cellInputs) { | ||
return cellInputs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.