Skip to content

Commit 021dfc9

Browse files
committed
refactor(csv-parse): rename data to records in tests
1 parent e7617da commit 021dfc9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+447
-449
lines changed

packages/csv-parse/test/api.arguments.coffee

+21-21
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ describe 'API arguments', ->
1111
describe '0 arg', ->
1212

1313
it 'no arguments', (next) ->
14-
data = []
14+
records = []
1515
parser = parse()
1616
parser.on 'readable', ->
1717
while d = this.read()
18-
data.push d
18+
records.push d
1919
parser.on 'err', (err) ->
2020
next err
2121
parser.on 'end', ->
22-
data.should.eql [ [ 'field_1', 'field_2' ], [ 'value 1', 'value 2' ] ]
22+
records.should.eql [ [ 'field_1', 'field_2' ], [ 'value 1', 'value 2' ] ]
2323
next()
2424
parser.write 'field_1,field_2\nvalue 1,value 2'
2525
parser.end()
@@ -28,53 +28,53 @@ describe 'API arguments', ->
2828

2929
it 'callback:function; pipe data and get result in callback', (next) ->
3030
generate(length: 2, seed: 1, columns: 2, fixed_size: true)
31-
.pipe parse (err, data) ->
32-
data.should.eql [ [ 'OMH', 'ONKCHhJmjadoA' ], [ 'D', 'GeACHiN' ] ]
31+
.pipe parse (err, records) ->
32+
records.should.eql [ [ 'OMH', 'ONKCHhJmjadoA' ], [ 'D', 'GeACHiN' ] ]
3333
next err
3434

3535
it 'options:object; write data and read stream', (next) ->
36-
data = []
36+
records = []
3737
parser = parse columns: true
3838
parser.on 'readable', ->
3939
while d = parser.read()
40-
data.push d
40+
records.push d
4141
parser.on 'err', (err) ->
4242
next err
4343
parser.on 'end', ->
44-
data.should.eql [field_1: 'value 1', field_2: 'value 2']
44+
records.should.eql [field_1: 'value 1', field_2: 'value 2']
4545
next()
4646
parser.write 'field_1,field_2\nvalue 1,value 2'
4747
parser.end()
4848

4949
describe '2 args', ->
5050

5151
it 'data:string, options:object; read stream', (next) ->
52-
data = []
52+
records = []
5353
parser = parse 'field_1,field_2\nvalue 1,value 2', columns: true
5454
parser.on 'readable', ->
5555
while d = parser.read()
56-
data.push d
56+
records.push d
5757
parser.on 'err', (err) ->
5858
next err
5959
parser.on 'end', ->
60-
data.should.eql [field_1: 'value 1', field_2: 'value 2']
60+
records.should.eql [field_1: 'value 1', field_2: 'value 2']
6161
next()
6262

6363
it 'options:object, callback:function; write data and get result in callback', (next) ->
64-
parser = parse columns: true, (err, data) ->
65-
data.should.eql [field_1: 'value 1', field_2: 'value 2']
64+
parser = parse columns: true, (err, records) ->
65+
records.should.eql [field_1: 'value 1', field_2: 'value 2']
6666
next err
6767
parser.write 'field_1,field_2\nvalue 1,value 2'
6868
parser.end()
6969

7070
it 'data:string, callback:function', (next) ->
71-
parse 'value a,value b\nvalue 1,value 2', (err, data) ->
72-
data.should.eql [ [ 'value a', 'value b' ], [ 'value 1', 'value 2' ] ]
71+
parse 'value a,value b\nvalue 1,value 2', (err, records) ->
72+
records.should.eql [ [ 'value a', 'value b' ], [ 'value 1', 'value 2' ] ]
7373
next err
7474

7575
it 'data:buffer, callback:function', (next) ->
76-
parse Buffer.from('value a,value b\nvalue 1,value 2'), (err, data) ->
77-
data.should.eql [ [ 'value a', 'value b' ], [ 'value 1', 'value 2' ] ]
76+
parse Buffer.from('value a,value b\nvalue 1,value 2'), (err, records) ->
77+
records.should.eql [ [ 'value a', 'value b' ], [ 'value 1', 'value 2' ] ]
7878
next err
7979

