-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from derjust/master
Strict record handling
- Loading branch information
Showing
5 changed files
with
45 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ First7,Last7,[email protected],"7 Street St, State ST, 88888" | |
First8,Last8,[email protected],"8 Street St, State ST, 88888" | ||
#Line 9 | ||
First9,Last9,[email protected],"9 Street St, State ST, 88888" | ||
#End of CSV | ||
#End of CSV |
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,4 @@ | ||
first_name,last_name,email_address,extra | ||
First1,Last1,[email protected],Extra1 | ||
First2,Last2,[email protected], | ||
First3,Last3,[email protected],Extra2 |
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 |
---|---|---|
|
@@ -375,6 +375,13 @@ var expected23 = [ | |
{"first_name": "First3", "last_name": "Last3", "email_address": "[email protected]"} | ||
]; | ||
|
||
var expected25 = [ | ||
{"first_name": "First1", "last_name": "Last1", "email_address": "[email protected]", "extra": "Extra1"}, | ||
{"first_name": "First3", "last_name": "Last3", "email_address": "[email protected]", "extra": "Extra2"} | ||
]; | ||
|
||
var expected25_invalid = [ 'First2', 'Last2', '[email protected]' ]; | ||
|
||
it.describe("fast-csv parsing", function (it) { | ||
|
||
it.timeout(60000); | ||
|
@@ -985,6 +992,27 @@ it.describe("fast-csv parsing", function (it) { | |
}); | ||
}); | ||
|
||
it.should("report missing columns that do not exist but have a header with strictColumnHandling option", function (next) { | ||
var actual = []; | ||
var reachedInvalid = false; | ||
csv | ||
.fromPath(path.resolve(__dirname, "./assets/test25.csv"), {headers: true, strictColumnHandling: true}) | ||
.on("data", function (data) { | ||
actual.push(data); | ||
}) | ||
.on("data-invalid", function(actual) { | ||
assert.deepEqual(actual, expected25_invalid); | ||
reachedInvalid = true; | ||
}) | ||
.on("error", next) | ||
.on("end", function (count) { | ||
assert.equal(true, reachedInvalid); | ||
assert.deepEqual(actual, expected25); | ||
assert.equal(count, actual.length); | ||
next(); | ||
}); | ||
}); | ||
|
||
it.describe("alternate delimiters", function (it) { | ||
it.should("support tab delimiters", function (next) { | ||
var actual = []; | ||
|