Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
tests: compatibility with Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed May 5, 2018
1 parent bddf8d5 commit d3234ec
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## Trunk

* tests: compatibility with Node.js 10
* trim: handle quote followed by escape
* parser: set nextChar to null instead of empty
* travis: run against node 8 and 10
Expand Down
12 changes: 6 additions & 6 deletions test/api.arguments.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ describe 'api arguments', ->
data = []
parser = parse()
parser.on 'readable', ->
while d = parser.read()
while d = this.read()
data.push d
parser.on 'err', (err) ->
next err
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [ [ 'field_1', 'field_2' ], [ 'value 1', 'value 2' ] ]
next()
parser.write 'field_1,field_2\nvalue 1,value 2'
Expand All @@ -39,7 +39,7 @@ describe 'api arguments', ->
data.push d
parser.on 'err', (err) ->
next err
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [field_1: 'value 1', field_2: 'value 2']
next()
parser.write 'field_1,field_2\nvalue 1,value 2'
Expand All @@ -55,7 +55,7 @@ describe 'api arguments', ->
data.push d
parser.on 'err', (err) ->
next err
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [field_1: 'value 1', field_2: 'value 2']
next()

Expand All @@ -72,7 +72,7 @@ describe 'api arguments', ->
next err

it 'data:buffer, callback:function', (next) ->
parse new Buffer('value a,value b\nvalue 1,value 2'), (err, data) ->
parse Buffer.from('value a,value b\nvalue 1,value 2'), (err, data) ->
data.should.eql [ [ 'value a', 'value b' ], [ 'value 1', 'value 2' ] ]
next err

Expand Down Expand Up @@ -106,7 +106,7 @@ describe 'api arguments', ->
next err

it 'data:buffer, options:object, callback:function', (next) ->
parse new Buffer('field_1,field_2\nvalue 1,value 2'), columns: true, (err, data) ->
parse Buffer.from('field_1,field_2\nvalue 1,value 2'), columns: true, (err, data) ->
data.should.eql [field_1: 'value 1', field_2: 'value 2']
next err

