forked from adaltas/node-csv-parse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.comment.coffee
80 lines (72 loc) · 1.54 KB
/
options.comment.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
should = require 'should'
parse = require '../src'
describe 'comment', ->
it 'skip line starting by # by default', (next) ->
parse """
# skip this
"ABC","45"
"DEF","23"
# and this
"GHI","94"
# as well as that
""", comment: '#', (err, data) ->
data.should.eql [
[ 'ABC','45' ]
[ 'DEF','23' ]
[ 'GHI','94' ]
]
next()
it 'doent apply inside quotes', (next) ->
parse """
"ABC","45"
"D#noEF","23"#yes
"GHI","94"
""", comment: '#', (err, data) ->
data.should.eql [
[ 'ABC','45' ]
[ 'D#noEF','23' ]
[ 'GHI','94' ]
]
next()
it 'is cancel if empty', (next) ->
parse """
abc,#,def
1,2,3
""", comment: '', (err, data) ->
data.should.eql [
[ 'abc','#','def' ]
[ '1','2', '3' ]
]
next()
it 'is cancel by default', (next) ->
parse """
abc,#,def
1,2,3
""", (err, data) ->
data.should.eql [
[ 'abc','#','def' ]
[ '1','2', '3' ]
]
next()
it 'accept multiple characters', (next) ->
parser = parse comment: '//', (err, data) ->
data.should.eql [
[ 'abc','def' ]
[ '1','2' ]
]
next()
data = """
abc,def
// a comment
1,2
"""
parser.write char for char in data
parser.end()
it 'accept quotes', (next) ->
parse """
"Alaska","Site1","Rack1","RTU-1","192.168.1.3"
# Contains double-quote: "
""",
comment: "#"
, (err, content) ->
next err