pdf.js/external/builder/test-fixtures_esprima.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-05-11 08:05:29 +09:00
'use strict';
var p2 = require('./preprocessor2.js');
var fs = require('fs');
2017-05-04 02:16:37 +09:00
var path = require('path');
2016-05-11 08:05:29 +09:00
var errors = 0;
2017-05-04 02:16:37 +09:00
var baseDir = path.join(__dirname, 'fixtures_esprima');
var files = fs.readdirSync(baseDir).filter(function (name) {
return /-expected\./.test(name);
}).map(function (name) {
return path.join(baseDir, name);
});
files.forEach(function(expectationFilename) {
2016-05-11 08:05:29 +09:00
var inFilename = expectationFilename.replace('-expected', '');
2017-05-04 02:16:37 +09:00
var expectation = fs.readFileSync(expectationFilename).toString().trim()
2016-05-11 08:05:29 +09:00
.replace(/__filename/g, fs.realpathSync(inFilename));
var input = fs.readFileSync(inFilename).toString();
var defines = {
TRUE: true,
FALSE: false,
OBJ: {obj: {i: 1}, j: 2},
TEXT: 'text'
};
var ctx = {
defines: defines,
rootPath: __dirname + '/../..',
};
var out;
try {
out = p2.preprocessPDFJSCode(ctx, input);
} catch (e) {
out = ('Error: ' + e.message).replace(/^/gm, '//');
}
if (out !== expectation) {
errors++;
2017-05-04 02:16:37 +09:00
console.log('Assertion failed for ' + inFilename);
console.log('--------------------------------------------------');
console.log('EXPECTED:');
console.log(expectation);
console.log('--------------------------------------------------');
console.log('ACTUAL');
console.log(out);
console.log('--------------------------------------------------');
console.log();
2016-05-11 08:05:29 +09:00
}
});
if (errors) {
2017-05-04 02:16:37 +09:00
console.error('Found ' + errors + ' expectation failures.');
process.exit(1);
2016-05-11 08:05:29 +09:00
} else {
2017-05-04 02:16:37 +09:00
console.log('All tests completed without errors.');
process.exit(0);
2016-05-11 08:05:29 +09:00
}