-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtestCsvIn.js
148 lines (133 loc) · 4.32 KB
/
testCsvIn.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
140
141
142
143
144
145
146
147
148
const Excel = require('../excel');
const filename = process.argv[2];
const wb = new Excel.Workbook();
let passed = true;
const assert = function(value, failMessage, passMessage) {
if (!value) {
if (failMessage) {
console.log(failMessage);
}
passed = false;
} else if (passMessage) {
console.log(passMessage);
}
};
// const assertEqual = function(address, name, value, expected) {
// assert(
// _.isEqual(value, expected),
// `Expected Cell[${address}] ${name} to be ${JSON.stringify(
// expected
// )}, was ${JSON.stringify(value)}`
// );
// };
const assertDate = function(address, cell, expected) {
assert(
cell.type === Excel.ValueType.Date,
`expected ${address} type to be Date, was ${cell.type}`
);
assert(
cell.value instanceof Date,
`expected value ${address} to be a Date, was ${cell.value}`
);
const {value} = cell;
assert(
value.getYear() === expected.getYear(),
`expected ${address} Year to be ${expected.getYear()}, was ${value.getYear()}`
);
assert(
value.getMonth() === expected.getMonth(),
`expected ${address} Month to be ${expected.getMonth()}, was ${value.getMonth()}`
);
assert(
value.getDay() === expected.getDay(),
`expected ${address} Day to be ${expected.getDay()}, was ${value.getDay()}`
);
assert(
value.getHours() === expected.getHours(),
`expected ${address} Hour to be ${expected.getHours()}, was ${value.getHours()}`
);
assert(
value.getMinutes() === expected.getMinutes(),
`expected ${address} Minute to be ${expected.getMinutes()}, was ${value.getMinutes()}`
);
assert(
value.getSeconds() === expected.getSeconds(),
`expected ${address} Second to be ${expected.getSeconds()}, was ${value.getSeconds()}`
);
};
const options = {
dateFormats: ['DD/MM/YYYY HH:mm:ss'],
};
// assuming file created by testBookOut
wb.csv.readFile(filename, options).then(() => {
const ws = wb.getWorksheet();
assert(ws, 'Expected to find at least one worksheet');
assert(ws.getCell('A2').value === 7, 'Expected A2 == 7');
assert(
ws.getCell('A2').type === Excel.ValueType.Number,
`expected A2 type to be Number, was ${ws.getCell('A2').type}`
);
assert(
ws.getCell('B2').value === 'Hello, World!',
`Expected B2 == "Hello, World!", was "${ws.getCell('B2').value}"`
);
assert(
ws.getCell('B2').type === Excel.ValueType.String,
`expected B2 type to be String, was ${ws.getCell('B2').type}`
);
assert(
Math.abs(ws.getCell('C2').value + 5.55) < 0.000001,
`Expected C2 == -5.55, was ${ws.getCell('C2').value}`
);
assert(
ws.getCell('C2').type === Excel.ValueType.Number,
`expected C2 type to be Number, was ${ws.getCell('C2').type}`
);
const expected = new Date(2015, 2, 10, 7, 8, 9);
assertDate('D2', ws.getCell('D2'), expected);
assert(ws.getCell('C5').value === 3, 'Expected C5 == 3');
assert(
ws.getCell('C5').type === Excel.ValueType.Number,
`expected C5 type to be Number, was ${ws.getCell('C5').type}`
);
assert(ws.getCell('A7').value === 1, 'Expected A7 == 1');
assert(
ws.getCell('A7').type === Excel.ValueType.Number,
`expected A7 type to be Number, was ${ws.getCell('A7').type}`
);
assert(ws.getCell('B7').value === 2, 'Expected B7 == 2');
assert(
ws.getCell('B7').type === Excel.ValueType.Number,
`expected B7 type to be Number, was ${ws.getCell('B7').type}`
);
assert(
ws.getCell('C7').value === null,
`Expected C7 == null, was ${ws.getCell('C7').value}`
);
assert(
ws.getCell('C7').type === Excel.ValueType.Null,
`expected C7 type to be Null, was ${ws.getCell('C7').type}`
);
assert(ws.getCell('D7').value === 4, 'Expected D7 == 4');
assert(
ws.getCell('D7').type === Excel.ValueType.Number,
`expected D7 type to be Number, was ${ws.getCell('D7').type}`
);
assert(
ws.getCell('A10').value === '<',
`Expected A10 to be "<", was "${ws.getCell('A10').value}"`
);
assert(
ws.getCell('B10').value === '>',
`Expected A10 to be ">", was "${ws.getCell('B10').value}"`
);
assert(
ws.getCell('C10').value === '<a>',
`Expected A10 to be "<a>", was "${ws.getCell('C10').value}"`
);
assert(
ws.getCell('D10').value === '><',
`Expected A10 to be "><", was "${ws.getCell('D10').value}"`
);
assert(passed, 'Something went wrong', 'All tests passed!');
});