Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Add failing test for #132
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 25, 2016
1 parent 87bb0d1 commit a3045b7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void _testMapsWithLinefeeds(boolean useBytes) throws Exception {
mi.close();
}

// [Issue#12]
// [dataformat-csv#12]
public void testEmptyHandlingForInteger() throws Exception {
CsvSchema schema = MAPPER.typedSchemaFor(Point.class).withoutHeader();

Expand All @@ -194,7 +194,7 @@ public void testStringNullHandlingForInteger() throws Exception {
assertNull(result.z);
}

// [Issue#41]
// [dataformat-csv#41]
public void testIncorrectDups41() throws Exception {
final String INPUT = "\"foo\",\"bar\",\"foo\"";
CsvSchema schema = CsvSchema.builder().addColumn("Col1").addColumn("Col2")
Expand All @@ -215,7 +215,7 @@ public void testIncorrectDups41() throws Exception {
assertEquals("foo", m.get("Col3"));
}

// for pull request 89
// for [dataformat-csv#89]
public void testColumnReordering() throws IOException {
CsvFactory factory = new CsvFactory();
String CSV = "b,a,c\nvb,va,vc\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.csv.*;

// Tests for [Issue#26]
// Tests for [dataformat-csv#26]
public class TestParserStrictQuoting extends ModuleTestBase
{
@JsonPropertyOrder({"a", "b"})
Expand All @@ -16,7 +16,7 @@ public AB(String a, String b) {
this.b = b;
}
}

/*
/**********************************************************************
/* Test methods
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.fasterxml.jackson.dataformat.csv.failing;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.dataformat.csv.*;

public class BrokenEncodingTest extends ModuleTestBase
{
/*
/**********************************************************************
/* Test methods
/**********************************************************************
*/

public void testLatin1asUTF8() throws Exception
{
CsvFactory factory = new CsvFactory();
String CSV = "1,2\nabc,\u00A0\n";

CsvSchema schema = CsvSchema.builder()
.addColumn("a")
.addColumn("b")
.build();
// So: take Latin-1 bytes, but construct without specifying to lead to UTF-8 handling
CsvParser parser = factory.createParser(CSV.getBytes("ISO-8859-1"));
parser.setSchema(schema);

assertToken(JsonToken.START_OBJECT, parser.nextToken());
assertToken(JsonToken.FIELD_NAME, parser.nextToken());
assertEquals("a", parser.getCurrentName());
assertToken(JsonToken.VALUE_STRING, parser.nextToken());
assertToken(JsonToken.FIELD_NAME, parser.nextToken());
assertToken(JsonToken.VALUE_STRING, parser.nextToken());
assertEquals("2", parser.getText());
assertToken(JsonToken.END_OBJECT, parser.nextToken());

// problem should only be triggered now
assertToken(JsonToken.START_OBJECT, parser.nextToken());
assertToken(JsonToken.FIELD_NAME, parser.nextToken());
assertEquals("a", parser.getCurrentName());
assertToken(JsonToken.VALUE_STRING, parser.nextToken());
assertEquals("abc", parser.getText());
try {
parser.nextToken();
fail("Should trigger exception for invalid UTF-8 char");
} catch (JsonParseException e) {
verifyException(e, "foobar");
}
parser.close();
}
}

0 comments on commit a3045b7

Please sign in to comment.