testErrorHandle.ts
1.55 KB
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
import {Converter} from "../src/Converter";
import CSVError from "../src/CSVError";
var assert = require("assert");
var fs = require("fs");
describe("Converter error handling", function() {
it("should handle quote not closed", function(done) {
var rs = fs.createReadStream(__dirname + "/data/dataWithUnclosedQuotes");
var conv = new Converter({});
conv.on("error", function(err:CSVError) {
assert(err.err === "unclosed_quote");
done();
});
rs.pipe(conv);
});
it ("should handle column number mismatched error", function(done) {
var rs = fs.createReadStream(__dirname + "/data/dataWithMismatchedColumn");
var conv = new Converter({
checkColumn:true
});
var tested = false;
conv.on("error", function(err:CSVError) {
if (tested === false) {
assert(err.err === "column_mismatched");
tested = true;
// done();
}
});
conv.on('done',function() {
assert(tested);
done();
});
rs.pipe(conv);
});
it("should treat quote not closed as column_mismatched when alwaysSplitAtEOL is true", function(done) {
var rs = fs.createReadStream(__dirname + "/data/dataWithUnclosedQuotes");
var conv = new Converter({
checkColumn:true,
alwaysSplitAtEOL:true,
});
var tested = false;
conv.on("error", function(err:CSVError) {
if (tested === false) {
assert(err.err === "column_mismatched");
tested = true;
}
});
conv.on('done',function() {
assert(tested);
done();
});
rs.pipe(conv);
});
});