Expand Down
6 changes: 4 additions & 2 deletions test/api.events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ describe 'api events', ->
parser = parse()
parser.on 'record', (record) ->
before.push record
parser.on 'data', -> while this.read() then null
parser.write """
"ABC","45"
"DEF","23"
"""
parser.on 'finish', ->
parser.on 'end', ->
before.should.eql [
[ 'ABC', '45' ]
[ 'DEF', '23' ]
Expand All @@ -29,7 +30,8 @@ describe 'api events', ->
"""
parser.on 'record', (record) ->
after.push record
parser.on 'finish', ->
parser.on 'data', -> while this.read() then null
parser.on 'end', ->
after.should.eql [
[ 'ABC', '45' ]
[ 'DEF', '23' ]
Expand Down
2 changes: 1 addition & 1 deletion test/api.pipe.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe 'api pipe', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
finished = true
parser.on 'end', ->
finished.should.be.ok
Expand Down
2 changes: 1 addition & 1 deletion test/api.sync.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe 'api sync', ->
data.should.eql [ [ 'field_1', 'field_2' ], [ 'value 1', 'value 2' ] ]

it 'take a buffer and return records', ->
data = parse new Buffer 'field_1,field_2\nvalue 1,value 2'
data = parse Buffer.from 'field_1,field_2\nvalue 1,value 2'
data.should.eql [ [ 'field_1', 'field_2' ], [ 'value 1', 'value 2' ] ]

it 'honors columns option', ->
Expand Down
12 changes: 6 additions & 6 deletions test/api.write.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe 'api write', ->
parser.on 'readable', ->
while(d = parser.read())
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'Test 0', '0', '"' ]
[ 'Test 1', '1', '"' ]
Expand Down Expand Up @@ -46,10 +46,10 @@ describe 'api write', ->
parser = parse (err, data) ->
data[0][0].should.eql ''
next()
parser.write new Buffer [0xE2]
parser.write new Buffer [0x82]
parser.write new Buffer [0xAC]
# buff = new Buffer [0xE2, 0x82, 0xAC]
parser.write Buffer.from [0xE2]
parser.write Buffer.from [0x82]
parser.write Buffer.from [0xAC]
# buff = Buffer.from [0xE2, 0x82, 0xAC]
# parser.write buff
parser.end()

Expand All @@ -59,6 +59,6 @@ describe 'api write', ->
parser.on 'data', (data) ->
data.should.eql ['A', 'B', 'C']
parser.end()
parser.on 'finish', ->
parser.on 'end', ->
next()
parser.write 'A,B,C\n'
3 changes: 2 additions & 1 deletion test/events.record.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe 'events record', ->
"""
parser.on 'record', (record) ->
records.push record
parser.on 'finish', ->
parser.on 'data', -> while this.read() then null
parser.on 'end', ->
records.should.eql [
[ 'ABC', '45' ]
[ 'DEF', '23' ]
Expand Down
2 changes: 1 addition & 1 deletion test/options.auto_parse.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe 'options "auto_parse" (deprecated)', ->
data.push d
parser.on 'error', (err) ->
next err
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[20322051544, 1979, 8.8017226e7, 800, 'ABC', 45, '2000-01-01']
[28392898392, 1974, 8.8392926e7, 800, 'DEF', 23, '2050-11-27']
Expand Down
2 changes: 1 addition & 1 deletion test/options.cast.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe 'options "cast"', ->
data.push d
parser.on 'error', (err) ->
next err
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[20322051544, 1979, 8.8017226e7, 800, 'ABC', 45, '2000-01-01']
[28392898392, 1974, 8.8392926e7, 800, 'DEF', 23, '2050-11-27']
Expand Down
2 changes: 1 addition & 1 deletion test/options.escape.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe 'options escape', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'field with " inside' ]
]
Expand Down
14 changes: 7 additions & 7 deletions test/options.rowDelimiter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe 'options rowDelimiter', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'ABC','45' ]
[ 'DEF','23' ]
Expand All @@ -78,7 +78,7 @@ describe 'options rowDelimiter', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'ABC','45' ]
[ 'DEF','23' ]
Expand All @@ -100,7 +100,7 @@ describe 'options rowDelimiter', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'ABC','45' ]
[ 'DEF','23' ]
Expand All @@ -120,7 +120,7 @@ describe 'options rowDelimiter', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'ABC','45' ]
[ 'DEF','23' ]
Expand Down Expand Up @@ -171,7 +171,7 @@ describe 'options rowDelimiter', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'ABC','45' ]
[ 'DEF','23' ]
Expand All @@ -191,7 +191,7 @@ describe 'options rowDelimiter', ->
parser.on 'readable', ->
while(d = parser.read())
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'abc', '123' ]
[ 'def', '456' ]
Expand All @@ -216,7 +216,7 @@ describe 'options rowDelimiter', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'ABC','45' ]
[ 'DEF','23' ]
Expand Down
2 changes: 1 addition & 1 deletion test/options.skip_empty_lines.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe 'options skip_empty_lines', ->
data.push d
parser.on 'error', (err) ->
next err
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
['20322051544', '1979', '8.8017226E7', 'ABC', '45', '2000-01-01']
['28392898392', '1974', '8.8392926E7', 'DEF', '23', '2050-11-27']
Expand Down
14 changes: 7 additions & 7 deletions test/options.trim.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe 'options ltrim', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'FIELD 1','FIELD 2','FIELD 3','FIELD 4','FIELD 5','FIELD 6' ]
[ '20322051544',' 1979','8.8017226E7','ABC','45','2000-01-01' ]
Expand All @@ -39,7 +39,7 @@ describe 'options ltrim', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'FIELD_1','FIELD_2' ]
[ '20322051544','a' ]
Expand All @@ -61,7 +61,7 @@ describe 'rtrim', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'FIELD_1','FIELD_2','FIELD_3','FIELD_4','FIELD_5','FIELD_6']
[ '20322051544','1979','8.8017226E7','ABC','45','2000-01-01']
Expand All @@ -83,7 +83,7 @@ describe 'trim', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'FIELD 1','FIELD 2','FIELD 3','FIELD 4','FIELD 5','FIELD 6' ]
[ '20322051544','1979','8.8017226E7','ABC','45','2000-01-01' ]
Expand All @@ -103,7 +103,7 @@ describe 'trim', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'FIELD 1','FIELD 2','FIELD 3','FIELD 4','FIELD 5','FIELD 6' ]
[ '20322051544','1979','8.8017226E7','ABC DEF','45','2000-01-01' ]
Expand Down Expand Up @@ -154,7 +154,7 @@ describe 'trim', ->
parser.on 'readable', ->
while(d = parser.read())
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ 'Test 0', '', ' 0,00 ', '"' ]
[ 'Test 1', '', ' 100000,100000 ', '"' ]
Expand Down Expand Up @@ -196,7 +196,7 @@ describe 'no trim', ->
parser.on 'readable', ->
while d = parser.read()
data.push d
parser.on 'finish', ->
parser.on 'end', ->
data.should.eql [
[ ' FIELD 1 ',' FIELD 2 ',' FIELD 3','FIELD 4 ',' FIELD 5','FIELD 6 ' ]
[ '20322051544','1979 ','8.8017226E7','AB C ',' 45 ',' 2000-01-01' ]
Expand Down
6 changes: 4 additions & 2 deletions test/properties.lines_count.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ describe 'properties number of lines', ->

it 'adds up with default settings', (next) ->
parser = parse()
parser.on 'finish', ->
parser.on 'data', -> while this.read() then null
parser.on 'end', ->
this.lines.should.eql(this.count + this.empty_line_count + this.skipped_line_count)
next()
parser.write 'ABC\n\nDEF'
Expand All @@ -29,9 +30,10 @@ describe 'properties number of lines', ->

it 'counts skipped lines', (next) ->
parser = parse '', relax_column_count: true
parser.on 'data', -> while this.read() then null
parser.on 'error', (err) ->
next(err)
parser.on 'finish', ->
parser.on 'end', ->
this.lines.should.eql(this.count + this.empty_line_count)
this.empty_line_count.should.eql(2)
this.skipped_line_count.should.eql(1)
Expand Down

0 comments on commit d3234ec

Please sign in to comment.