131 lines
No EOL
17 KiB
JavaScript
131 lines
No EOL
17 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var rowSplit_1 = require("./rowSplit");
|
|
var Converter_1 = require("./Converter");
|
|
var assert = require("assert");
|
|
describe("Test delimiters", function () {
|
|
var getDelimiter = function (str, opt) {
|
|
return rowSplit_1.RowSplit.prototype["getDelimiter"].call({
|
|
conv: {
|
|
parseParam: {
|
|
delimiter: opt.delimiter
|
|
}
|
|
}
|
|
}, str);
|
|
};
|
|
it("should return the explicitly specified delimiter", function () {
|
|
var delimiter = ";";
|
|
var rowStr = "a;b;c";
|
|
var returnedDelimiter = getDelimiter(rowStr, { delimiter: ";" });
|
|
assert.equal(returnedDelimiter, delimiter);
|
|
});
|
|
it("should return the autodetected delimiter if 'auto' specified", function () {
|
|
var rowStr = "a;b;c";
|
|
var returnedDelimiter = getDelimiter(rowStr, { delimiter: "auto" });
|
|
assert(returnedDelimiter === ";");
|
|
});
|
|
it("should return the ',' delimiter if delimiter cannot be specified, in case of 'auto'", function () {
|
|
var rowStr = "abc";
|
|
var returnedDelimiter = getDelimiter(rowStr, { delimiter: "auto" });
|
|
assert(returnedDelimiter === ",");
|
|
});
|
|
it("should accetp an array with potential delimiters", function () {
|
|
var rowStr = "a$b$c";
|
|
var returnedDelimiter = getDelimiter(rowStr, { delimiter: [",", ";", "$"] });
|
|
assert(returnedDelimiter === '$');
|
|
});
|
|
});
|
|
describe("ParseMultiLine function", function () {
|
|
var rowSplit = new rowSplit_1.RowSplit(new Converter_1.Converter());
|
|
var func = function (lines) {
|
|
return rowSplit.parseMultiLines(lines);
|
|
};
|
|
it("should convert lines to csv lines", function () {
|
|
var lines = [
|
|
"a,b,c,d",
|
|
"hello,world,csvtojson,abc",
|
|
"1,2,3,4"
|
|
];
|
|
var res = func(lines);
|
|
assert.equal(res.rowsCells.length, 3);
|
|
assert.equal(res.partial, "");
|
|
});
|
|
it("should process line breaks", function () {
|
|
var lines = [
|
|
"a,b,c",
|
|
'15",hello,"ab',
|
|
"cde\"",
|
|
"\"b\"\"b\",cc,dd"
|
|
];
|
|
var res = func(lines);
|
|
assert.equal(res.rowsCells.length, 3);
|
|
assert.equal(res.rowsCells[1][0], "15\"");
|
|
assert.equal(res.rowsCells[1][2], "ab\ncde");
|
|
assert.equal(res.rowsCells[2][0], "b\"b");
|
|
assert.equal(res.partial, "");
|
|
});
|
|
it("should return partial if line not closed", function () {
|
|
var lines = [
|
|
"a,b,c",
|
|
'15",hello,"ab',
|
|
"d,e,f"
|
|
];
|
|
var res = func(lines);
|
|
assert.equal(res.rowsCells.length, 1);
|
|
assert.equal(res.partial, "15\",hello,\"ab\nd,e,f\n");
|
|
});
|
|
});
|
|
describe("RowSplit.parse function", function () {
|
|
var rowSplit = new rowSplit_1.RowSplit(new Converter_1.Converter());
|
|
var func = function (str) {
|
|
return rowSplit.parse(str);
|
|
};
|
|
it("should split complete csv line", function () {
|
|
var str = "hello,world,csvtojson,awesome";
|
|
var res = func(str);
|
|
assert.equal(res.cells.length, 4);
|
|
assert.equal(res.closed, true);
|
|
});
|
|
it("should split incomplete csv line", function () {
|
|
var str = "hello,world,\"csvtojson,awesome";
|
|
var res = func(str);
|
|
assert.equal(res.closed, false);
|
|
});
|
|
it("should allow multiple line", function () {
|
|
var str = "\"he\"llo\",world,\"csvtojson,a\"\nwesome\"";
|
|
var res = func(str);
|
|
assert.equal(res.closed, true);
|
|
assert.equal(res.cells[2], 'csvtojson,a"\nwesome');
|
|
});
|
|
it("should allow blank quotes", function () {
|
|
var data = "a|^^|^b^";
|
|
var rowSplit = new rowSplit_1.RowSplit(new Converter_1.Converter({
|
|
delimiter: '|',
|
|
quote: '^',
|
|
noheader: true
|
|
}));
|
|
var res = rowSplit.parse(data);
|
|
assert.equal(res.cells[1], "");
|
|
});
|
|
it("should allow blank quotes in quotes", function () {
|
|
var data = 'a,"hello,this,"", test"';
|
|
var rowSplit = new rowSplit_1.RowSplit(new Converter_1.Converter({
|
|
noheader: true
|
|
}));
|
|
var res = rowSplit.parse(data);
|
|
assert.equal(res.cells[1], 'hello,this,", test');
|
|
});
|
|
it("should smart detect if an initial quote is only part of value ", function () {
|
|
var data = '"Weight" (kg),Error code,"Height" (m)';
|
|
var rowSplit = new rowSplit_1.RowSplit(new Converter_1.Converter({
|
|
noheader: true
|
|
}));
|
|
var res = rowSplit.parse(data);
|
|
assert.equal(res.cells.length, 3);
|
|
assert(res.closed);
|
|
assert.equal(res.cells[0], '"Weight" (kg)');
|
|
assert.equal(res.cells[1], 'Error code');
|
|
assert.equal(res.cells[2], '"Height" (m)');
|
|
});
|
|
});
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiL1VzZXJzL2t4aWFuZy93b3JrL3Byb2plY3RzL2NzdjJqc29uL3NyYy9yb3dTcGxpdC50ZXN0LnRzIiwic291cmNlcyI6WyIvVXNlcnMva3hpYW5nL3dvcmsvcHJvamVjdHMvY3N2Mmpzb24vc3JjL3Jvd1NwbGl0LnRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx1Q0FBeUU7QUFDekUseUNBQXdDO0FBQ3hDLElBQU0sTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUVqQyxRQUFRLENBQUMsaUJBQWlCLEVBQUU7SUFDMUIsSUFBTSxZQUFZLEdBQUcsVUFBQyxHQUFHLEVBQUUsR0FBcUM7UUFDOUQsT0FBTyxtQkFBUSxDQUFDLFNBQVMsQ0FBQyxjQUFjLENBQUMsQ0FBQyxJQUFJLENBQUM7WUFDN0MsSUFBSSxFQUFFO2dCQUNKLFVBQVUsRUFBRTtvQkFDVixTQUFTLEVBQUUsR0FBRyxDQUFDLFNBQVM7aUJBQ3pCO2FBQ0Y7U0FDRixFQUFFLEdBQUcsQ0FBQyxDQUFDO0lBQ1YsQ0FBQyxDQUFBO0lBRUQsRUFBRSxDQUFD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