forked from web-platform-dx/web-features
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparse.test.ts
More file actions
101 lines (92 loc) · 2.83 KB
/
Copy pathparse.test.ts
File metadata and controls
101 lines (92 loc) · 2.83 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import assert from "node:assert/strict";
import { makeCompatSets, parseAuthoring } from "./parse.ts";
describe("makeCompatSets", function () {
it("from explicit compat sets", function () {
const set = makeCompatSets({
core: ["html.elements.a"],
modifier: ["api.HTMLAnchorElement"],
spare: ["html.elements.a.href.href_sms"],
});
assert.deepEqual(set.core, ["html.elements.a"]);
assert.deepEqual(set.modifier, ["api.HTMLAnchorElement"]);
assert.deepEqual(set.spare, ["html.elements.a.href.href_sms"]);
});
it("from compute_from and flat compat_features", function () {
const set = makeCompatSets(
[
"api.HTMLAnchorElement",
"html.elements.a",
"html.elements.a.href.href_sms",
],
["html.elements.a"],
);
assert.deepEqual(set.core, ["html.elements.a"]);
assert.deepEqual(set.modifier, []);
assert.deepEqual(set.spare, [
"api.HTMLAnchorElement",
"html.elements.a.href.href_sms",
]);
});
it("from compute_from and implicit keys", function () {
const set = makeCompatSets("a", ["html.elements.a"]);
assert.deepEqual(set.core, ["html.elements.a"]);
assert(set.spare.includes("api.HTMLAnchorElement"));
});
it("from flat compat_features", function () {
const set = makeCompatSets([
"api.HTMLAnchorElement",
"html.elements.a",
"html.elements.a.href.href_sms",
]);
assert.deepEqual(set.core, [
"api.HTMLAnchorElement",
"html.elements.a",
"html.elements.a.href.href_sms",
]);
});
it("from implicit keys", function () {
const set = makeCompatSets("a");
assert(set.core.includes("html.elements.a"));
});
it("from implicit keys, keylessly", function () {
const set = makeCompatSets("http3");
assert.equal(set.core.length, 0);
assert.equal(set.modifier.length, 0);
assert.equal(set.spare.length, 0);
});
it("keylessly", function () {
const set = makeCompatSets();
assert.deepEqual(set.core, []);
assert.deepEqual(set.modifier, []);
assert.deepEqual(set.spare, []);
});
it("throws if compute_from is not a strict subset of a feature's keys", function () {
assert.throws(() => {
makeCompatSets(["a", "b", "c"], ["d"]);
});
});
});
describe("parseAuthoring", function () {
it("throws with non-object inputs", function () {
assert.throws(
() => parseAuthoring("foo", null),
Error,
"expected throw for authored null",
);
assert.throws(
() => parseAuthoring("bar", undefined),
Error,
"expected throw for authored undefined",
);
assert.throws(
() => parseAuthoring("baz", 123),
Error,
"expected throw for authored number",
);
assert.throws(
() => parseAuthoring("quux", "somestring"),
Error,
"expected throw for authored string",
);
});
});