Skip to content

Commit 356fc69

Browse files
committed
test: use @cross/test instead
1 parent 2ce6a4e commit 356fc69

File tree

119 files changed

+2966
-3191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+2966
-3191
lines changed

README_test.ts

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
1+
import { test } from "@cross/test";
12
import { assertEquals } from "@std/assert";
23
import { pipe } from "@core/pipe";
34
import * as rootMod from "./mod.ts";
45
import * as asyncMod from "./async/mod.ts";
56
import * as pipeMod from "./pipe/mod.ts";
67
import * as pipeAsyncMod from "./pipe/async/mod.ts";
78

8-
Deno.test("README", async (t) => {
9-
await t.step("case 1", () => {
10-
const iter = rootMod.map([1, 2, 3], (v) => v * 2);
11-
assertEquals(Array.from(iter), [2, 4, 6]);
12-
});
9+
await test("README case 1", () => {
10+
const iter = rootMod.map([1, 2, 3], (v) => v * 2);
11+
assertEquals(Array.from(iter), [2, 4, 6]);
12+
});
1313

14-
await t.step("case 2", async () => {
15-
const iter = asyncMod.map([1, 2, 3], (v) => Promise.resolve(v * 2));
16-
assertEquals(await Array.fromAsync(iter), [2, 4, 6]);
17-
});
14+
await test("README case 2", async () => {
15+
const iter = asyncMod.map([1, 2, 3], (v) => Promise.resolve(v * 2));
16+
assertEquals(await Array.fromAsync(iter), [2, 4, 6]);
17+
});
1818

19-
await t.step("case 3", () => {
20-
const iter = pipe(
21-
[1, 2, 3],
22-
pipeMod.map((v) => v * 2),
23-
pipeMod.cycle,
24-
pipeMod.take(10),
25-
pipeMod.filter((v) => v % 2 === 0),
26-
);
27-
assertEquals(Array.from(iter), [2, 4, 6, 2, 4, 6, 2, 4, 6, 2]);
28-
});
19+
await test("README case 3", () => {
20+
const iter = pipe(
21+
[1, 2, 3],
22+
pipeMod.map((v) => v * 2),
23+
pipeMod.cycle,
24+
pipeMod.take(10),
25+
pipeMod.filter((v) => v % 2 === 0),
26+
);
27+
assertEquals(Array.from(iter), [2, 4, 6, 2, 4, 6, 2, 4, 6, 2]);
28+
});
2929

30-
await t.step("case 4", async () => {
31-
const iter = pipe(
32-
[1, 2, 3],
33-
pipeAsyncMod.map((v) => v * 2),
34-
pipeAsyncMod.cycle,
35-
pipeAsyncMod.take(10),
36-
pipeAsyncMod.filter((v) => v % 2 === 0),
37-
);
38-
assertEquals(await Array.fromAsync(iter), [2, 4, 6, 2, 4, 6, 2, 4, 6, 2]);
39-
});
30+
await test("README case 4", async () => {
31+
const iter = pipe(
32+
[1, 2, 3],
33+
pipeAsyncMod.map((v) => v * 2),
34+
pipeAsyncMod.cycle,
35+
pipeAsyncMod.take(10),
36+
pipeAsyncMod.filter((v) => v % 2 === 0),
37+
);
38+
assertEquals(await Array.fromAsync(iter), [2, 4, 6, 2, 4, 6, 2, 4, 6, 2]);
4039
});

async/chain_test.ts

+29-30
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
1+
import { test } from "@cross/test";
12
import { assertEquals } from "@std/assert";
23
import { assertType, type IsExact } from "@std/testing/types";
34
import { toAsyncIterable } from "./to_async_iterable.ts";
45
import { chain } from "./chain.ts";
56

6-
Deno.test("chain", async (t) => {
7-
await t.step("with empty iterables", async () => {
8-
const result = chain([] as number[], [] as string[]);
9-
const expected = [] as (number | string)[];
10-
assertEquals(await Array.fromAsync(result), expected);
11-
assertType<IsExact<typeof result, AsyncIterable<number | string>>>(true);
12-
});
7+
await test("chain with empty iterables", async () => {
8+
const result = chain([] as number[], [] as string[]);
9+
const expected = [] as (number | string)[];
10+
assertEquals(await Array.fromAsync(result), expected);
11+
assertType<IsExact<typeof result, AsyncIterable<number | string>>>(true);
12+
});
1313

14-
await t.step("with iterables", async () => {
15-
const result = chain(
16-
[1, 2, 3],
17-
toAsyncIterable(["a", "b"]),
18-
);
19-
const expected = [1, 2, 3, "a", "b"];
20-
assertEquals(await Array.fromAsync(result), expected);
21-
assertType<IsExact<typeof result, AsyncIterable<number | string>>>(true);
22-
});
14+
await test("chain with iterables", async () => {
15+
const result = chain(
16+
[1, 2, 3],
17+
toAsyncIterable(["a", "b"]),
18+
);
19+
const expected = [1, 2, 3, "a", "b"];
20+
assertEquals(await Array.fromAsync(result), expected);
21+
assertType<IsExact<typeof result, AsyncIterable<number | string>>>(true);
22+
});
2323

24-
await t.step("with multiple iterables", async () => {
25-
const result = chain(
26-
toAsyncIterable([1, 2, 3]),
27-
["a", "b"],
28-
toAsyncIterable([true]),
29-
);
30-
const expected = [1, 2, 3, "a", "b", true];
31-
assertEquals(await Array.fromAsync(result), expected);
32-
assertType<
33-
IsExact<typeof result, AsyncIterable<number | string | boolean>>
34-
>(
35-
true,
36-
);
37-
});
24+
await test("chain with multiple iterables", async () => {
25+
const result = chain(
26+
toAsyncIterable([1, 2, 3]),
27+
["a", "b"],
28+
toAsyncIterable([true]),
29+
);
30+
const expected = [1, 2, 3, "a", "b", true];
31+
assertEquals(await Array.fromAsync(result), expected);
32+
assertType<
33+
IsExact<typeof result, AsyncIterable<number | string | boolean>>
34+
>(
35+
true,
36+
);
3837
});

async/chunked_test.ts

+64-73
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,79 @@
1+
import { test } from "@cross/test";
12
import { assertEquals, assertThrows } from "@std/assert";
23
import { assertType, type IsExact } from "@std/testing/types";
34
import { toAsyncIterable } from "./to_async_iterable.ts";
45
import { chunked } from "./chunked.ts";
56

6-
Deno.test("chunked", async (t) => {
7-
await t.step("with async iterable", async (t) => {
8-
await t.step("the length is divisible by the size", async () => {
9-
const result = chunked(toAsyncIterable([1, 2, 3, 4, 5, 6]), 2);
10-
const expected = [[1, 2], [3, 4], [5, 6]];
11-
assertEquals(await Array.fromAsync(result), expected);
12-
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
13-
});
7+
await test("chunked with async iterable the length is divisible by the size", async () => {
8+
const result = chunked(toAsyncIterable([1, 2, 3, 4, 5, 6]), 2);
9+
const expected = [[1, 2], [3, 4], [5, 6]];
10+
assertEquals(await Array.fromAsync(result), expected);
11+
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
12+
});
1413

15-
await t.step("the length is not divisible by the size", async () => {
16-
const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 2);
17-
const expected = [[1, 2], [3, 4], [5]];
18-
assertEquals(await Array.fromAsync(result), expected);
19-
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
20-
});
14+
await test("chunked with async iterable the length is not divisible by the size", async () => {
15+
const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 2);
16+
const expected = [[1, 2], [3, 4], [5]];
17+
assertEquals(await Array.fromAsync(result), expected);
18+
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
19+
});
2120

22-
await t.step("the length is equal to the size", async () => {
23-
const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 5);
24-
const expected = [[1, 2, 3, 4, 5]];
25-
assertEquals(await Array.fromAsync(result), expected);
26-
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
27-
});
21+
await test("chunked with async iterable the length is equal to the size", async () => {
22+
const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 5);
23+
const expected = [[1, 2, 3, 4, 5]];
24+
assertEquals(await Array.fromAsync(result), expected);
25+
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
26+
});
2827

29-
await t.step("the length is less than the size", async () => {
30-
const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 6);
31-
const expected = [[1, 2, 3, 4, 5]];
32-
assertEquals(await Array.fromAsync(result), expected);
33-
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
34-
});
28+
await test("chunked with async iterable the length is less than the size", async () => {
29+
const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 6);
30+
const expected = [[1, 2, 3, 4, 5]];
31+
assertEquals(await Array.fromAsync(result), expected);
32+
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
33+
});
3534

36-
await t.step("throws RangeError", async (t) => {
37-
await t.step("if the length is not positive safe integer", () => {
38-
assertThrows(() => chunked([], NaN), RangeError);
39-
assertThrows(() => chunked([], Infinity), RangeError);
40-
assertThrows(() => chunked([], -Infinity), RangeError);
41-
assertThrows(() => chunked([], -1), RangeError);
42-
assertThrows(() => chunked([], 1.1), RangeError);
43-
assertThrows(() => chunked([], 0), RangeError);
44-
});
45-
});
46-
});
35+
await test("chunked with async iterable throws RangeError", () => {
36+
assertThrows(() => chunked([], NaN), RangeError);
37+
assertThrows(() => chunked([], Infinity), RangeError);
38+
assertThrows(() => chunked([], -Infinity), RangeError);
39+
assertThrows(() => chunked([], -1), RangeError);
40+
assertThrows(() => chunked([], 1.1), RangeError);
41+
assertThrows(() => chunked([], 0), RangeError);
42+
});
4743

48-
await t.step("with iterable", async (t) => {
49-
await t.step("the length is divisible by the size", async () => {
50-
const result = chunked([1, 2, 3, 4, 5, 6], 2);
51-
const expected = [[1, 2], [3, 4], [5, 6]];
52-
assertEquals(await Array.fromAsync(result), expected);
53-
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
54-
});
44+
await test("chunked with iterable the length is divisible by the size", async () => {
45+
const result = chunked([1, 2, 3, 4, 5, 6], 2);
46+
const expected = [[1, 2], [3, 4], [5, 6]];
47+
assertEquals(await Array.fromAsync(result), expected);
48+
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
49+
});
5550

56-
await t.step("the length is not divisible by the size", async () => {
57-
const result = chunked([1, 2, 3, 4, 5], 2);
58-
const expected = [[1, 2], [3, 4], [5]];
59-
assertEquals(await Array.fromAsync(result), expected);
60-
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
61-
});
51+
await test("chunked with iterable the length is not divisible by the size", async () => {
52+
const result = chunked([1, 2, 3, 4, 5], 2);
53+
const expected = [[1, 2], [3, 4], [5]];
54+
assertEquals(await Array.fromAsync(result), expected);
55+
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
56+
});
6257

63-
await t.step("the length is equal to the size", async () => {
64-
const result = chunked([1, 2, 3, 4, 5], 5);
65-
const expected = [[1, 2, 3, 4, 5]];
66-
assertEquals(await Array.fromAsync(result), expected);
67-
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
68-
});
58+
await test("chunked with iterable the length is equal to the size", async () => {
59+
const result = chunked([1, 2, 3, 4, 5], 5);
60+
const expected = [[1, 2, 3, 4, 5]];
61+
assertEquals(await Array.fromAsync(result), expected);
62+
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
63+
});
6964

70-
await t.step("the length is less than the size", async () => {
71-
const result = chunked([1, 2, 3, 4, 5], 6);
72-
const expected = [[1, 2, 3, 4, 5]];
73-
assertEquals(await Array.fromAsync(result), expected);
74-
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
75-
});
65+
await test("chunked with iterable the length is less than the size", async () => {
66+
const result = chunked([1, 2, 3, 4, 5], 6);
67+
const expected = [[1, 2, 3, 4, 5]];
68+
assertEquals(await Array.fromAsync(result), expected);
69+
assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true);
70+
});
7671

77-
await t.step("throws RangeError", async (t) => {
78-
await t.step("if the length is not positive safe integer", () => {
79-
assertThrows(() => chunked([], NaN), RangeError);
80-
assertThrows(() => chunked([], Infinity), RangeError);
81-
assertThrows(() => chunked([], -Infinity), RangeError);
82-
assertThrows(() => chunked([], -1), RangeError);
83-
assertThrows(() => chunked([], 1.1), RangeError);
84-
assertThrows(() => chunked([], 0), RangeError);
85-
});
86-
});
87-
});
72+
await test("chunked with iterable throws RangeError", () => {
73+
assertThrows(() => chunked([], NaN), RangeError);
74+
assertThrows(() => chunked([], Infinity), RangeError);
75+
assertThrows(() => chunked([], -Infinity), RangeError);
76+
assertThrows(() => chunked([], -1), RangeError);
77+
assertThrows(() => chunked([], 1.1), RangeError);
78+
assertThrows(() => chunked([], 0), RangeError);
8879
});

0 commit comments

Comments
 (0)