55 lines
6.5 KiB
JavaScript
55 lines
6.5 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
var Converter_1 = require("../src/Converter");
|
||
|
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_1.Converter({});
|
||
|
conv.on("error", function (err) {
|
||
|
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_1.Converter({
|
||
|
checkColumn: true
|
||
|
});
|
||
|
var tested = false;
|
||
|
conv.on("error", function (err) {
|
||
|
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_1.Converter({
|
||
|
checkColumn: true,
|
||
|
alwaysSplitAtEOL: true,
|
||
|
});
|
||
|
var tested = false;
|
||
|
conv.on("error", function (err) {
|
||
|
if (tested === false) {
|
||
|
assert(err.err === "column_mismatched");
|
||
|
tested = true;
|
||
|
}
|
||
|
});
|
||
|
conv.on('done', function () {
|
||
|
assert(tested);
|
||
|
done();
|
||
|
});
|
||
|
rs.pipe(conv);
|
||
|
});
|
||
|
});
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiL1VzZXJzL2t4aW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