-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathinvoke.test.ts
95 lines (88 loc) · 1.57 KB
/
invoke.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
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
import { limitInvocations, once } from "./invoke.ts";
import { assertEquals, assertThrows } from "testing/asserts.ts";
Deno.test("once", () => {
once(() => {});
once(
() => {},
// @ts-expect-error
(_arg) => {},
);
once(
() => {},
() => {},
);
// @ts-expect-error
once(() => 0);
once(
() => 0,
() => 0,
);
once(
() => 0,
// @ts-expect-error
() => "",
);
once(
() => 0,
// @ts-expect-error
async () => 0,
);
once(async () => {});
// @ts-expect-error
once(async () => 0);
once(
async () => 0,
async () => 0,
);
once(
async () => 0,
() => 0,
);
// @ts-expect-error
once((_n: number) => {})();
once((_n: number) => {})(1);
// @ts-expect-error
once((_n: number) => {})(1, 2);
// @ts-expect-error
once((_a: number, _b: strin) => {})(1);
once((_a: number, _b: string) => {})(1, "a");
const _rn: number = once(
() => 1,
() => 2,
)();
// @ts-expect-error
const _rs: string = once(
() => 1,
() => 2,
)();
{
const f = once(
() => 1,
() => 2,
);
assertEquals(f(), 1);
assertEquals(f(), 2);
assertEquals(f(), 2);
}
});
Deno.test("limit", () => {
const f = limitInvocations(
() => "a",
2,
() => "b",
);
assertEquals(f(), "a");
assertEquals(f(), "a");
assertEquals(f(), "b");
const f3 = limitInvocations(
() => 0,
3,
() => {
throw Error("4th invoke");
},
);
assertEquals(f3(), 0);
assertEquals(f3(), 0);
assertEquals(f3(), 0);
assertThrows(() => f3(), Error, "4th invoke");
});