sheetjs/packages/ssf/test/comma.js

22 lines
770 B
JavaScript
Raw Permalink Normal View History

/* vim: set ts=2: */
2017-03-12 07:34:36 +00:00
/*jshint loopfunc:true, mocha:true, node:true */
var SSF = require('../');
2017-03-12 07:34:36 +00:00
var fs = require('fs');
var data = fs.readFileSync('./test/comma.tsv','utf8').split("\n");
function doit(w, headers) {
it(headers[w], function() {
for(var j=1;j<data.length;++j) {
if(!data[j]) continue;
var d = data[j].replace(/#{255}/g,"").split("\t");
var expected = d[w].replace("|", ""), actual;
try { actual = SSF.format(headers[w], Number(d[0]), {}); } catch(e) { }
2017-03-12 07:34:36 +00:00
if(actual != expected && d[w][0] !== "|") throw new Error([actual, expected, w, headers[w],d[0],d].join("|"));
}
});
}
describe('comma formats', function() {
var headers = data[0].split("\t");
for(var w = 1; w < headers.length; ++w) doit(w, headers);
});