This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new ignore_last_delimiters option, solve #193
- Loading branch information
Showing
8 changed files
with
155 additions
and
10 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
parse = require '../lib' | ||
|
||
describe 'Option `ignore_last_delimiters`', -> | ||
|
||
describe 'validation & normalization', -> | ||
|
||
it 'default to `false`', -> | ||
parse().options.ignore_last_delimiters.should.eql false | ||
|
||
it 'boolean', -> | ||
parse(ignore_last_delimiters: true, columns: true).options.ignore_last_delimiters.should.eql true | ||
parse(ignore_last_delimiters: false, columns: true).options.ignore_last_delimiters.should.eql false | ||
|
||
it 'integer', -> | ||
parse(ignore_last_delimiters: 1, columns: true).options.ignore_last_delimiters.should.eql true | ||
parse(ignore_last_delimiters: 0, columns: true).options.ignore_last_delimiters.should.eql false | ||
|
||
it 'throw error with invalid type', -> | ||
(-> | ||
parse(ignore_last_delimiters: 'invalid') | ||
).should.throw | ||
code: 'CSV_INVALID_OPTION_IGNORE_LAST_DELIMITERS' | ||
message: [ | ||
'Invalid option `ignore_last_delimiters`:' | ||
'the value must be a boolean value or an integer,' | ||
'got "invalid"' | ||
].join ' ' | ||
|
||
it 'requires columns', -> | ||
(-> | ||
parse(ignore_last_delimiters: true) | ||
).should.throw | ||
code: 'CSV_IGNORE_LAST_DELIMITERS_REQUIRES_COLUMNS' | ||
message: [ | ||
'The option `ignore_last_delimiters`' | ||
'requires the activation of the `columns` option' | ||
].join ' ' | ||
|
||
describe 'usage', -> | ||
|
||
it 'dont interpret last delimiters', (next) -> | ||
parse ''' | ||
a,b,c | ||
1,2,3,4,5 | ||
11,22,33,44 | ||
''', ignore_last_delimiters: true, columns: true, (err, data) -> | ||
data.should.eql [ | ||
{a: '1', b: '2', c: '3,4,5'} | ||
{a: '11', b: '22', c: '33,44'} | ||
] unless err | ||
next err |