Skip to content

Commit 1901a01

Browse files
committed
test(csv-parse): using on_record, columns and raw conjointly
1 parent fbaf23e commit 1901a01

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

packages/csv-parse/test/option.on_record.coffee

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe 'Option `on_record`', ->
5757
it 'properties', (next) ->
5858
parse "a,b",
5959
on_record: (record, context) ->
60+
should(context.raw).be.undefined()
6061
Object.keys(context).sort()
6162
skip_records_with_error: true
6263
, (err, records) ->
@@ -66,7 +67,26 @@ describe 'Option `on_record`', ->
6667
'index', 'invalid_field_length', 'lines', 'raw', 'records'
6768
]]
6869
next()
69-
70+
71+
it 'properties with `columns: true` and `raw: true`', (next) ->
72+
parse "a,b\n1,2\n3,4",
73+
columns: true
74+
raw: true
75+
on_record: (record, context) ->
76+
if context.lines is 2
77+
context.raw.should.eql '1,2\n'
78+
else if context.lines is 3
79+
context.raw.should.eql '3,4'
80+
Object.keys(context).sort()
81+
skip_records_with_error: true
82+
, (err, records) ->
83+
records.shift().should.eql [
84+
'bytes',
85+
'columns', 'comment_lines', 'empty_lines', 'error', 'header',
86+
'index', 'invalid_field_length', 'lines', 'raw', 'records'
87+
]
88+
next()
89+
7090
it 'values', (next) ->
7191
parse "a,b\nc,d",
7292
on_record: (record, context) ->

0 commit comments

Comments
 (0)