8080
it 'data:undefined, options:object', ->
@@ -108,13 +108,13 @@ describe 'API arguments', ->
108108
describe '3 args', ->
109109

110110
it 'data:string, options:object, callback:function', (next) ->
111-
parse 'field_1,field_2\nvalue 1,value 2', columns: true, (err, data) ->
112-
data.should.eql [field_1: 'value 1', field_2: 'value 2']
111+
parse 'field_1,field_2\nvalue 1,value 2', columns: true, (err, records) ->
112+
records.should.eql [field_1: 'value 1', field_2: 'value 2']
113113
next err
114114

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

120120
it 'data:undefined, options:object, callback:function', ->

packages/csv-parse/test/api.destroy.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe 'API destroy', ->
3030
return next err if err
3131
parser = parse()
3232
parser.on 'readable', ->
33-
while data = this.read()
33+
while record = this.read()
3434
parser.destroy(Error 'Catch me')
3535
parser.on 'error', (err) ->
3636
err.message.should.eql 'Catch me'
@@ -46,7 +46,7 @@ describe 'API destroy', ->
4646
# csv-generate emit data synchronously, it cant detect error on time
4747
parser = parse()
4848
parser.on 'readable', ->
49-
while data = this.read()
49+
while record = this.read()
5050
parser.destroy(Error 'Catch me')
5151
parser.on 'error', (err) ->
5252
err.message.should.eql 'Catch me'

packages/csv-parse/test/api.events.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe 'API events', ->
4444
x " a b",x " c d"
4545
x " e f", x " g h"
4646
'''
47-
parser = parse (err, data) ->
47+
parser = parse (err) ->
4848
assert_error err,
4949
message: 'Invalid Opening Quote: a quote is found inside a field at line 1'
5050
code: 'INVALID_OPENING_QUOTE'

packages/csv-parse/test/api.info.coffee

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe 'API info', ->
77
parse '''
88
1,2,3
99
a,b,
10-
''', (err, data, info) ->
10+
''', (err, records, info) ->
1111
info.should.eql
1212
bytes: 10
1313
columns: false
@@ -22,7 +22,7 @@ describe 'API info', ->
2222
parse '''
2323
1,2,3
2424
a,b,c
25-
''', (err, data, info) ->
25+
''', (err, records, info) ->
2626
info.should.eql
2727
bytes: 11
2828
columns: false
@@ -37,7 +37,7 @@ describe 'API info', ->
3737
parse '''
3838
a,b,c
3939
1,2,3
40-
''', columns: true, (err, data, info) ->
40+
''', columns: true, (err, records, info) ->
4141
info.should.eql
4242
bytes: 11
4343
comment_lines: 0
@@ -58,7 +58,7 @@ describe 'API info', ->
5858
d,"e
5959
",f
6060
g,h,i
61-
''', (err, data, info) ->
61+
''', (err, records, info) ->
6262
info.should.eql
6363
bytes: 20
6464
columns: false

