-
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathweakMap.spec.ts
More file actions
104 lines (89 loc) · 2.73 KB
/
weakMap.spec.ts
File metadata and controls
104 lines (89 loc) · 2.73 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
102
103
104
import * as util from "../../util";
const initRefsTs = `
let ref = {};
let ref2 = () => {};
`;
test("weakMap constructor", () => {
util.testFunction`
${initRefsTs}
let mymap = new WeakMap([[ref, 1]]);
return mymap.get(ref);
`.expectToMatchJsResult();
});
test("weakMap iterable constructor", () => {
util.testFunction`
${initRefsTs}
let mymap = new WeakMap([[ref, 1], [ref2, 2]]);
return mymap.has(ref) && mymap.has(ref2);
`.expectToMatchJsResult();
});
test("weakMap iterable constructor map", () => {
util.testFunction`
${initRefsTs}
let mymap = new WeakMap(new Map([[ref, 1], [ref2, 2]]));
return mymap.has(ref) && mymap.has(ref2);
`.expectToMatchJsResult();
});
test("weakMap delete", () => {
util.testFunction`
${initRefsTs}
let mymap = new WeakMap([[ref, true], [ref2, true]]);
mymap.delete(ref2);
return mymap.has(ref) && !mymap.has(ref2);
`.expectToMatchJsResult();
});
test("weakMap get", () => {
util.testFunction`
${initRefsTs}
let mymap = new WeakMap([[ref, 1], [{}, 2]]);
return mymap.get(ref);
`.expectToMatchJsResult();
});
test("weakMap get missing", () => {
util.testFunction`
${initRefsTs}
let mymap = new WeakMap([[{}, true]]);
return mymap.get({});
`.expectToMatchJsResult();
});
test("weakMap has", () => {
util.testFunction`
${initRefsTs}
let mymap = new WeakMap([[ref, true]]);
return mymap.has(ref);
`.expectToMatchJsResult();
});
test("weakMap has false", () => {
util.testFunction`
${initRefsTs}
let mymap = new WeakMap([[ref, true]]);
return mymap.has(ref2);
`.expectToMatchJsResult();
});
test("weakMap has null", () => {
util.testFunction`
${initRefsTs}
let mymap = new WeakMap([[{}, true]]);
return mymap.has(null);
`.expectToMatchJsResult();
});
test("weakMap set", () => {
const init = `
${initRefsTs}
let mymap = new WeakMap();
mymap.set(ref, 5);
`;
util.testFunction(init + "return mymap.has(ref);").expectToMatchJsResult();
util.testFunction(init + "return mymap.get(ref)").expectToMatchJsResult();
});
test("weakMap has no map features (size)", () => {
util.testExpression("(new WeakMap() as any).size").expectToMatchJsResult();
});
test.each(["clear()", "keys()", "values()", "entries()", "forEach(() => {})"])(
"weakMap has no map features (%p)",
call => {
const testBuilder = util.testFunction(`(new WeakMap() as any).${call}`);
const luaResult = testBuilder.getLuaExecutionResult();
expect(luaResult.message).toContain("attempt to call a nil value");
}
);