blob: c98218037264e8e5d7c7ffd59847ae1fe638748d [file] [log] [blame]
// NOTES:
// - the errors actually still need to be reviewed to check that they
// are fully correct interpretations of the IDLs
var wp = process.env.JSCOV ? require("../lib-cov/webidl2") : require("../lib/webidl2")
, expect = require("expect.js")
, pth = require("path")
, fs = require("fs")
;
describe("Parses all of the invalid IDLs to check that they blow up correctly", function () {
var dir = pth.join(__dirname, "invalid/idl")
, skip = {}
, idls = fs.readdirSync(dir)
.filter(function (it) { return (/\.w?idl$/).test(it) && !skip[it]; })
.map(function (it) { return pth.join(dir, it); })
, errors = idls.map(function (it) { return pth.join(__dirname, "invalid", "json", pth.basename(it).replace(/\.w?idl/, ".json")); })
;
for (var i = 0, n = idls.length; i < n; i++) {
var idl = idls[i], error = JSON.parse(fs.readFileSync(errors[i], "utf8"));
var func = (function (idl, err) {
return function () {
var error;
try {
var ast = wp.parse(fs.readFileSync(idl, "utf8"));
console.log(JSON.stringify(ast, null, 4));
}
catch (e) {
error = e;
}
finally {
expect(error).to.be.ok();
expect(error.message).to.equal(err.message);
expect(error.line).to.equal(err.line);
}
};
}(idl, error));
it("should produce the right error for " + idl, func);
}
});