packages/csv-parse/test/api.pipe.coffee

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ describe 'API pipe', ->
99
it 'piping in and reading out', (next) ->
1010
finished = false
1111
parser = parse()
12-
data = []
12+
records = []
1313
generator = generate length: 2, seed: 1, columns: 2, fixed_size: true
1414
parser.on 'readable', ->
1515
while d = parser.read()
16-
data.push d
16+
records.push d
1717
parser.on 'end', ->
1818
finished = true
1919
parser.on 'end', ->
2020
finished.should.be.ok
21-
data.should.eql [
21+
records.should.eql [
2222
[ 'OMH', 'ONKCHhJmjadoA' ]
2323
[ 'D', 'GeACHiN' ]
2424
]
@@ -27,8 +27,8 @@ describe 'API pipe', ->
2727

2828
it 'piping in and callback out', (next) ->
2929
generator = generate length: 2, seed: 1, columns: 2, fixed_size: true
30-
generator.pipe parse (err, data) ->
31-
data.should.eql [
30+
generator.pipe parse (err, records) ->
31+
records.should.eql [
3232
[ 'OMH', 'ONKCHhJmjadoA' ]
3333
[ 'D', 'GeACHiN' ]
3434
]

packages/csv-parse/test/api.sync.coffee

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ import { parse } from '../lib/sync.js'
44
describe 'API sync', ->
55

66
it 'take a string and return records', ->
7-
data = parse 'field_1,field_2\nvalue 1,value 2'
8-
data.should.eql [ [ 'field_1', 'field_2' ], [ 'value 1', 'value 2' ] ]
7+
records = parse 'field_1,field_2\nvalue 1,value 2'
8+
records.should.eql [ [ 'field_1', 'field_2' ], [ 'value 1', 'value 2' ] ]
99

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

1414
it 'honors columns option', ->
15-
data = parse 'field_1,field_2\nvalue 1,value 2', columns: true
16-
data.should.eql [ 'field_1': 'value 1', 'field_2': 'value 2' ]
15+
records = parse 'field_1,field_2\nvalue 1,value 2', columns: true
16+
records.should.eql [ 'field_1': 'value 1', 'field_2': 'value 2' ]
1717

1818
it 'honors objname option', ->
19-
data = parse 'field_1,field_2\nname 1,value 1\nname 2,value 2', objname: 'field_1', columns: true
20-
data.should.eql {
19+
records = parse 'field_1,field_2\nname 1,value 1\nname 2,value 2', objname: 'field_1', columns: true
20+
records.should.eql {
2121
'name 1': {'field_1': 'name 1', 'field_2': 'value 1'},
2222
'name 2': {'field_1': 'name 2', 'field_2': 'value 2'}
2323
}
2424

2525
it 'honors to_line', ->
26-
data = parse '1\n2\n3\n4', to_line: 2
27-
data.should.eql [ [ '1' ], [ '2' ] ]
26+
records = parse '1\n2\n3\n4', to_line: 2
27+
records.should.eql [ [ '1' ], [ '2' ] ]
2828

2929
it 'catch errors', ->
3030
try

packages/csv-parse/test/api.types.sync.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ describe('API Types', () => {
1818

1919
it('return records', () => {
2020
try {
21-
const data: object = parse("")
22-
typeof data
21+
const records: object = parse("")
22+
typeof records
2323
}catch (err){
2424
if (err instanceof CsvError){
2525
err.message

packages/csv-parse/test/api.types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ describe('API Types', () => {
7474

7575
it('return records', () => {
7676
try {
77-
const data: object = parse_sync("")
78-
typeof data
77+
const records: object = parse_sync("")
78+
typeof records
7979
}catch (err){
8080
if (err instanceof CsvError){
8181
err.message

packages/csv-parse/test/api.write.coffee

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { parse } from '../lib/index.js'
44
describe 'API write', ->
55

66
it 'string randomly splited', (next) ->
7-
data = []
7+
records = []
88
parser = parse()
99
parser.on 'readable', ->
1010
while(d = parser.read())
11-
data.push d
11+
records.push d
1212
parser.on 'end', ->
13-
data.should.eql [
13+
records.should.eql [
1414
[ 'Test 0', '0', '"' ]
1515
[ 'Test 1', '1', '"' ]
1616
[ 'Test 2', '2', '"' ]
@@ -42,8 +42,8 @@ describe 'API write', ->
4242
parser.write 'def,456'
4343

4444
it 'support multi-bytes utf8 encoded characters', (next) ->
45-
parser = parse (err, data) ->
46-
data[0][0].should.eql ''
45+
parser = parse (err, records) ->
46+
records[0][0].should.eql ''
4747
next()
4848
parser.write Buffer.from [0xE2]
4949
parser.write Buffer.from [0x82]

packages/csv-parse/test/info.comment_lines.coffee

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe 'info comment_lines', ->
77
parse '''
88
a,b,c
99
d,e,f
10-
''', comment: '#', (err, data, {comment_lines}) ->
10+
''', comment: '#', (err, records, {comment_lines}) ->
1111
comment_lines.should.eql 0 unless err
1212
next err
1313

@@ -16,17 +16,17 @@ describe 'info comment_lines', ->
1616
a,b,c
1717
d,e,f # comment
1818
h,i,j
19-
''', comment: '#', (err, data, {comment_lines}) ->
19+
''', comment: '#', (err, records, {comment_lines}) ->
2020
comment_lines.should.eql 0 unless err
2121
next err
2222

2323
it 'single comment line', (next) ->
24-
parse '# comment', comment: '#', (err, data, {comment_lines}) ->
24+
parse '# comment', comment: '#', (err, records, {comment_lines}) ->
2525
comment_lines.should.eql 1 unless err
2626
next err
2727

2828
it 'single comment line with empty field', (next) ->
29-
parse '""# comment', comment: '#', (err, data, {comment_lines}) ->
29+
parse '""# comment', comment: '#', (err, records, {comment_lines}) ->
3030
comment_lines.should.eql 0 unless err
3131
next err
3232

@@ -36,7 +36,7 @@ describe 'info comment_lines', ->
3636
# comment 1
3737
# comment 2
3838
d,e,f
39-
''', comment: '#', skip_empty_lines: true, (err, data, {comment_lines}) ->
39+
''', comment: '#', skip_empty_lines: true, (err, records, {comment_lines}) ->
4040
comment_lines.should.eql 2 unless err
4141
next err
4242

@@ -45,7 +45,7 @@ describe 'info comment_lines', ->
4545
a,b,c
4646
d,e,f
4747
# comment
48-
''', comment: '#', (err, data, {comment_lines}) ->
48+
''', comment: '#', (err, records, {comment_lines}) ->
4949
comment_lines.should.eql 1 unless err
5050
next err
5151

@@ -54,6 +54,6 @@ describe 'info comment_lines', ->
5454
# comment
5555
a,b,c
5656
d,e,f
57-
''', comment: '#', (err, data, {comment_lines}) ->
57+
''', comment: '#', (err, records, {comment_lines}) ->
5858
comment_lines.should.eql 1 unless err
5959
next err

packages/csv-parse/test/info.empty_lines.coffee

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { parse } from '../lib/index.js'
44
describe 'info empty_lines', ->
55

66
it 'no lines', (next) ->
7-
parse '', (err, data, {empty_lines}) ->
7+
parse '', (err, records, {empty_lines}) ->
88
empty_lines.should.eql 0
99
next()
1010

1111
it 'no empty lines', (next) ->
1212
parse '''
1313
a,b,c
1414
d,e,f
15-
''', (err, data, {empty_lines}) ->
15+
''', (err, records, {empty_lines}) ->
1616
empty_lines.should.eql 0
1717
next()
1818

@@ -21,7 +21,7 @@ describe 'info empty_lines', ->
2121
a,b,c
2222
2323
d,e,f
24-
''', skip_empty_lines: true, (err, data, {empty_lines}) ->
24+
''', skip_empty_lines: true, (err, records, {empty_lines}) ->
2525
empty_lines.should.eql 1
2626
next()
2727

@@ -30,7 +30,7 @@ describe 'info empty_lines', ->
3030
a,b,c
3131
d,e,f
3232
33-
''', (err, data, {empty_lines}) ->
33+
''', (err, records, {empty_lines}) ->
3434
empty_lines.should.eql 1
3535
next()
3636

@@ -39,7 +39,7 @@ describe 'info empty_lines', ->
3939
4040
a,b,c
4141
d,e,f
42-
''', (err, data, {empty_lines}) ->
42+
''', (err, records, {empty_lines}) ->
4343
err.message.should.eql 'Invalid Record Length: expect 1, got 3 on line 2'
4444
empty_lines.should.eql 0
4545
next()
@@ -49,6 +49,6 @@ describe 'info empty_lines', ->
4949
a,b,c
5050
d,e,f
5151
# comment
52-
''', (err, data, {empty_lines}) ->
52+
''', (err, records, {empty_lines}) ->
5353
empty_lines.should.eql 0
5454
next()

0 commit comments

Comments
 (0)