Skip to content

Commit

Permalink
Add failing test for #15, as well as tentative feature enum
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 7, 2017
1 parent d6c0b4c commit 939c7f9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Expand Up @@ -62,11 +62,24 @@ public enum Feature
* columns that appear after columns for which types are defined. When disabled,
* an exception is thrown for such column values, but if enabled, they are
* silently ignored.
*<p>
* Feature is disabled by default.
*
* @since 2.7
*/
IGNORE_TRAILING_UNMAPPABLE(false),

/**
* Feature that allows skipping input lines that are completely empty, instead
* of being decoded as lines of just a single column with empty String value (or,
* depending on binding, `null`).
*<p>
* Feature is disabled by default.
*
* @since 2.9
*/
SKIP_EMPTY_LINES(false),

/**
* Feature that allows there to be a trailing single extraneous data
* column that is empty. When this feature is disabled, any extraneous
Expand Down
@@ -0,0 +1,67 @@
package com.fasterxml.jackson.dataformat.csv.failing;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.csv.*;

public class SkipEmptyLines15Test extends ModuleTestBase
{
@JsonPropertyOrder({ "age", "name", "cute" })
protected static class Entry {
public int age;
public String name;
public boolean cute;
}

/*
/**********************************************************************
/* Test methods, success
/**********************************************************************
*/

// for [dataformats-text#15]: Allow skipping of empty lines
public void testSkipEmptyLinesFeature() throws Exception
{
final String CSV = "1,\"xyz\"\n\ntrue,\n";

CsvMapper mapper = mapperForCsv();
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);

// First, verify default behavior:

String[][] rows = mapper.readValue(CSV, String[][].class);
assertEquals(3, rows.length);
String[] row;

row = rows[0];
assertEquals(2, row.length);
assertEquals("1",row[0]);
assertEquals("xyz", row[1]);

row = rows[1];
assertEquals(1, row.length);
assertEquals("", row[0]);

row = rows[2];
assertEquals(2, row.length);
assertEquals("true", row[0]);
assertEquals("", row[1]);

mapper.enable(CsvParser.Feature.SKIP_EMPTY_LINES);

// when wrapped as an array, we'll get array of Lists:
rows = mapper.readerFor(String[][].class)
.with(CsvParser.Feature.WRAP_AS_ARRAY)
.readValue(CSV);

assertEquals(2, rows.length);
row = rows[0];
assertEquals(2, row.length);
assertEquals("1",row[0]);
assertEquals("xyz", row[1]);

row = rows[1];
assertEquals(2, row.length);
assertEquals("true", row[0]);
assertEquals("", row[1]);
}
}

0 comments on commit 939c7f9

Please sign in to comment.