Skip to content

Commit

Permalink
test(csv-parse): using on_record, columns and raw conjointly
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 6, 2023
1 parent fbaf23e commit 1901a01
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/csv-parse/test/option.on_record.coffee
Expand Up @@ -57,6 +57,7 @@ describe 'Option `on_record`', ->
it 'properties', (next) ->
parse "a,b",
on_record: (record, context) ->
should(context.raw).be.undefined()
Object.keys(context).sort()
skip_records_with_error: true
, (err, records) ->
Expand All @@ -66,7 +67,26 @@ describe 'Option `on_record`', ->
'index', 'invalid_field_length', 'lines', 'raw', 'records'
]]
next()


it 'properties with `columns: true` and `raw: true`', (next) ->
parse "a,b\n1,2\n3,4",
columns: true
raw: true
on_record: (record, context) ->
if context.lines is 2
context.raw.should.eql '1,2\n'
else if context.lines is 3
context.raw.should.eql '3,4'
Object.keys(context).sort()
skip_records_with_error: true
, (err, records) ->
records.shift().should.eql [
'bytes',
'columns', 'comment_lines', 'empty_lines', 'error', 'header',
'index', 'invalid_field_length', 'lines', 'raw', 'records'
]
next()

it 'values', (next) ->
parse "a,b\nc,d",
on_record: (record, context) ->
Expand Down

0 comments on commit 1901a01

Please sign in to comment.