Skip to content

Commit fc3775f

Browse files
committed
Rewrite test options
1 parent 16ccc11 commit fc3775f

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

test/options.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const test = require('tape');
2+
const csv = require('../src/jquery.csv.js');
3+
const fixtures = require('./fixtures/fixtures.js');
4+
5+
const setup = () => {
6+
const fixtures = require('./fixtures/fixtures.js');
7+
return fixtures;
8+
};
9+
10+
const teardown = (fixtures) => {
11+
fixtures = {};
12+
};
13+
14+
test('Options - should parse using the default terminals', (t) => {
15+
let result = csv.toArray(fixtures.defaults_csv);
16+
let expect = fixtures.defaults_obj;
17+
t.deepEqual(result, expect);
18+
t.end();
19+
});
20+
21+
test('Options - should parse using a custom delimiter', (t) => {
22+
let options = {
23+
delimiter: '\''
24+
};
25+
26+
let result = csv.toArray(fixtures.delimiter_csv, options);
27+
let expect = fixtures.delimiter_obj;
28+
t.deepEqual(result, expect);
29+
t.end();
30+
});
31+
32+
test('Options - should parse using a custom separator', (t) => {
33+
let options = {
34+
separator: ';'
35+
};
36+
37+
let result = csv.toArray(fixtures.separator_csv, options);
38+
let expect = fixtures.separator_obj;
39+
t.deepEqual(result, expect);
40+
t.end();
41+
});
42+
43+
test('Options - should properly escape regex special chars', (t) => {
44+
let options = {
45+
separator: '|'
46+
};
47+
48+
let result = csv.toArray(fixtures.regex_csv, options);
49+
let expect = fixtures.regex_obj;
50+
t.deepEqual(result, expect);
51+
t.end();
52+
});
53+
54+
test('Options - should support custom terminals via toArrays()', (t) => {
55+
let options = {
56+
delimiter: '*',
57+
separator: ':'
58+
};
59+
60+
let result = csv.toArrays(fixtures.term_arrays_csv, options);
61+
let expect = fixtures.term_arrays_obj;
62+
t.deepEqual(result, expect);
63+
t.end();
64+
});
65+
66+
test('Options - should support custom terminals via toObjects()', (t) => {
67+
let options = {
68+
delimiter: '^',
69+
separator: '&'
70+
};
71+
72+
let result = csv.toObjects(fixtures.term_objects_csv, options);
73+
let expect = fixtures.term_objects_obj;
74+
t.deepEqual(result, expect);
75+
t.end();
76+
});

0 commit comments

Comments
 (0)