Skip to content

Commit a461b81

Browse files
committed
Update csv.toArrays & csv.fromArrays tests
Added tests to ensure delimiters are being parsed/escaped properly.
1 parent e7ee235 commit a461b81

File tree

7 files changed

+41
-9
lines changed

7 files changed

+41
-9
lines changed

test/csv.from_arrays.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ const teardown = (fixtures) => {
1212
};
1313

1414
test('$.csv.fromArrays() - should be able to format multi-entry/multi-cell data set', (t) => {
15-
let result = csv.fromArrays(fixtures.arrays_obj);
16-
let expect = fixtures.arrays_csv;
15+
let result = csv.fromArrays(fixtures.arrays1_obj);
16+
let expect = fixtures.arrays1_csv;
17+
t.deepEqual(result, expect);
18+
t.end();
19+
});
20+
21+
test('$.csv.fromArrays() - should be able to format multi-entry/multi-cell data set with escaped delimiters', (t) => {
22+
let result = csv.fromArrays(fixtures.arrays2_obj);
23+
console.dir(result);
24+
let expect = fixtures.arrays2_csv;
1725
t.deepEqual(result, expect);
1826
t.end();
1927
});

test/csv.to_arrays.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ const teardown = (fixtures) => {
1212
};
1313

1414
test('$.csv.toArrays() - should be able to parse multi-entry/multi-cell input', (t) => {
15-
let result = csv.toArrays(fixtures.arrays_csv);
16-
let expect = fixtures.arrays_obj;
15+
let result = csv.toArrays(fixtures.arrays1_csv);
16+
let expect = fixtures.arrays1_obj;
1717
t.deepEqual(result, expect);
1818
t.end();
1919
});
2020

21-
test('$.csv.toArrays() - should be able to parse multi-entry/multi-cell input', (t) => {
22-
let result = csv.toArrays(fixtures.arrays_csv);
23-
let expect = fixtures.arrays_obj;
21+
test('$.csv.toArrays() - should be able to parse multi-entry/multi-cell input with escaped delimiters', (t) => {
22+
let result = csv.toArrays(fixtures.arrays2_csv);
23+
let expect = fixtures.arrays2_obj;
2424
t.deepEqual(result, expect);
2525
t.end();
2626
});
File renamed without changes.
File renamed without changes.

test/fixtures/arrays2.csv

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
All work,and no play,makes Jack,a dull boy...
2+
All work,and no play,"makes ""Jack",a dull boy...
3+
All work,and no play,makes Jack,a dull boy...
4+
All work,and no play,makes Jack,a dull boy...
5+
All work,and no play,makes Jack,"a ""dull"" boy..."
6+
All work,and no play,makes Jack,a dull boy...
7+
All work,and no play,makes Jack,a dull boy...
8+
All work,and no play,makes Jack,a dull boy...
9+
"All ""work",and no play,makes Jack,a dull boy...
10+
All work,and no play,makes Jack,a dull boy...

test/fixtures/arrays2.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
["All work","and no play","makes Jack","a dull boy..."],
3+
["All work","and no play","makes \"Jack","a dull boy..."],
4+
["All work","and no play","makes Jack","a dull boy..."],
5+
["All work","and no play","makes Jack","a dull boy..."],
6+
["All work","and no play","makes Jack","a \"dull\" boy..."],
7+
["All work","and no play","makes Jack","a dull boy..."],
8+
["All work","and no play","makes Jack","a dull boy..."],
9+
["All work","and no play","makes Jack","a dull boy..."],
10+
["All \"work","and no play","makes Jack","a dull boy..."],
11+
["All work","and no play","makes Jack","a dull boy..."]
12+
]

test/fixtures/fixtures.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ var fs = require('fs');
1414
var fixtures = {
1515
array_csv: csvFixture('array'),
1616
array_obj: jsonFixture('array'),
17-
arrays_csv: csvFixture('arrays'),
18-
arrays_obj: jsonFixture('arrays'),
17+
arrays1_csv: csvFixture('arrays1'),
18+
arrays1_obj: jsonFixture('arrays1'),
19+
arrays2_csv: csvFixture('arrays2'),
20+
arrays2_obj: jsonFixture('arrays2'),
1921
rfc1_csv: csvFixture('rfc1'),
2022
rfc1_obj: jsonFixture('rfc1'),
2123
rfc2_csv: csvFixture('rfc2'),

0 commit comments

Comments
 (0)