Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"mocha": "5.0.0"
},
"scripts": {
"test": "mocha"
"test": "mocha",
"acquire": "node test/util/acquire.js"
},
"repository": "git://github.com/darobin/webidl2.js",
"repository": "git://github.com/w3c/webidl2.js",
"main": "index"
}
37 changes: 8 additions & 29 deletions test/invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,17 @@

"use strict";

const wp = require("../lib/webidl2");
const expect = require("expect");
const pth = require("path");
const { collect } = require("./util/collect");
const fs = require("fs");
const expect = require("expect");

describe("Parses all of the invalid IDLs to check that they blow up correctly", () => {
const dir = pth.join(__dirname, "invalid/idl");
const skip = {};
const idls = fs.readdirSync(dir)
.filter(it => (/\.w?idl$/).test(it) && !skip[it])
.map(it => pth.join(dir, it));

for (const idl of idls) {
const err = JSON.parse(fs.readFileSync(
pth.join(__dirname, "invalid", "json", pth.basename(idl).replace(/\.w?idl/, ".json")),
"utf8"
));

it(`should produce the right error for ${idl}`, () => {
let error;
try {
const ast = wp.parse(fs.readFileSync(idl, "utf8"));
console.log(JSON.stringify(ast, null, 4));
}
catch (e) {
error = e;
}
finally {
expect(error).toBeTruthy();
expect(error.message).toEqual(err.message);
expect(error.line).toEqual(err.line);
}
for (const test of collect("invalid", { expectError: true })) {
it(`should produce the right error for ${test.path}`, () => {
const err = test.readJSON();
expect(test.error).toBeTruthy();
expect(test.error.message).toEqual(err.message);
expect(test.error.line).toEqual(err.line);
});
}
});
26 changes: 4 additions & 22 deletions test/syntax.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
"use strict";

const wp = require("../lib/webidl2");
const { collect } = require("./util/collect");
const expect = require("expect");
const pth = require("path");
const fs = require("fs");
const jdp = require("jsondiffpatch");
const debug = true;

describe("Parses all of the IDLs to produce the correct ASTs", () => {
const dir = pth.join(__dirname, "syntax/idl");
const skip = {}; // use if we have a broken test
const idls = fs.readdirSync(dir)
.filter(it => (/\.widl$/).test(it) && !skip[it])
.map(it => pth.join(dir, it));

for (const idl of idls) {
const json = pth.join(__dirname, "syntax/json", pth.basename(idl).replace(".widl", ".json"));

it(`should produce the same AST for ${idl}`, () => {
for (const test of collect("syntax")) {
it(`should produce the same AST for ${test.path}`, () => {
try {
const optFile = pth.join(__dirname, "syntax/opt", pth.basename(json));
let opt = undefined;
if (fs.existsSync(optFile))
opt = JSON.parse(fs.readFileSync(optFile, "utf8"));
const diff = jdp.diff(JSON.parse(fs.readFileSync(json, "utf8")),
wp.parse(fs.readFileSync(idl, "utf8").replace(/\r\n/g, "\n"), opt));
if (diff && debug) console.log(JSON.stringify(diff, null, 4));
expect(diff).toBe(undefined);
expect(test.diff()).toBeFalsy();
}
catch (e) {
console.log(e.toString());
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/syntax/json/attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"inheritance": null,
"extAttrs": []
}
]
]
2 changes: 1 addition & 1 deletion test/syntax/json/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@
"inheritance": null,
"extAttrs": []
}
]
]
2 changes: 1 addition & 1 deletion test/syntax/json/dictionary-inherits.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@
"inheritance": "PaintOptions",
"extAttrs": []
}
]
]
2 changes: 1 addition & 1 deletion test/syntax/json/dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@
],
"extAttrs": []
}
]
]
2 changes: 1 addition & 1 deletion test/syntax/json/documentation-dos.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"inheritance": null,
"extAttrs": []
}
]
]
2 changes: 1 addition & 1 deletion test/syntax/json/documentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"inheritance": null,
"extAttrs": []
}
]
]
30 changes: 24 additions & 6 deletions test/syntax/json/enum.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
"type": "enum",
"name": "MealType",
"values": [
{ "type": "string", "value": "rice" },
{ "type": "string", "value": "noodles" },
{ "type": "string", "value": "other" }
{
"type": "string",
"value": "rice"
},
{
"type": "string",
"value": "noodles"
},
{
"type": "string",
"value": "other"
}
],
"extAttrs": []
},
Expand Down Expand Up @@ -99,9 +108,18 @@
"type": "enum",
"name": "AltMealType",
"values": [
{ "type": "string", "value": "rice" },
{ "type": "string", "value": "noodles" },
{ "type": "string", "value": "other" }
{
"type": "string",
"value": "rice"
},
{
"type": "string",
"value": "noodles"
},
{
"type": "string",
"value": "other"
}
],
"extAttrs": []
}
Expand Down
Loading