Skip to content

Commit

Permalink
Start some consistency checks
Browse files Browse the repository at this point in the history
  • Loading branch information
foolip committed Oct 27, 2020
1 parent 1d9d4a8 commit 77a5950
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/idl/consistency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const assert = require('assert');

const idl = require('@webref/idl');

describe.only('Web IDL consistency', () => {
const dfns = new Map();
const includes = [];
const partials = [];

it('unique definitions', async () => {
const all = await idl.parseAll();

for (const [spec, ast] of Object.entries(all)) {
for (const dfn of ast) {
if (dfn.partial) {
partials.push(dfn);
} else if (dfn.type === 'includes') {
includes.push(dfn);
} else {
assert(dfn.name, `definition with no name in ${spec}`);
assert(!dfns.has(dfn.name), `duplicate definition of ${dfn.type} ${dfn.name}`);
dfns.set(dfn.name, dfn);
}
}
}
});

it('unique members', () => {
for (const dfn of dfns.values()) {
if (!dfn.members) {
continue;
}
// TODO
}
});

it('inheritance', () => {
for (const dfn of dfns.values()) {
if (dfn.inheritance) {
const parent = dfns.get(dfn.inheritance);
assert(parent, `TODO: ${dfn.name} ${dfn.inheritance}`);
assert.strictEqual(dfn.type, parent.type, 'inheritance from wrong type');
}
switch (dfn.type) {
case 'callback':
case 'callback interface':
case 'dictionary':
case 'enum':
case 'interface':
case 'interface mixin':
break;
case 'namespace':
case 'typedef':
break;
default:
assert(false, `unknown definition type ${dfn.type}`)
}
}
});

it('includes', () => {
for (const include of includes) {
assert(include.target);
const target = dfns.get(include.target);
assert(target);
assert.strictEqual(target.type, 'interface');
assert(include.includes);
const mixin = dfns.get(include.includes);
assert(mixin);
assert.strictEqual(mixin.type, 'interface mixin');
}
});
});

0 comments on commit 77a5950

Please sign in to comment.