2013-10-29 18:50:54 +00:00
|
|
|
/* vim: set ts=2: */
|
2013-10-26 20:20:19 +00:00
|
|
|
var CFB;
|
|
|
|
var fs = require('fs');
|
|
|
|
describe('source', function() { it('should load', function() { CFB = require('./'); }); });
|
2013-10-29 18:50:54 +00:00
|
|
|
|
2014-11-03 04:02:42 +00:00
|
|
|
var ex = [".xls",".doc",".ppt"];
|
|
|
|
if(process.env.FMTS) ex=process.env.FMTS.split(":").map(function(x){return x[0]==="."?x:"."+x;});
|
|
|
|
if(process.env.FMTS === "full") process.env.FMTS = ex.join(":");
|
|
|
|
if(process.env.FMTS) ex=process.env.FMTS.split(":").map(function(x){return x[0]==="."?x:"."+x;});
|
|
|
|
|
|
|
|
var ffunc = function(x){return (ex.indexOf(x.substr(-4))>=0 || ex.indexOf(x.substr(-3))>=0) && fails.indexOf(x) === -1;};
|
2014-05-20 17:43:03 +00:00
|
|
|
var fails = fs.existsSync('./fails.lst') ? fs.readFileSync('./fails.lst', 'utf-8').split("\n") : [];
|
2014-06-24 04:00:39 +00:00
|
|
|
var files = fs.readdirSync('test_files').filter(ffunc);
|
|
|
|
var f2011 = fs.readdirSync('test_files/2011').filter(ffunc);
|
|
|
|
var f2013 = fs.readdirSync('test_files/2013').filter(ffunc);
|
2014-11-03 04:02:42 +00:00
|
|
|
var fpres = fs.readdirSync('test_files_pres').filter(ffunc);
|
2014-05-20 17:43:03 +00:00
|
|
|
|
|
|
|
var dir = "./test_files/";
|
2013-10-29 18:50:54 +00:00
|
|
|
|
|
|
|
function parsetest(x, cfb) {
|
|
|
|
describe(x + ' should have basic parts', function() {
|
|
|
|
it('should find relative path', function() {
|
2014-11-03 04:02:42 +00:00
|
|
|
switch(x.substr(-4)) {
|
|
|
|
case '.xls': if(!cfb.find('Workbook') && !cfb.find('Book')) throw new Error("Cannot find workbook for " + x); break;
|
|
|
|
case '.ppt': if(!cfb.find('PowerPoint Document')) throw new Error("Cannot find presentation for " + x); break;
|
|
|
|
case '.doc': if(!cfb.find('WordDocument') && !cfb.find('Word Document')) throw new Error("Cannot find doc for " + x); break;
|
|
|
|
}
|
2013-10-29 18:50:54 +00:00
|
|
|
});
|
|
|
|
it('should find absolute path', function() {
|
2014-11-03 04:02:42 +00:00
|
|
|
switch(x.substr(-4)) {
|
|
|
|
case '.xls': if(!cfb.find('/Workbook') && !cfb.find('/Book')) throw new Error("Cannot find workbook for " + x); break;
|
|
|
|
case '.ppt': if(!cfb.find('/PowerPoint Document')) throw new Error("Cannot find presentation for " + x); break;
|
|
|
|
case '.doc': if(!cfb.find('/WordDocument') && !cfb.find('/Word Document')) throw new Error("Cannot find doc for " + x); break;
|
|
|
|
}
|
2013-10-29 18:50:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('should parse test files', function() {
|
|
|
|
files.forEach(function(x) {
|
2013-10-26 20:20:19 +00:00
|
|
|
it('should parse ' + x, function() {
|
|
|
|
var cfb = CFB.read('./test_files/' + x, {type: "file"});
|
2013-10-29 18:50:54 +00:00
|
|
|
parsetest(x, cfb);
|
2013-10-26 20:20:19 +00:00
|
|
|
});
|
|
|
|
});
|
2014-11-03 04:02:42 +00:00
|
|
|
fpres.forEach(function(x) {
|
|
|
|
it('should parse ' + x, function() {
|
|
|
|
var cfb = CFB.read('./test_files_pres/' + x, {type: "file"});
|
|
|
|
parsetest(x, cfb);
|
|
|
|
});
|
|
|
|
});
|
2014-05-20 17:43:03 +00:00
|
|
|
f2011.forEach(function(x) {
|
|
|
|
it('should parse ' + x, function() {
|
|
|
|
var cfb = CFB.read('./test_files/2011/' + x, {type: "file"});
|
|
|
|
parsetest(x, cfb);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
f2013.forEach(function(x) {
|
|
|
|
it('should parse ' + x, function() {
|
|
|
|
var cfb = CFB.read('./test_files/2013/' + x, {type: "file"});
|
|
|
|
parsetest(x, cfb);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var cp = 'custom_properties.xls'
|
|
|
|
|
|
|
|
describe('input formats', function() {
|
|
|
|
it('should read binary strings', function() {
|
|
|
|
CFB.read(fs.readFileSync(dir + '/' + cp, 'binary'), {type: 'binary'});
|
|
|
|
});
|
|
|
|
it('should read base64 strings', function() {
|
|
|
|
CFB.read(fs.readFileSync(dir + '/' + cp, 'base64'), {type: 'base64'});
|
|
|
|
});
|
2014-06-24 04:00:39 +00:00
|
|
|
it('should read buffers', function() {
|
|
|
|
CFB.read(fs.readFileSync(dir + '/' + cp), {type: 'buffer'});
|
|
|
|
});
|
2013-10-26 20:20:19 +00:00
|
|
|
});
|