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

Commit

Permalink
columns: group tests by type
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jul 31, 2018
1 parent fdc88ce commit ac8242c
Showing 1 changed file with 97 additions and 93 deletions.
190 changes: 97 additions & 93 deletions test/options.columns.coffee
Expand Up @@ -2,105 +2,109 @@
parse = require '../src'

describe 'options columns', ->

describe 'boolean', ->

it 'read from first row if true', (next) ->
parse """
FIELD_1,FIELD_2,FIELD_3,FIELD_4,FIELD_5,FIELD_6
20322051544,1979,8.8017226E7,ABC,45,2000-01-01
28392898392,1974,8.8392926E7,DEF,23,2050-11-27
""", columns: true, (err, data) ->
return next err if err
data.should.eql [
"FIELD_1":"20322051544"
"FIELD_2":"1979"
"FIELD_3":"8.8017226E7"
"FIELD_4":"ABC"
"FIELD_5":"45"
"FIELD_6":"2000-01-01"
,
"FIELD_1":"28392898392"
"FIELD_2":"1974"
"FIELD_3": "8.8392926E7"
"FIELD_4":"DEF"
"FIELD_5":"23"
"FIELD_6":"2050-11-27"
]
next()
it 'read from first row if true', (next) ->
parse """
FIELD_1,FIELD_2,FIELD_3,FIELD_4,FIELD_5,FIELD_6
20322051544,1979,8.8017226E7,ABC,45,2000-01-01
28392898392,1974,8.8392926E7,DEF,23,2050-11-27
""", columns: true, (err, data) ->
return next err if err
data.should.eql [
"FIELD_1":"20322051544"
"FIELD_2":"1979"
"FIELD_3":"8.8017226E7"
"FIELD_4":"ABC"
"FIELD_5":"45"
"FIELD_6":"2000-01-01"
,
"FIELD_1":"28392898392"
"FIELD_2":"1974"
"FIELD_3": "8.8392926E7"
"FIELD_4":"DEF"
"FIELD_5":"23"
"FIELD_6":"2050-11-27"
]
next()

describe 'boolean array', ->

it 'enforced by user if array', (next) ->
parse """
20322051544,1979,8.8017226E7,ABC,45,2000-01-01
28392898392,1974,8.8392926E7,DEF,23,2050-11-27
""", columns: ["FIELD_1", "FIELD_2", "FIELD_3", "FIELD_4", "FIELD_5", "FIELD_6"], (err, data) ->
return next err if err
data.should.eql [
"FIELD_1":"20322051544"
"FIELD_2":"1979"
"FIELD_3":"8.8017226E7"
"FIELD_4":"ABC"
"FIELD_5":"45"
"FIELD_6":"2000-01-01"
,
"FIELD_1":"28392898392"
"FIELD_2":"1974"
"FIELD_3":"8.8392926E7"
"FIELD_4":"DEF"
"FIELD_5":"23"
"FIELD_6":"2050-11-27"
]
next()

it 'skip columns with false value', (next) ->
parse """
abc,123,def,456
hij,789,klm,789
""", columns: ["FIELD_1", false, "FIELD_2", false], (err, data) ->
return next err if err
data.should.eql [
"FIELD_1":"abc"
"FIELD_2":"def"
,
"FIELD_1":"hij"
"FIELD_2":"klm"
]
next()
it 'enforced by user if array', (next) ->
parse """
20322051544,1979,8.8017226E7,ABC,45,2000-01-01
28392898392,1974,8.8392926E7,DEF,23,2050-11-27
""", columns: ["FIELD_1", "FIELD_2", "FIELD_3", "FIELD_4", "FIELD_5", "FIELD_6"], (err, data) ->
return next err if err
data.should.eql [
"FIELD_1":"20322051544"
"FIELD_2":"1979"
"FIELD_3":"8.8017226E7"
"FIELD_4":"ABC"
"FIELD_5":"45"
"FIELD_6":"2000-01-01"
,
"FIELD_1":"28392898392"
"FIELD_2":"1974"
"FIELD_3":"8.8392926E7"
"FIELD_4":"DEF"
"FIELD_5":"23"
"FIELD_6":"2050-11-27"
]
next()
it 'skip columns with false value', (next) ->
parse """
abc,123,def,456
hij,789,klm,789
""", columns: ["FIELD_1", false, "FIELD_2", false], (err, data) ->
return next err if err
data.should.eql [
"FIELD_1":"abc"
"FIELD_2":"def"
,
"FIELD_1":"hij"
"FIELD_2":"klm"
]
next()

it 'validate options column length on first line', (next) ->
parse """
1,2,3
4,5,6,x
7,8,9,x
""", columns: ["a", "b", "c", "d"], (err, data) ->
err.message.should.eql 'Number of columns on line 1 does not match header'
next()
it 'validate options column length on first line', (next) ->
parse """
1,2,3
4,5,6,x
7,8,9,x
""", columns: ["a", "b", "c", "d"], (err, data) ->
err.message.should.eql 'Number of columns on line 1 does not match header'
next()

it 'emit single error when column count is invalid on multiple lines', (next) ->
parse """
1;2
1
3;4
5;6;7
"""
, delimiter: ';', skip_empty_lines: true, (err, data) ->
err.message.should.eql 'Number of columns is inconsistent on line 2'
process.nextTick next
it 'emit single error when column count is invalid on multiple lines', (next) ->
parse """
1;2
1
3;4
5;6;7
"""
, delimiter: ';', skip_empty_lines: true, (err, data) ->
err.message.should.eql 'Number of columns is inconsistent on line 2'
process.nextTick next

it 'validate options column length on last line', (next) ->
parse """
1,2,3,x
4,5,6,x
7,8,9
""", columns: ["a", "b", "c", "d"], (err, data) ->
err.message.should.eql 'Number of columns on line 3 does not match header'
next()
it 'validate options column length on last line', (next) ->
parse """
1,2,3,x
4,5,6,x
7,8,9
""", columns: ["a", "b", "c", "d"], (err, data) ->
err.message.should.eql 'Number of columns on line 3 does not match header'
next()

it 'handles missing column if number of columns is inconsistent', (next) ->
parse """
20322051544,1979,8.8017226E7,ABC,45,2000-01-01
28392898392,1974,8.8392926E7,23,2050-11-27
""", (err, data) ->
err.message.should.eql 'Number of columns is inconsistent on line 2'
next()
it 'handles missing column if number of columns is inconsistent', (next) ->
parse """
20322051544,1979,8.8017226E7,ABC,45,2000-01-01
28392898392,1974,8.8392926E7,23,2050-11-27
""", (err, data) ->
err.message.should.eql 'Number of columns is inconsistent on line 2'
next()

describe 'function', ->

Expand Down

0 comments on commit ac8242c

Please sign in to comment.