-
Notifications
You must be signed in to change notification settings - Fork 0
/
deno.test.ts
65 lines (60 loc) · 1.45 KB
/
deno.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
import { assertEquals } from "https://deno.land/std@0.220.0/assert/assert_equals.ts";
import withWith from "./src/index.ts";
Deno.test("lifter", () => {
const hello = 0;
let general = "kenobi";
withWith(
{ hello: () => "there" },
() => {
// @ts-ignore Arguments must only be for satisfying types.
assertEquals(typeof hello === "function", true);
// @ts-ignore Arguments must only be for satisfying types.
assertEquals(hello(), "there");
// @ts-ignore Arguments must only be for satisfying types.
assertEquals(general, "kenobi");
// @ts-ignore Arguments must only be for satisfying types.
general = "skywalker";
// @ts-ignore Arguments must only be for satisfying types.
assertEquals(general, "skywalker");
},
{ lifter: (data) => eval(data.eval) }
);
assertEquals(hello, 0);
});
Deno.test("return value", () => {
assertEquals(
withWith(
{ value: () => 2 + 2 },
({ value }) => {
return value();
},
{ lifter: (data) => eval(data.eval) }
),
4
);
});
Deno.test("binding", () => {
assertEquals(
withWith(
{},
function () {
return this;
},
{ binding: { exists: "yes" } }
),
{ exists: "yes" }
);
});
Deno.test("array", () => {
assertEquals(
withWith(
[1, 2, 3],
() => {
// @ts-ignore Arguments must only be for satisfying types.
return toString();
},
{ binding: { exists: "yes" } }
),
"1,2,3"
);
});