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 167
/
option.to.coffee
91 lines (83 loc) · 2.05 KB
/
option.to.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
parse = require '../lib'
describe 'Option `to`', ->
it 'validation', ->
parse '', to: 10, (->)
parse '', to: "10", (->)
(->
parse '', to: -1, (->)
).should.throw 'Invalid Option: to must be a positive integer, got -1'
(->
parse '', to: 0, (->)
).should.throw 'Invalid Option: to must be a positive integer, got 0'
(->
parse '', to: '0', (->)
).should.throw 'Invalid Option: to must be castable to a positive integer, got "0"'
(->
parse '', to: true, (->)
).should.throw 'Invalid Option: to must be an integer, got true'
(->
parse '', to: false, (->)
).should.throw 'Invalid Option: to must be an integer, got false'
(->
parse '', to: 'oh no', (->)
).should.throw 'Invalid Option: to must be an integer, got "oh no"'
it 'start at defined position', (next) ->
parse """
1,2,3
4,5,6
7,8,9
""", to: 2, (err, data) ->
return next err if err
data.should.eql [
[ '1','2','3' ]
[ '4','5','6' ]
]
next()
it 'dont count headers', (next) ->
parse """
a,b,c
1,2,3
4,5,6
7,8,9
""", columns: true, to: 2, (err, data) ->
return next err if err
data.should.eql [
{a:'1',b:'2',c:'3'}
{a:'4',b:'5',c:'6'}
]
next()
it 'end stream when "to" is reached, further lines are not parsed', (next) ->
parse """
1,2,3
4,5,6
7,8
""", to: 2, (err, data) ->
return next err if err
data.should.eql [
[ '1','2','3' ]
[ '4','5','6' ]
]
next()
it 'not influenced by lines', (next) ->
parse """
1,2,"
3"
4,5,"
6"
7,8,"
9"
""", to: 2, (err, data) ->
data.should.eql [
[ '1','2','\n3' ]
[ '4','5','\n6' ]
] unless err
next err
it 'not influenced by row delimiter', (next) ->
parse """
1,2,3:4,5,6:7,8,9
""", to: 2, record_delimiter: ':', (err, data) ->
data.should.eql [
[ '1','2','3' ]
[ '4','5','6' ]
] unless err
next err