-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
139 lines (109 loc) · 4.37 KB
/
test.js
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const dotest = require ('dotest');
const app = require ('./');
const customHead = ['Test', 'Times', 'Ahead'];
function testFileNohead (file, test) {
app (file, (err, data) => {
test (err)
.isArray ('fail', 'data', data)
.isNotEmpty ('fail', 'data', data)
.isArray ('fail', 'data[0]', data && data[0])
.isExactly ('fail', 'data[0][0]', data && data[0] && data[0][0], 'One')
.isExactly ('fail', 'data[0][1]', data && data[0] && data[0][1], 'Two')
.isExactly ('fail', 'data[0][2]', data && data[0] && data[0][2], 'Three')
.isArray ('fail', 'data[1]', data && data[1])
.isExactly ('fail', 'data[1][0]', data && data[1] && data[1][0], 'Hello')
.isExactly ('fail', 'data[1][1]', data && data[1] && data[1][1], 'World')
.isExactly ('fail', 'data[1][2]', data && data[1] && data[1][2], '!!')
.done();
});
}
function testFileAuto (head, file, test) {
app (head, file, (err, data) => {
test (err)
.isArray ('fail', 'data', data)
.isNotEmpty ('fail', 'data', data)
.isObject ('fail', 'data[0]', data && data[0])
.isExactly ('fail', 'data[0].One', data && data[0] && data[0].One, 'Hello')
.isExactly ('fail', 'data[0].Two', data && data[0] && data[0].Two, 'World')
.isExactly ('fail', 'data[0].Three', data && data[0] && data[0].Three, '!!')
.done();
});
}
function testFileCustom (head, file, test) {
app (head, file, (err, data) => {
test (err)
.isArray ('fail', 'data', data)
.isNotEmpty ('fail', 'data', data)
.isObject ('fail', 'data[0]', data && data[0])
.isExactly ('fail', 'data[0].Test', data && data[0] && data[0].Test, 'One')
.isExactly ('fail', 'data[0].Times', data && data[0] && data[0].Times, 'Two')
.isExactly ('fail', 'data[0].Ahead', data && data[0] && data[0].Ahead, 'Three')
.isObject ('fail', 'data[1]', data && data[1])
.isExactly ('fail', 'data[1].Test', data && data[1] && data[1].Test, 'Hello')
.isExactly ('fail', 'data[1].Times', data && data[1] && data[1].Times, 'World')
.isExactly ('fail', 'data[1].Ahead', data && data[1] && data[1].Ahead, '!!')
.done();
});
}
dotest.add ('Module', test => {
test()
.isFunction ('fail', 'exports', app)
.done ();
});
dotest.add ('Comma-quoted - without head - dos linebreaks', test => {
testFileNohead ('./test/test.comma-quoted-dos.csv', test);
});
dotest.add ('Comma-quoted - without head', test => {
testFileNohead ('./test/test.comma-quoted.csv', test);
});
dotest.add ('Comma-quoted - auto head', test => {
testFileAuto (true, './test/test.comma-quoted.csv', test);
});
dotest.add ('Comma-quoted - custom head', test => {
testFileCustom (customHead, './test/test.comma-quoted.csv', test);
});
dotest.add ('Comma-single-quoted - without head', test => {
testFileNohead ('./test/test.comma-single-quoted.csv', test);
});
dotest.add ('Comma-single-quoted - auto head', test => {
testFileAuto (true, './test/test.comma-single-quoted.csv', test);
});
dotest.add ('Comma-single-quoted - custom head', test => {
testFileCustom (customHead, './test/test.comma-single-quoted.csv', test);
});
dotest.add ('Semi-quoted - without head', test => {
testFileNohead ('./test/test.semi-quoted.csv', test);
});
dotest.add ('Semi-quoted - auto head', test => {
testFileAuto (true, './test/test.semi-quoted.csv', test);
});
dotest.add ('Semi-quoted - custom head', test => {
testFileCustom (customHead, './test/test.semi-quoted.csv', test);
});
dotest.add ('Semi-single-quoted - without head', test => {
testFileNohead ('./test/test.semi-single-quoted.csv', test);
});
dotest.add ('Semi-single-quoted - auto head', test => {
testFileAuto (true, './test/test.semi-single-quoted.csv', test);
});
dotest.add ('Semi-single-quoted - custom head', test => {
testFileCustom (customHead, './test/test.semi-single-quoted.csv', test);
});
dotest.add ('Error - invalid file', test => {
app ('./invalid.file', (err, data) => {
test()
.isError ('fail', 'err', err)
.isUndefined ('fail', 'data', data)
.done();
});
});
dotest.add ('Error - cannot detect line format', test => {
app ('./test/test.invalid-line-format.csv', (err, data) => {
test()
.isError ('fail', 'err', err)
.isExactly ('fail', 'err.message', err && err.message, 'cannot detect line format')
.isUndefined ('fail', 'data', data)
.done();
});
});
dotest.run ();