forked from gpuweb/cts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idl_test.ts
27 lines (25 loc) · 935 Bytes
/
idl_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Fixture } from '../../common/framework/fixture.js';
import { assert } from '../../common/framework/util/util.js';
interface UnknownObject {
[k: string]: unknown;
}
export class IDLTest extends Fixture {
/**
* Asserts that an IDL interface has the expected members.
*/
// TODO: exp should allow sentinel markers for unnameable values, such as methods and attributes
// TODO: handle extensions
// TODO: check prototype chains (maybe as separate method)
assertMembers(act: UnknownObject, exp: UnknownObject) {
const expKeys = Object.keys(exp);
for (const k of expKeys) {
assert(k in act, () => `Expected key ${k} missing`);
assert(act[k] === exp[k], () => `Value of [${k}] was ${act[k]}, expected ${exp[k]}`);
}
const actKeys = Object.keys(act);
assert(
actKeys.length === expKeys.length,
() => `Had ${actKeys.length} keys, expected ${expKeys.length}`
);
}
}