mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Adds esprima-based preprocessor.
This commit is contained in:
parent
bc3bcebde2
commit
bf52ff156d
15 changed files with 502 additions and 0 deletions
54
external/builder/test2.js
vendored
Normal file
54
external/builder/test2.js
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* jshint node:true */
|
||||
/* globals cat, cd, echo, ls */
|
||||
'use strict';
|
||||
|
||||
require('shelljs/make');
|
||||
|
||||
var p2 = require('./preprocessor2.js');
|
||||
var fs = require('fs');
|
||||
|
||||
var errors = 0;
|
||||
|
||||
cd(__dirname);
|
||||
cd('fixtures_esprima');
|
||||
ls('*-expected.*').forEach(function(expectationFilename) {
|
||||
var inFilename = expectationFilename.replace('-expected', '');
|
||||
var expectation = cat(expectationFilename).trim()
|
||||
.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 + '/../..',
|
||||
saveComments: true
|
||||
};
|
||||
var out;
|
||||
try {
|
||||
out = p2.preprocessPDFJSCode(ctx, input);
|
||||
} catch (e) {
|
||||
out = ('Error: ' + e.message).replace(/^/gm, '//');
|
||||
}
|
||||
if (out !== expectation) {
|
||||
echo('Assertion failed for ' + inFilename);
|
||||
echo('--------------------------------------------------');
|
||||
echo('EXPECTED:');
|
||||
echo(expectation);
|
||||
echo('--------------------------------------------------');
|
||||
echo('ACTUAL');
|
||||
echo(out);
|
||||
echo('--------------------------------------------------');
|
||||
echo();
|
||||
}
|
||||
});
|
||||
|
||||
if (errors) {
|
||||
echo('Found ' + errors + ' expectation failures.');
|
||||
} else {
|
||||
echo('All tests completed without errors.');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue