-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathunary.test.ts
32 lines (28 loc) · 1013 Bytes
/
unary.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
import unary from "./unary.ts";
import { assertEquals } from "testing/asserts.ts";
Deno.test("unary", async () => {
// @ts-expect-error
unary(() => {});
unary((_a: any) => {});
unary((_a?: any) => {});
unary((_a: any, _b?: any) => {});
// @ts-expect-error
unary((_a: any, _b: any) => {});
unary((..._args: any[]) => {});
unary((_a: any, ..._args: any[]) => {});
unary((_a?: any, ..._args: any[]) => {});
unary((_a: any, _b?: any, ..._args: any[]) => {});
// @ts-expect-error
unary((_a: any, _b: any, ..._args: any[]) => {});
const parseInt10 = unary(parseInt);
assertEquals(parseInt10("10"), 10);
// @ts-expect-error
assertEquals(parseInt10("10", 16), 10);
// @ts-expect-error
assertEquals(parseInt10(), NaN);
assertEquals(["1", "2", "3"].map(parseInt10), [1, 2, 3]);
const asyncTest = async (a: number, b = 2) =>
await new Promise<number>((res) => setTimeout(() => res(a * b)));
const asyncUnary = unary(asyncTest);
assertEquals(await asyncUnary(3), 6);
});