Skip to content

Commit 4930e05

Browse files
committed
Start some consistency checks
1 parent 00a481b commit 4930e05

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/idl/consistency.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const assert = require('assert');
2+
3+
const idl = require('@webref/idl');
4+
5+
describe.only('Web IDL consistency', () => {
6+
const dfns = new Map();
7+
const includes = [];
8+
const partials = [];
9+
10+
it('unique definitions', async () => {
11+
const all = await idl.parseAll();
12+
13+
for (const [spec, ast] of Object.entries(all)) {
14+
for (const dfn of ast) {
15+
if (dfn.partial) {
16+
partials.push(dfn);
17+
} else if (dfn.type === 'includes') {
18+
includes.push(dfn);
19+
} else {
20+
assert(dfn.name, `definition with no name in ${spec}`);
21+
assert(!dfns.has(dfn.name), `duplicate definition of ${dfn.type} ${dfn.name}`);
22+
dfns.set(dfn.name, dfn);
23+
}
24+
}
25+
}
26+
});
27+
28+
it('unique members', () => {
29+
for (const dfn of dfns.values()) {
30+
if (!dfn.members) {
31+
continue;
32+
}
33+
// TODO
34+
}
35+
});
36+
37+
it('inheritance', () => {
38+
for (const dfn of dfns.values()) {
39+
if (dfn.inheritance) {
40+
const parent = dfns.get(dfn.inheritance);
41+
assert(parent, `TODO: ${dfn.name} ${dfn.inheritance}`);
42+
assert.strictEqual(dfn.type, parent.type, 'inheritance from wrong type');
43+
}
44+
switch (dfn.type) {
45+
case 'callback':
46+
case 'callback interface':
47+
case 'dictionary':
48+
case 'enum':
49+
case 'interface':
50+
case 'interface mixin':
51+
break;
52+
case 'namespace':
53+
case 'typedef':
54+
break;
55+
default:
56+
assert(false, `unknown definition type ${dfn.type}`)
57+
}
58+
}
59+
});
60+
61+
it('includes', () => {
62+
for (const include of includes) {
63+
assert(include.target);
64+
const target = dfns.get(include.target);
65+
assert(target);
66+
assert.strictEqual(target.type, 'interface');
67+
assert(include.includes);
68+
const mixin = dfns.get(include.includes);
69+
assert(mixin);
70+
assert.strictEqual(mixin.type, 'interface mixin');
71+
}
72+
});
73+
});

0 commit comments

Comments
 (0)