-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
compact_test.ts
42 lines (38 loc) · 1.25 KB
/
compact_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
import { test } from "@cross/test";
import { assertEquals } from "@std/assert";
import { assertType, type IsExact } from "@std/testing/types";
import { compact } from "./compact.ts";
await test("compact without undefined/null", () => {
const result = compact([1, 2, 3, 4, 5]);
const expected = [1, 2, 3, 4, 5];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<number>>>(true);
});
await test("compact with undefined", () => {
const result = compact([
undefined,
1,
2,
undefined,
3,
undefined,
4,
5,
undefined,
]);
const expected = [1, 2, 3, 4, 5];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<number>>>(true);
});
await test("compact with null", () => {
const result = compact([null, 1, 2, null, 3, null, 4, 5, null]);
const expected = [1, 2, 3, 4, 5];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<number>>>(true);
});
await test("compact with undefined/null", () => {
const result = compact([undefined, 1, 2, null, 3, undefined, 4, 5, null]);
const expected = [1, 2, 3, 4, 5];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<number>>>(true);
});