-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
README_test.ts
39 lines (35 loc) · 1.13 KB
/
README_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
import { test } from "@cross/test";
import { assertEquals } from "@std/assert";
import { pipe } from "@core/pipe";
import * as rootMod from "./mod.ts";
import * as asyncMod from "./async/mod.ts";
import * as pipeMod from "./pipe/mod.ts";
import * as pipeAsyncMod from "./pipe/async/mod.ts";
await test("README case 1", () => {
const iter = rootMod.map([1, 2, 3], (v) => v * 2);
assertEquals(Array.from(iter), [2, 4, 6]);
});
await test("README case 2", async () => {
const iter = asyncMod.map([1, 2, 3], (v) => Promise.resolve(v * 2));
assertEquals(await Array.fromAsync(iter), [2, 4, 6]);
});
await test("README case 3", () => {
const iter = pipe(
[1, 2, 3],
pipeMod.map((v) => v * 2),
pipeMod.cycle,
pipeMod.take(10),
pipeMod.filter((v) => v % 2 === 0),
);
assertEquals(Array.from(iter), [2, 4, 6, 2, 4, 6, 2, 4, 6, 2]);
});
await test("README case 4", async () => {
const iter = pipe(
[1, 2, 3],
pipeAsyncMod.map((v) => v * 2),
pipeAsyncMod.cycle,
pipeAsyncMod.take(10),
pipeAsyncMod.filter((v) => v % 2 === 0),
);
assertEquals(await Array.fromAsync(iter), [2, 4, 6, 2, 4, 6, 2, 4, 6, 2]);
});