-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
}); |