diff --git a/.github/workflows/test-node.yml b/.github/workflows/test-node.yml new file mode 100644 index 0000000..6be0cac --- /dev/null +++ b/.github/workflows/test-node.yml @@ -0,0 +1,27 @@ +name: Test (Node) + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22.x + - name: Install deps + run: | + npx jsr install + - name: Test + run: | + npx --yes tsx --test *_test.ts + npx --yes tsx --test async/*_test.ts + npx --yes tsx --test pipe/*_test.ts + npx --yes tsx --test pipe/async/*_test.ts + timeout-minutes: 5 diff --git a/.gitignore b/.gitignore index 4e4b189..eabbba7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /docs deno.lock .coverage +node_modules diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..41583e3 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@jsr:registry=https://npm.jsr.io diff --git a/README_test.ts b/README_test.ts index 52adbd6..e88b324 100644 --- a/README_test.ts +++ b/README_test.ts @@ -1,40 +1,39 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { pipe } from "@core/pipe"; -import * as rootMod from "@core/iterutil"; -import * as asyncMod from "@core/iterutil/async"; -import * as pipeMod from "@core/iterutil/pipe"; -import * as pipeAsyncMod from "@core/iterutil/pipe/async"; +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"; -Deno.test("README", async (t) => { - await t.step("case 1", () => { - const iter = rootMod.map([1, 2, 3], (v) => v * 2); - assertEquals(Array.from(iter), [2, 4, 6]); - }); +await test("README case 1", () => { + const iter = rootMod.map([1, 2, 3], (v) => v * 2); + assertEquals(Array.from(iter), [2, 4, 6]); +}); - await t.step("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 2", async () => { + const iter = asyncMod.map([1, 2, 3], (v) => Promise.resolve(v * 2)); + assertEquals(await Array.fromAsync(iter), [2, 4, 6]); +}); - await t.step("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 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 t.step("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]); - }); +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]); }); diff --git a/async/chain_test.ts b/async/chain_test.ts index ca8ab91..df54d29 100644 --- a/async/chain_test.ts +++ b/async/chain_test.ts @@ -1,38 +1,37 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { chain } from "./chain.ts"; -Deno.test("chain", async (t) => { - await t.step("with empty iterables", async () => { - const result = chain([] as number[], [] as string[]); - const expected = [] as (number | string)[]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chain with empty iterables", async () => { + const result = chain([] as number[], [] as string[]); + const expected = [] as (number | string)[]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with iterables", async () => { - const result = chain( - [1, 2, 3], - toAsyncIterable(["a", "b"]), - ); - const expected = [1, 2, 3, "a", "b"]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chain with iterables", async () => { + const result = chain( + [1, 2, 3], + toAsyncIterable(["a", "b"]), + ); + const expected = [1, 2, 3, "a", "b"]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with multiple iterables", async () => { - const result = chain( - toAsyncIterable([1, 2, 3]), - ["a", "b"], - toAsyncIterable([true]), - ); - const expected = [1, 2, 3, "a", "b", true]; - assertEquals(await Array.fromAsync(result), expected); - assertType< - IsExact> - >( - true, - ); - }); +await test("chain with multiple iterables", async () => { + const result = chain( + toAsyncIterable([1, 2, 3]), + ["a", "b"], + toAsyncIterable([true]), + ); + const expected = [1, 2, 3, "a", "b", true]; + assertEquals(await Array.fromAsync(result), expected); + assertType< + IsExact> + >( + true, + ); }); diff --git a/async/chunked_test.ts b/async/chunked_test.ts index 7519b8b..a897a88 100644 --- a/async/chunked_test.ts +++ b/async/chunked_test.ts @@ -1,88 +1,79 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { chunked } from "./chunked.ts"; -Deno.test("chunked", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("the length is divisible by the size", async () => { - const result = chunked(toAsyncIterable([1, 2, 3, 4, 5, 6]), 2); - const expected = [[1, 2], [3, 4], [5, 6]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chunked with async iterable the length is divisible by the size", async () => { + const result = chunked(toAsyncIterable([1, 2, 3, 4, 5, 6]), 2); + const expected = [[1, 2], [3, 4], [5, 6]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the length is not divisible by the size", async () => { - const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 2); - const expected = [[1, 2], [3, 4], [5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chunked with async iterable the length is not divisible by the size", async () => { + const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 2); + const expected = [[1, 2], [3, 4], [5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the length is equal to the size", async () => { - const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 5); - const expected = [[1, 2, 3, 4, 5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chunked with async iterable the length is equal to the size", async () => { + const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 5); + const expected = [[1, 2, 3, 4, 5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the length is less than the size", async () => { - const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 6); - const expected = [[1, 2, 3, 4, 5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chunked with async iterable the length is less than the size", async () => { + const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 6); + const expected = [[1, 2, 3, 4, 5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the length is not positive safe integer", () => { - assertThrows(() => chunked([], NaN), RangeError); - assertThrows(() => chunked([], Infinity), RangeError); - assertThrows(() => chunked([], -Infinity), RangeError); - assertThrows(() => chunked([], -1), RangeError); - assertThrows(() => chunked([], 1.1), RangeError); - assertThrows(() => chunked([], 0), RangeError); - }); - }); - }); +await test("chunked with async iterable throws RangeError", () => { + assertThrows(() => chunked([], NaN), RangeError); + assertThrows(() => chunked([], Infinity), RangeError); + assertThrows(() => chunked([], -Infinity), RangeError); + assertThrows(() => chunked([], -1), RangeError); + assertThrows(() => chunked([], 1.1), RangeError); + assertThrows(() => chunked([], 0), RangeError); +}); - await t.step("with iterable", async (t) => { - await t.step("the length is divisible by the size", async () => { - const result = chunked([1, 2, 3, 4, 5, 6], 2); - const expected = [[1, 2], [3, 4], [5, 6]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chunked with iterable the length is divisible by the size", async () => { + const result = chunked([1, 2, 3, 4, 5, 6], 2); + const expected = [[1, 2], [3, 4], [5, 6]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the length is not divisible by the size", async () => { - const result = chunked([1, 2, 3, 4, 5], 2); - const expected = [[1, 2], [3, 4], [5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chunked with iterable the length is not divisible by the size", async () => { + const result = chunked([1, 2, 3, 4, 5], 2); + const expected = [[1, 2], [3, 4], [5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the length is equal to the size", async () => { - const result = chunked([1, 2, 3, 4, 5], 5); - const expected = [[1, 2, 3, 4, 5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chunked with iterable the length is equal to the size", async () => { + const result = chunked([1, 2, 3, 4, 5], 5); + const expected = [[1, 2, 3, 4, 5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the length is less than the size", async () => { - const result = chunked([1, 2, 3, 4, 5], 6); - const expected = [[1, 2, 3, 4, 5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chunked with iterable the length is less than the size", async () => { + const result = chunked([1, 2, 3, 4, 5], 6); + const expected = [[1, 2, 3, 4, 5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the length is not positive safe integer", () => { - assertThrows(() => chunked([], NaN), RangeError); - assertThrows(() => chunked([], Infinity), RangeError); - assertThrows(() => chunked([], -Infinity), RangeError); - assertThrows(() => chunked([], -1), RangeError); - assertThrows(() => chunked([], 1.1), RangeError); - assertThrows(() => chunked([], 0), RangeError); - }); - }); - }); +await test("chunked with iterable throws RangeError", () => { + assertThrows(() => chunked([], NaN), RangeError); + assertThrows(() => chunked([], Infinity), RangeError); + assertThrows(() => chunked([], -Infinity), RangeError); + assertThrows(() => chunked([], -1), RangeError); + assertThrows(() => chunked([], 1.1), RangeError); + assertThrows(() => chunked([], 0), RangeError); }); diff --git a/async/compact_test.ts b/async/compact_test.ts index 38560e6..2dc2315 100644 --- a/async/compact_test.ts +++ b/async/compact_test.ts @@ -1,90 +1,85 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { compact } from "./compact.ts"; -Deno.test("compact", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("without undefined/null", async () => { - const result = compact(toAsyncIterable([1, 2, 3, 4, 5])); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compact with async iterable without undefined/null", async () => { + const result = compact(toAsyncIterable([1, 2, 3, 4, 5])); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with undefined", async () => { - const result = compact(toAsyncIterable([ - undefined, - 1, - 2, - undefined, - 3, - undefined, - 4, - 5, - undefined, - ])); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compact with async iterable with undefined", async () => { + const result = compact(toAsyncIterable([ + undefined, + 1, + 2, + undefined, + 3, + undefined, + 4, + 5, + undefined, + ])); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with null", async () => { - const result = compact( - toAsyncIterable([null, 1, 2, null, 3, null, 4, 5, null]), - ); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compact with async iterable with null", async () => { + const result = compact( + toAsyncIterable([null, 1, 2, null, 3, null, 4, 5, null]), + ); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with undefined/null", async () => { - const result = compact( - toAsyncIterable([undefined, 1, 2, null, 3, undefined, 4, 5, null]), - ); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("compact with async iterable with undefined/null", async () => { + const result = compact( + toAsyncIterable([undefined, 1, 2, null, 3, undefined, 4, 5, null]), + ); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("without undefined/null", async () => { - const result = compact([1, 2, 3, 4, 5]); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compact with iterable without undefined/null", async () => { + const result = compact([1, 2, 3, 4, 5]); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with undefined", async () => { - const result = compact([ - undefined, - 1, - 2, - undefined, - 3, - undefined, - 4, - 5, - undefined, - ]); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compact with iterable with undefined", async () => { + const result = compact([ + undefined, + 1, + 2, + undefined, + 3, + undefined, + 4, + 5, + undefined, + ]); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with null", async () => { - const result = compact([null, 1, 2, null, 3, null, 4, 5, null]); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compact with iterable with null", async () => { + const result = compact([null, 1, 2, null, 3, null, 4, 5, null]); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with undefined/null", async () => { - const result = compact([undefined, 1, 2, null, 3, undefined, 4, 5, null]); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("compact with iterable with undefined/null", async () => { + const result = compact([undefined, 1, 2, null, 3, undefined, 4, 5, null]); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/async/compress_test.ts b/async/compress_test.ts index 018b9cc..353c2ee 100644 --- a/async/compress_test.ts +++ b/async/compress_test.ts @@ -1,67 +1,62 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { compress } from "./compress.ts"; -Deno.test("compress", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("the iterable and the selectors are same length", async () => { - const result = compress( - toAsyncIterable([1, 2, 3, 4, 5]), - toAsyncIterable([true, false, true, false, true]), - ); - const expected = [1, 3, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compress with async iterable the iterable and the selectors are same length", async () => { + const result = compress( + toAsyncIterable([1, 2, 3, 4, 5]), + toAsyncIterable([true, false, true, false, true]), + ); + const expected = [1, 3, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the iterable is larger than the selectors", async () => { - const result = compress( - toAsyncIterable([1, 2, 3, 4, 5]), - toAsyncIterable([true, false, true]), - ); - const expected = [1, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compress with async iterable the iterable is larger than the selectors", async () => { + const result = compress( + toAsyncIterable([1, 2, 3, 4, 5]), + toAsyncIterable([true, false, true]), + ); + const expected = [1, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the iterable is smaller than the selector", async () => { - const result = compress( - toAsyncIterable([1, 2, 3]), - toAsyncIterable([true, false, true, false, true]), - ); - const expected = [1, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("compress with async iterable the iterable is smaller than the selector", async () => { + const result = compress( + toAsyncIterable([1, 2, 3]), + toAsyncIterable([true, false, true, false, true]), + ); + const expected = [1, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("the iterable and the selectors are same length", async () => { - const result = compress([1, 2, 3, 4, 5], [ - true, - false, - true, - false, - true, - ]); - const expected = [1, 3, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compress with iterable the iterable and the selectors are same length", async () => { + const result = compress([1, 2, 3, 4, 5], [ + true, + false, + true, + false, + true, + ]); + const expected = [1, 3, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the iterable is larger than the selectors", async () => { - const result = compress([1, 2, 3, 4, 5], [true, false, true]); - const expected = [1, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compress with iterable the iterable is larger than the selectors", async () => { + const result = compress([1, 2, 3, 4, 5], [true, false, true]); + const expected = [1, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("the iterable is smaller than the selector", async () => { - const result = compress([1, 2, 3], [true, false, true, false, true]); - const expected = [1, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("compress with iterable the iterable is smaller than the selector", async () => { + const result = compress([1, 2, 3], [true, false, true, false, true]); + const expected = [1, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/async/cycle_test.ts b/async/cycle_test.ts index 6c412ca..f5eeb8a 100644 --- a/async/cycle_test.ts +++ b/async/cycle_test.ts @@ -1,53 +1,48 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { take } from "./take.ts"; import { cycle } from "./cycle.ts"; -Deno.test("cycle", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = cycle(toAsyncIterable([0, 1, 2])); - const expected = [0, 1, 2, 0, 1]; - assertEquals(await Array.fromAsync(take(result, 5)), expected); - assertType>>(true); - }); +await test("cycle with async iterable with non empty iterable", async () => { + const result = cycle(toAsyncIterable([0, 1, 2])); + const expected = [0, 1, 2, 0, 1]; + assertEquals(await Array.fromAsync(take(result, 5)), expected); + assertType>>(true); +}); - await t.step("with single value iterable", async () => { - const result = cycle(toAsyncIterable([0])); - const expected = [0, 0, 0, 0, 0]; - assertEquals(await Array.fromAsync(take(result, 5)), expected); - assertType>>(true); - }); +await test("cycle with async iterable with single value iterable", async () => { + const result = cycle(toAsyncIterable([0])); + const expected = [0, 0, 0, 0, 0]; + assertEquals(await Array.fromAsync(take(result, 5)), expected); + assertType>>(true); +}); - await t.step("with empty iterable", async () => { - const result = cycle(toAsyncIterable([] as number[])); - const expected: number[] = []; - assertEquals(await Array.fromAsync(take(result, 5)), expected); - assertType>>(true); - }); - }); +await test("cycle with async iterable with empty iterable", async () => { + const result = cycle(toAsyncIterable([] as number[])); + const expected: number[] = []; + assertEquals(await Array.fromAsync(take(result, 5)), expected); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = cycle([0, 1, 2]); - const expected = [0, 1, 2, 0, 1]; - assertEquals(await Array.fromAsync(take(result, 5)), expected); - assertType>>(true); - }); +await test("cycle with iterable with non empty iterable", async () => { + const result = cycle([0, 1, 2]); + const expected = [0, 1, 2, 0, 1]; + assertEquals(await Array.fromAsync(take(result, 5)), expected); + assertType>>(true); +}); - await t.step("with single value iterable", async () => { - const result = cycle([0]); - const expected = [0, 0, 0, 0, 0]; - assertEquals(await Array.fromAsync(take(result, 5)), expected); - assertType>>(true); - }); +await test("cycle with iterable with single value iterable", async () => { + const result = cycle([0]); + const expected = [0, 0, 0, 0, 0]; + assertEquals(await Array.fromAsync(take(result, 5)), expected); + assertType>>(true); +}); - await t.step("with empty iterable", async () => { - const result = cycle([] as number[]); - const expected: number[] = []; - assertEquals(await Array.fromAsync(take(result, 5)), expected); - assertType>>(true); - }); - }); +await test("cycle with iterable with empty iterable", async () => { + const result = cycle([] as number[]); + const expected: number[] = []; + assertEquals(await Array.fromAsync(take(result, 5)), expected); + assertType>>(true); }); diff --git a/async/drop_test.ts b/async/drop_test.ts index 245fbef..09a8aea 100644 --- a/async/drop_test.ts +++ b/async/drop_test.ts @@ -1,58 +1,49 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { drop } from "./drop.ts"; -Deno.test("drop", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with positive limit", async () => { - const result = drop(toAsyncIterable([0, 1, 2, 3, 4]), 2); - const expected = [2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("drop with async iterable with positive limit", async () => { + const result = drop(toAsyncIterable([0, 1, 2, 3, 4]), 2); + const expected = [2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with 0 limit", async () => { - const result = drop(toAsyncIterable([0, 1, 2, 3, 4]), 0); - const expected = [0, 1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("drop with async iterable with 0 limit", async () => { + const result = drop(toAsyncIterable([0, 1, 2, 3, 4]), 0); + const expected = [0, 1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the limit is not 0 nor positive safe integer", () => { - assertThrows(() => drop([], NaN), RangeError); - assertThrows(() => drop([], Infinity), RangeError); - assertThrows(() => drop([], -Infinity), RangeError); - assertThrows(() => drop([], -1), RangeError); - assertThrows(() => drop([], 1.1), RangeError); - }); - }); - }); +await test("drop with async iterable throws RangeError", () => { + assertThrows(() => drop([], NaN), RangeError); + assertThrows(() => drop([], Infinity), RangeError); + assertThrows(() => drop([], -Infinity), RangeError); + assertThrows(() => drop([], -1), RangeError); + assertThrows(() => drop([], 1.1), RangeError); +}); - await t.step("with iterable", async (t) => { - await t.step("with positive limit", async () => { - const result = drop([0, 1, 2, 3, 4], 2); - const expected = [2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("drop with iterable with positive limit", async () => { + const result = drop([0, 1, 2, 3, 4], 2); + const expected = [2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with 0 limit", async () => { - const result = drop([0, 1, 2, 3, 4], 0); - const expected = [0, 1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("drop with iterable with 0 limit", async () => { + const result = drop([0, 1, 2, 3, 4], 0); + const expected = [0, 1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the limit is not 0 nor positive safe integer", () => { - assertThrows(() => drop([], NaN), RangeError); - assertThrows(() => drop([], Infinity), RangeError); - assertThrows(() => drop([], -Infinity), RangeError); - assertThrows(() => drop([], -1), RangeError); - assertThrows(() => drop([], 1.1), RangeError); - }); - }); - }); +await test("drop with iterable throws RangeError", () => { + assertThrows(() => drop([], NaN), RangeError); + assertThrows(() => drop([], Infinity), RangeError); + assertThrows(() => drop([], -Infinity), RangeError); + assertThrows(() => drop([], -1), RangeError); + assertThrows(() => drop([], 1.1), RangeError); }); diff --git a/async/drop_while_test.ts b/async/drop_while_test.ts index d3f6e41..db3bfa9 100644 --- a/async/drop_while_test.ts +++ b/async/drop_while_test.ts @@ -1,85 +1,80 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { dropWhile } from "./drop_while.ts"; -Deno.test("dropWhile", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with some true", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = dropWhile(toAsyncIterable([1, 2, 3, 4, 5]), (v, index) => { - values.push(v); - indices.push(index); - return v < 3; - }); - const expected = [3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>>(true); - }); +await test("dropWhile with async iterable with some true", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = dropWhile(toAsyncIterable([1, 2, 3, 4, 5]), (v, index) => { + values.push(v); + indices.push(index); + return v < 3; + }); + const expected = [3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>>(true); +}); - await t.step("with some promise true", async () => { - const result = dropWhile( - toAsyncIterable([0, 1, 2, 3, 4]), - (v) => Promise.resolve(v < 2), - ); - const expected = [2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("dropWhile with async iterable with some promise true", async () => { + const result = dropWhile( + toAsyncIterable([0, 1, 2, 3, 4]), + (v) => Promise.resolve(v < 2), + ); + const expected = [2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with all true", async () => { - const result = dropWhile(toAsyncIterable([0, 1, 2, 3, 4]), () => true); - const expected: number[] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("dropWhile with async iterable with all true", async () => { + const result = dropWhile(toAsyncIterable([0, 1, 2, 3, 4]), () => true); + const expected: number[] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with all false", async () => { - const result = dropWhile(toAsyncIterable([0, 1, 2, 3, 4]), () => false); - const expected = [0, 1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("dropWhile with async iterable with all false", async () => { + const result = dropWhile(toAsyncIterable([0, 1, 2, 3, 4]), () => false); + const expected = [0, 1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with some true", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = dropWhile([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v < 3; - }); - const expected = [3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>>(true); - }); +await test("dropWhile with iterable with some true", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = dropWhile([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v < 3; + }); + const expected = [3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>>(true); +}); - await t.step("with some promise true", async () => { - const result = dropWhile([0, 1, 2, 3, 4], (v) => Promise.resolve(v < 2)); - const expected = [2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("dropWhile with iterable with some promise true", async () => { + const result = dropWhile([0, 1, 2, 3, 4], (v) => Promise.resolve(v < 2)); + const expected = [2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with all true", async () => { - const result = dropWhile([0, 1, 2, 3, 4], () => true); - const expected: number[] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("dropWhile with iterable with all true", async () => { + const result = dropWhile([0, 1, 2, 3, 4], () => true); + const expected: number[] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with all false", async () => { - const result = dropWhile([0, 1, 2, 3, 4], () => false); - const expected = [0, 1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("dropWhile with iterable with all false", async () => { + const result = dropWhile([0, 1, 2, 3, 4], () => false); + const expected = [0, 1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/async/enumerate_test.ts b/async/enumerate_test.ts index bb14a82..287e1b7 100644 --- a/async/enumerate_test.ts +++ b/async/enumerate_test.ts @@ -1,168 +1,155 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { enumerate } from "./enumerate.ts"; -Deno.test("enumerate", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("default", async () => { - const result = enumerate(toAsyncIterable([0, 1, 2])); - const expected = [[0, 0], [1, 1], [2, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with positive start", async () => { - const result = enumerate(toAsyncIterable([0, 1, 2]), 1); - const expected = [[1, 0], [2, 1], [3, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with negative start", async () => { - const result = enumerate(toAsyncIterable([0, 1, 2]), -1); - const expected = [[-1, 0], [0, 1], [1, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with float start", async () => { - const result = enumerate(toAsyncIterable([0, 1, 2]), 1.1); - const expected = [[1.1, 0], [2.1, 1], [3.1, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with start and positive step", async () => { - const result = enumerate(toAsyncIterable([0, 1, 2]), 1, 2); - const expected = [[1, 0], [3, 1], [5, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with start and negative step", async () => { - const result = enumerate(toAsyncIterable([0, 1, 2]), 1, -1); - const expected = [[1, 0], [0, 1], [-1, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with start and float step", async () => { - const result = enumerate(toAsyncIterable([0, 1, 2]), 1, 0.2); - const expected = [[1, 0], [1.2, 1], [1.4, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("throws RangeError", async (t) => { - await t.step("if the start is not finite", () => { - assertThrows(() => enumerate(toAsyncIterable([]), NaN), RangeError); - assertThrows( - () => enumerate(toAsyncIterable([]), Infinity), - RangeError, - ); - assertThrows( - () => enumerate(toAsyncIterable([]), -Infinity), - RangeError, - ); - }); - - await t.step("if the step is not finite", () => { - assertThrows(() => enumerate(toAsyncIterable([]), 0, NaN), RangeError); - assertThrows( - () => enumerate(toAsyncIterable([]), 0, Infinity), - RangeError, - ); - assertThrows( - () => enumerate(toAsyncIterable([]), 0, -Infinity), - RangeError, - ); - }); - - await t.step("if the step is 0", () => { - assertThrows(() => enumerate(toAsyncIterable([]), 0, 0), RangeError); - }); - }); - }); - - await t.step("with iterable", async (t) => { - await t.step("default", async () => { - const result = enumerate([0, 1, 2]); - const expected = [[0, 0], [1, 1], [2, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with positive start", async () => { - const result = enumerate([0, 1, 2], 1); - const expected = [[1, 0], [2, 1], [3, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with negative start", async () => { - const result = enumerate([0, 1, 2], -1); - const expected = [[-1, 0], [0, 1], [1, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with float start", async () => { - const result = enumerate([0, 1, 2], 1.1); - const expected = [[1.1, 0], [2.1, 1], [3.1, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with start and positive step", async () => { - const result = enumerate([0, 1, 2], 1, 2); - const expected = [[1, 0], [3, 1], [5, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with start and negative step", async () => { - const result = enumerate([0, 1, 2], 1, -1); - const expected = [[1, 0], [0, 1], [-1, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("with start and float step", async () => { - const result = enumerate([0, 1, 2], 1, 0.2); - const expected = [[1, 0], [1.2, 1], [1.4, 2]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - - await t.step("throws RangeError", async (t) => { - await t.step("if the start is not finite", () => { - assertThrows(() => enumerate([], NaN), RangeError); - assertThrows( - () => enumerate([], Infinity), - RangeError, - ); - assertThrows( - () => enumerate([], -Infinity), - RangeError, - ); - }); - - await t.step("if the step is not finite", () => { - assertThrows(() => enumerate([], 0, NaN), RangeError); - assertThrows( - () => enumerate([], 0, Infinity), - RangeError, - ); - assertThrows( - () => enumerate([], 0, -Infinity), - RangeError, - ); - }); - - await t.step("if the step is 0", () => { - assertThrows(() => enumerate([], 0, 0), RangeError); - }); - }); - }); +await test("enumerate with async iterable default", async () => { + const result = enumerate(toAsyncIterable([0, 1, 2])); + const expected = [[0, 0], [1, 1], [2, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); + +await test("enumerate with async iterable with positive start", async () => { + const result = enumerate(toAsyncIterable([0, 1, 2]), 1); + const expected = [[1, 0], [2, 1], [3, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); + +await test("enumerate with async iterable with negative start", async () => { + const result = enumerate(toAsyncIterable([0, 1, 2]), -1); + const expected = [[-1, 0], [0, 1], [1, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); + +await test("enumerate with async iterable with float start", async () => { + const result = enumerate(toAsyncIterable([0, 1, 2]), 1.1); + const expected = [[1.1, 0], [2.1, 1], [3.1, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); + +await test( + "enumerate with async iterable with start and positive step", + async () => { + const result = enumerate(toAsyncIterable([0, 1, 2]), 1, 2); + const expected = [[1, 0], [3, 1], [5, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); + }, +); + +await test( + "enumerate with async iterable with start and negative step", + async () => { + const result = enumerate(toAsyncIterable([0, 1, 2]), 1, -1); + const expected = [[1, 0], [0, 1], [-1, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); + }, +); + +await test( + "enumerate with async iterable with start and float step", + async () => { + const result = enumerate(toAsyncIterable([0, 1, 2]), 1, 0.2); + const expected = [[1, 0], [1.2, 1], [1.4, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); + }, +); + +await test("enumerate with iterable default", async () => { + const result = enumerate([0, 1, 2]); + const expected = [[0, 0], [1, 1], [2, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); + +await test("enumerate with iterable with positive start", async () => { + const result = enumerate([0, 1, 2], 1); + const expected = [[1, 0], [2, 1], [3, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); + +await test("enumerate with iterable with negative start", async () => { + const result = enumerate([0, 1, 2], -1); + const expected = [[-1, 0], [0, 1], [1, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); + +await test("enumerate with iterable with float start", async () => { + const result = enumerate([0, 1, 2], 1.1); + const expected = [[1.1, 0], [2.1, 1], [3.1, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); + +await test( + "enumerate with iterable with start and positive step", + async () => { + const result = enumerate([0, 1, 2], 1, 2); + const expected = [[1, 0], [3, 1], [5, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); + }, +); + +await test( + "enumerate with iterable with start and negative step", + async () => { + const result = enumerate([0, 1, 2], 1, -1); + const expected = [[1, 0], [0, 1], [-1, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); + }, +); + +await test("enumerate with iterable with start and float step", async () => { + const result = enumerate([0, 1, 2], 1, 0.2); + const expected = [[1, 0], [1.2, 1], [1.4, 2]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); + +await test( + "enumerate with iterable throws RangeError if the start is not finite", + () => { + assertThrows(() => enumerate([], NaN), RangeError); + assertThrows( + () => enumerate([], Infinity), + RangeError, + ); + assertThrows( + () => enumerate([], -Infinity), + RangeError, + ); + }, +); + +await test( + "enumerate with iterable throws RangeError if the step is not finite", + () => { + assertThrows(() => enumerate([], 0, NaN), RangeError); + assertThrows( + () => enumerate([], 0, Infinity), + RangeError, + ); + assertThrows( + () => enumerate([], 0, -Infinity), + RangeError, + ); + }, +); + +await test( + "enumerate with iterable throws RangeError if the step is 0", + () => { + assertThrows(() => enumerate([], 0, 0), RangeError); + }, +); diff --git a/async/every_test.ts b/async/every_test.ts index 9eaa47e..3d0c661 100644 --- a/async/every_test.ts +++ b/async/every_test.ts @@ -1,148 +1,143 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { every } from "./every.ts"; -Deno.test("every", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("true", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await every( - toAsyncIterable([1, 2, 3, 4, 5]), - (v, index) => { - values.push(v); - indices.push(index); - return v < 6; - }, - ); - const expected = true; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); +await test("every with async iterable true", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await every( + toAsyncIterable([1, 2, 3, 4, 5]), + (v, index) => { + values.push(v); + indices.push(index); + return v < 6; + }, + ); + const expected = true; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); + +await test("every with async iterable false", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await every( + toAsyncIterable([1, 2, 3, 4, 5]), + (v, index) => { + values.push(v); + indices.push(index); + return v < 3; + }, + ); + const expected = false; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>(true); +}); - await t.step("false", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await every( - toAsyncIterable([1, 2, 3, 4, 5]), - (v, index) => { - values.push(v); - indices.push(index); - return v < 3; - }, - ); - const expected = false; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>(true); - }); +await test("every with async iterable promise true", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await every( + toAsyncIterable([1, 2, 3, 4, 5]), + (v, index) => { + values.push(v); + indices.push(index); + return Promise.resolve(v < 6); + }, + ); + const expected = true; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); - await t.step("promise true", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await every( - toAsyncIterable([1, 2, 3, 4, 5]), - (v, index) => { - values.push(v); - indices.push(index); - return Promise.resolve(v < 6); - }, - ); - const expected = true; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); +await test("pevery with async iterable romise false", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await every( + toAsyncIterable([1, 2, 3, 4, 5]), + (v, index) => { + values.push(v); + indices.push(index); + return Promise.resolve(v < 3); + }, + ); + const expected = false; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>(true); +}); - await t.step("promise false", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await every( - toAsyncIterable([1, 2, 3, 4, 5]), - (v, index) => { - values.push(v); - indices.push(index); - return Promise.resolve(v < 3); - }, - ); - const expected = false; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>(true); - }); +await test("every with iterable true", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await every([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v < 6; }); + const expected = true; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("true", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await every([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v < 6; - }); - const expected = true; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); - - await t.step("false", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await every([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v < 3; - }); - const expected = false; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>(true); - }); +await test("every with iterable false", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await every([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v < 3; + }); + const expected = false; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>(true); +}); - await t.step("promise true", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await every( - [1, 2, 3, 4, 5], - (v, index) => { - values.push(v); - indices.push(index); - return Promise.resolve(v < 6); - }, - ); - const expected = true; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); +await test("every with iterable promise true", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await every( + [1, 2, 3, 4, 5], + (v, index) => { + values.push(v); + indices.push(index); + return Promise.resolve(v < 6); + }, + ); + const expected = true; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); - await t.step("promise false", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await every( - [1, 2, 3, 4, 5], - (v, index) => { - values.push(v); - indices.push(index); - return Promise.resolve(v < 3); - }, - ); - const expected = false; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>(true); - }); - }); +await test("every with iterable promise false", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await every( + [1, 2, 3, 4, 5], + (v, index) => { + values.push(v); + indices.push(index); + return Promise.resolve(v < 3); + }, + ); + const expected = false; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>(true); }); diff --git a/async/filter_test.ts b/async/filter_test.ts index 9cd946a..410fe42 100644 --- a/async/filter_test.ts +++ b/async/filter_test.ts @@ -1,76 +1,71 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { filter } from "./filter.ts"; -Deno.test("filter", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("without promise", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = filter( - toAsyncIterable([1, 2, 3, 4, 5]), - (value, index) => { - values.push(value); - indices.push(index); - return value % 2 === 0; - }, - ); - const expected = [2, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); +await test("filter with async iterable without promise", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = filter( + toAsyncIterable([1, 2, 3, 4, 5]), + (value, index) => { + values.push(value); + indices.push(index); + return value % 2 === 0; + }, + ); + const expected = [2, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("with promise", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = filter( - toAsyncIterable([1, 2, 3, 4, 5]), - (value, index) => { - values.push(value); - indices.push(index); - return Promise.resolve(value % 2 === 0); - }, - ); - const expected = [2, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); - }); +await test("filter with async iterable with promise", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = filter( + toAsyncIterable([1, 2, 3, 4, 5]), + (value, index) => { + values.push(value); + indices.push(index); + return Promise.resolve(value % 2 === 0); + }, + ); + const expected = [2, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("without promise", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = filter([1, 2, 3, 4, 5], (value, index) => { - values.push(value); - indices.push(index); - return value % 2 === 0; - }); - const expected = [2, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); +await test("filter with iterable without promise", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = filter([1, 2, 3, 4, 5], (value, index) => { + values.push(value); + indices.push(index); + return value % 2 === 0; + }); + const expected = [2, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("with promise", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = filter([1, 2, 3, 4, 5], (value, index) => { - values.push(value); - indices.push(index); - return Promise.resolve(value % 2 === 0); - }); - const expected = [2, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); +await test("filter with iterable with promise", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = filter([1, 2, 3, 4, 5], (value, index) => { + values.push(value); + indices.push(index); + return Promise.resolve(value % 2 === 0); }); + const expected = [2, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); }); diff --git a/async/find_test.ts b/async/find_test.ts index 0cf2b81..adb2866 100644 --- a/async/find_test.ts +++ b/async/find_test.ts @@ -1,90 +1,85 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { find } from "./find.ts"; -Deno.test("find", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("found", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await find( - toAsyncIterable([1, 2, 3, 4, 5]), - (v, index) => { - values.push(v); - indices.push(index); - return v % 2 === 0; - }, - ); - const expected = 2; - assertEquals(result, expected); - assertEquals(values, [1, 2]); - assertEquals(indices, [0, 1]); - assertType>(true); - }); - - await t.step("promise found", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await find( - toAsyncIterable([1, 2, 3, 4, 5]), - (v, index) => { - values.push(v); - indices.push(index); - return Promise.resolve(v % 2 === 0); - }, - ); - const expected = 2; - assertEquals(result, expected); - assertEquals(values, [1, 2]); - assertEquals(indices, [0, 1]); - assertType>(true); - }); +await test("find with async iterable found", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await find( + toAsyncIterable([1, 2, 3, 4, 5]), + (v, index) => { + values.push(v); + indices.push(index); + return v % 2 === 0; + }, + ); + const expected = 2; + assertEquals(result, expected); + assertEquals(values, [1, 2]); + assertEquals(indices, [0, 1]); + assertType>(true); +}); - await t.step("not found", async () => { - const result = await find(toAsyncIterable([1, 2, 3, 4, 5]), () => false); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); - }); +await test("find with async iterable promise found", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await find( + toAsyncIterable([1, 2, 3, 4, 5]), + (v, index) => { + values.push(v); + indices.push(index); + return Promise.resolve(v % 2 === 0); + }, + ); + const expected = 2; + assertEquals(result, expected); + assertEquals(values, [1, 2]); + assertEquals(indices, [0, 1]); + assertType>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("found", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await find([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v % 2 === 0; - }); - const expected = 2; - assertEquals(result, expected); - assertEquals(values, [1, 2]); - assertEquals(indices, [0, 1]); - assertType>(true); - }); +await test("find with async iterable not found", async () => { + const result = await find(toAsyncIterable([1, 2, 3, 4, 5]), () => false); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("promise found", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await find([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return Promise.resolve(v % 2 === 0); - }); - const expected = 2; - assertEquals(result, expected); - assertEquals(values, [1, 2]); - assertEquals(indices, [0, 1]); - assertType>(true); - }); +await test("find with iterable found", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await find([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v % 2 === 0; + }); + const expected = 2; + assertEquals(result, expected); + assertEquals(values, [1, 2]); + assertEquals(indices, [0, 1]); + assertType>(true); +}); - await t.step("not found", async () => { - const result = await find([1, 2, 3, 4, 5], () => false); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); +await test("find with iterable promise found", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await find([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return Promise.resolve(v % 2 === 0); }); + const expected = 2; + assertEquals(result, expected); + assertEquals(values, [1, 2]); + assertEquals(indices, [0, 1]); + assertType>(true); +}); + +await test("find with iterable not found", async () => { + const result = await find([1, 2, 3, 4, 5], () => false); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); }); diff --git a/async/first_test.ts b/async/first_test.ts index 6163f9e..1c75883 100644 --- a/async/first_test.ts +++ b/async/first_test.ts @@ -1,38 +1,33 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { first } from "./first.ts"; -Deno.test("first", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = await first(toAsyncIterable([1, 2, 3, 4, 5])); - const expected = 1; - assertEquals(result, expected); - assertType>(true); - }); +await test("first with async iterable with non empty iterable", async () => { + const result = await first(toAsyncIterable([1, 2, 3, 4, 5])); + const expected = 1; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with empty iterable", async () => { - const result = await first(toAsyncIterable([] as number[])); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); - }); +await test("first with async iterable with empty iterable", async () => { + const result = await first(toAsyncIterable([] as number[])); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = await first([1, 2, 3, 4, 5]); - const expected = 1; - assertEquals(result, expected); - assertType>(true); - }); +await test("first with iterable with non empty iterable", async () => { + const result = await first([1, 2, 3, 4, 5]); + const expected = 1; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with empty iterable", async () => { - const result = await first([] as number[]); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); - }); +await test("first with iterable with empty iterable", async () => { + const result = await first([] as number[]); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); }); diff --git a/async/flat_map_test.ts b/async/flat_map_test.ts index b626bd1..9733d00 100644 --- a/async/flat_map_test.ts +++ b/async/flat_map_test.ts @@ -1,123 +1,118 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { flatMap } from "./flat_map.ts"; -Deno.test("flatMap", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("single nest", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = flatMap( - toAsyncIterable([1, 2, 3, 4, 5]), - (value, index) => { - values.push(value); - indices.push(index); - return [value, value]; - }, - ); - const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); - - await t.step("single async iterable nest", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = flatMap( - toAsyncIterable([1, 2, 3, 4, 5]), - (value, index) => { - values.push(value); - indices.push(index); - return toAsyncIterable([value, value]); - }, - ); - const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); +await test("flatMap with async iterable single nest", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = flatMap( + toAsyncIterable([1, 2, 3, 4, 5]), + (value, index) => { + values.push(value); + indices.push(index); + return [value, value]; + }, + ); + const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("single promise nest", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = flatMap( - toAsyncIterable([1, 2, 3, 4, 5]), - (value, index) => { - values.push(value); - indices.push(index); - return Promise.resolve([value, value]); - }, - ); - const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); +await test("flatMap with async iterable single async iterable nest", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = flatMap( + toAsyncIterable([1, 2, 3, 4, 5]), + (value, index) => { + values.push(value); + indices.push(index); + return toAsyncIterable([value, value]); + }, + ); + const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("multi nest", async () => { - const result = flatMap(toAsyncIterable([1, 2, 3, 4, 5]), (v) => [[v, v]]); - const expected = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("flatMap with async iterable single promise nest", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = flatMap( + toAsyncIterable([1, 2, 3, 4, 5]), + (value, index) => { + values.push(value); + indices.push(index); + return Promise.resolve([value, value]); + }, + ); + const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("single nest", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = flatMap([1, 2, 3, 4, 5], (value, index) => { - values.push(value); - indices.push(index); - return [value, value]; - }); - const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); +await test("flatMap with async iterable multi nest", async () => { + const result = flatMap(toAsyncIterable([1, 2, 3, 4, 5]), (v) => [[v, v]]); + const expected = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("single async iterable nest", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = flatMap([1, 2, 3, 4, 5], (value, index) => { - values.push(value); - indices.push(index); - return toAsyncIterable([value, value]); - }); - const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); +await test("flatMap with iterable single nest", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = flatMap([1, 2, 3, 4, 5], (value, index) => { + values.push(value); + indices.push(index); + return [value, value]; + }); + const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("single promise nest", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = flatMap([1, 2, 3, 4, 5], (value, index) => { - values.push(value); - indices.push(index); - return Promise.resolve([value, value]); - }); - const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); - }); +await test("flatMap with iterable single async iterable nest", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = flatMap([1, 2, 3, 4, 5], (value, index) => { + values.push(value); + indices.push(index); + return toAsyncIterable([value, value]); + }); + const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("multi nest", async () => { - const result = flatMap([1, 2, 3, 4, 5], (v) => [[v, v]]); - const expected = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("flatMap with iterable single promise nest", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = flatMap([1, 2, 3, 4, 5], (value, index) => { + values.push(value); + indices.push(index); + return Promise.resolve([value, value]); }); + const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); + +await test("flatMap with iterable multi nest", async () => { + const result = flatMap([1, 2, 3, 4, 5], (v) => [[v, v]]); + const expected = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/async/flatten_test.ts b/async/flatten_test.ts index 98e94dd..d8d6781 100644 --- a/async/flatten_test.ts +++ b/async/flatten_test.ts @@ -1,44 +1,41 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { flatten } from "./flatten.ts"; -Deno.test("flatten", async (t) => { - await t.step("with iterable", async (t) => { - await t.step("single nest", async () => { - const result = flatten([[1, 2], [3, 4], [5]]); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("flatten with iterable single nest", async () => { + const result = flatten([[1, 2], [3, 4], [5]]); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("single async iterable nest", async () => { - const result = flatten([ - toAsyncIterable([1, 2]), - toAsyncIterable([3, 4]), - toAsyncIterable([5]), - ]); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("flatten with iterable single async iterable nest", async () => { + const result = flatten([ + toAsyncIterable([1, 2]), + toAsyncIterable([3, 4]), + toAsyncIterable([5]), + ]); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("single promise nest", async () => { - const result = flatten([ - Promise.resolve([1, 2]), - Promise.resolve([3, 4]), - Promise.resolve([5]), - ]); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("flatten with iterable single promise nest", async () => { + const result = flatten([ + Promise.resolve([1, 2]), + Promise.resolve([3, 4]), + Promise.resolve([5]), + ]); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("multi nest", async () => { - const result = flatten([[[1, 2], [3, 4]], [[5]]]); - const expected = [[1, 2], [3, 4], [5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("flatten with iterable multi nest", async () => { + const result = flatten([[[1, 2], [3, 4]], [[5]]]); + const expected = [[1, 2], [3, 4], [5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/async/for_each_test.ts b/async/for_each_test.ts index a8402ab..e79ba2f 100644 --- a/async/for_each_test.ts +++ b/async/for_each_test.ts @@ -1,51 +1,50 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { forEach } from "./for_each.ts"; -Deno.test("forEach", async (t) => { - await t.step("with async iterable", async () => { - const values: number[] = []; - const indices: number[] = []; - await forEach(toAsyncIterable([1, 2, 3, 4, 5]), (value, index) => { - values.push(value); - indices.push(index); - }); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); +await test("forEach with async iterable", async () => { + const values: number[] = []; + const indices: number[] = []; + await forEach(toAsyncIterable([1, 2, 3, 4, 5]), (value, index) => { + values.push(value); + indices.push(index); }); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); +}); - await t.step("with async iterable (promise)", async () => { - const values: number[] = []; - const indices: number[] = []; - await forEach(toAsyncIterable([1, 2, 3, 4, 5]), (value, index) => { - values.push(value); - indices.push(index); - return Promise.resolve(); - }); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); +await test("forEach with async iterable (promise)", async () => { + const values: number[] = []; + const indices: number[] = []; + await forEach(toAsyncIterable([1, 2, 3, 4, 5]), (value, index) => { + values.push(value); + indices.push(index); + return Promise.resolve(); }); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); +}); - await t.step("with iterable", async () => { - const values: number[] = []; - const indices: number[] = []; - await forEach([1, 2, 3, 4, 5], (value, index) => { - values.push(value); - indices.push(index); - }); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); +await test("forEach with iterable", async () => { + const values: number[] = []; + const indices: number[] = []; + await forEach([1, 2, 3, 4, 5], (value, index) => { + values.push(value); + indices.push(index); }); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); +}); - await t.step("with iterable (promise)", async () => { - const values: number[] = []; - const indices: number[] = []; - await forEach([1, 2, 3, 4, 5], (value, index) => { - values.push(value); - indices.push(index); - return Promise.resolve(); - }); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); +await test("forEach with iterable (promise)", async () => { + const values: number[] = []; + const indices: number[] = []; + await forEach([1, 2, 3, 4, 5], (value, index) => { + values.push(value); + indices.push(index); + return Promise.resolve(); }); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); }); diff --git a/async/iter_test.ts b/async/iter_test.ts index 54c4731..ec77b57 100644 --- a/async/iter_test.ts +++ b/async/iter_test.ts @@ -1,22 +1,21 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { iter } from "./iter.ts"; -Deno.test("iter", async (t) => { - await t.step("with async iterable", async () => { - const it = iter(toAsyncIterable([0, 1, 2, 3, 4, 5])); - assertEquals(await it.next(), { done: false, value: 0 }); - assertEquals(await it.next(), { done: false, value: 1 }); - assertEquals(await Array.fromAsync(it), [2, 3, 4, 5]); - assertType>>(true); - }); +await test("iter with async iterable", async () => { + const it = iter(toAsyncIterable([0, 1, 2, 3, 4, 5])); + assertEquals(await it.next(), { done: false, value: 0 }); + assertEquals(await it.next(), { done: false, value: 1 }); + assertEquals(await Array.fromAsync(it), [2, 3, 4, 5]); + assertType>>(true); +}); - await t.step("with iterable", async () => { - const it = iter([0, 1, 2, 3, 4, 5]); - assertEquals(await it.next(), { done: false, value: 0 }); - assertEquals(await it.next(), { done: false, value: 1 }); - assertEquals(await Array.fromAsync(it), [2, 3, 4, 5]); - assertType>>(true); - }); +await test("iter with iterable", async () => { + const it = iter([0, 1, 2, 3, 4, 5]); + assertEquals(await it.next(), { done: false, value: 0 }); + assertEquals(await it.next(), { done: false, value: 1 }); + assertEquals(await Array.fromAsync(it), [2, 3, 4, 5]); + assertType>>(true); }); diff --git a/async/last_test.ts b/async/last_test.ts index 0f32e5b..79120bb 100644 --- a/async/last_test.ts +++ b/async/last_test.ts @@ -1,38 +1,33 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { last } from "./last.ts"; -Deno.test("last", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = await last(toAsyncIterable([1, 2, 3, 4, 5])); - const expected = 5; - assertEquals(result, expected); - assertType>(true); - }); +await test("last with async iterable with non empty iterable", async () => { + const result = await last(toAsyncIterable([1, 2, 3, 4, 5])); + const expected = 5; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with empty iterable", async () => { - const result = await last(toAsyncIterable([] as number[])); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); - }); +await test("last with async iterable with empty iterable", async () => { + const result = await last(toAsyncIterable([] as number[])); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = await last([1, 2, 3, 4, 5]); - const expected = 5; - assertEquals(result, expected); - assertType>(true); - }); +await test("last with iterable with non empty iterable", async () => { + const result = await last([1, 2, 3, 4, 5]); + const expected = 5; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with empty iterable", async () => { - const result = await last([] as number[]); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); - }); +await test("last with iterable with empty iterable", async () => { + const result = await last([] as number[]); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); }); diff --git a/async/map_test.ts b/async/map_test.ts index 8c20471..9a7c42a 100644 --- a/async/map_test.ts +++ b/async/map_test.ts @@ -1,66 +1,65 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { map } from "./map.ts"; -Deno.test("map", async (t) => { - await t.step("with async iterable", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = map(toAsyncIterable([1, 2, 3, 4, 5]), (v, index) => { - values.push(v); - indices.push(index); - return v * 2; - }); - const expected = [2, 4, 6, 8, 10]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); +await test("map with async iterable", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = map(toAsyncIterable([1, 2, 3, 4, 5]), (v, index) => { + values.push(v); + indices.push(index); + return v * 2; }); + const expected = [2, 4, 6, 8, 10]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("with iterable (promise)", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = map(toAsyncIterable([1, 2, 3, 4, 5]), (v, index) => { - values.push(v); - indices.push(index); - return Promise.resolve(v * 2); - }); - const expected = [2, 4, 6, 8, 10]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); +await test("map with iterable (promise)", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = map(toAsyncIterable([1, 2, 3, 4, 5]), (v, index) => { + values.push(v); + indices.push(index); + return Promise.resolve(v * 2); }); + const expected = [2, 4, 6, 8, 10]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("with iterable", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = map([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v * 2; - }); - const expected = [2, 4, 6, 8, 10]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); +await test("map with iterable", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = map([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v * 2; }); + const expected = [2, 4, 6, 8, 10]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("with iterable (promise)", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = map([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return Promise.resolve(v * 2); - }); - const expected = [2, 4, 6, 8, 10]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); +await test("map with iterable (promise)", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = map([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return Promise.resolve(v * 2); }); + const expected = [2, 4, 6, 8, 10]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); }); diff --git a/async/mod_test.ts b/async/mod_test.ts index 3409c34..e07e699 100644 --- a/async/mod_test.ts +++ b/async/mod_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cross/test"; import { assertArrayIncludes } from "@std/assert"; import { basename, globToRegExp, join } from "@std/path"; import { ensure, is } from "@core/unknownutil"; @@ -9,16 +10,16 @@ const excludes = [ "*_bench.ts", ]; -Deno.test("mod.ts must exports all exports in public modules", async () => { +test("mod.ts must exports all exports in public modules", async () => { const modExports = await listModExports("./mod.ts"); const pubExports = []; for await (const name of iterPublicModules(".")) { pubExports.push(...await listModExports(`./${name}.ts`)); } assertArrayIncludes(modExports, pubExports); -}); +}, { skip: !("Deno" in globalThis) }); -Deno.test("JSR exports must have all exports in mod.ts", async () => { +test("JSR exports must have all exports in mod.ts", async () => { const jsrExportEntries = await listJsrExportEntries(); const modExportEntries: [string, string][] = []; for await (const name of iterPublicModules(".")) { @@ -28,7 +29,7 @@ Deno.test("JSR exports must have all exports in mod.ts", async () => { ]); } assertArrayIncludes(jsrExportEntries, modExportEntries); -}); +}, { skip: !("Deno" in globalThis) }); async function* iterPublicModules(relpath: string): AsyncIterable { const patterns = excludes.map((p) => globToRegExp(p)); diff --git a/async/nth_test.ts b/async/nth_test.ts index 220b448..7d7a416 100644 --- a/async/nth_test.ts +++ b/async/nth_test.ts @@ -1,48 +1,41 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { nth } from "./nth.ts"; -Deno.test("last", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = await nth(toAsyncIterable([1, 2, 3, 4, 5]), 2); - const expected = 3; - assertEquals(result, expected); - assertType>(true); - }); +await test("last with async iterable with non empty iterable", async () => { + const result = await nth(toAsyncIterable([1, 2, 3, 4, 5]), 2); + const expected = 3; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with empty iterable", async () => { - const result = await nth(toAsyncIterable([] as number[]), 2); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); - }); +await test("last with async iterable with empty iterable", async () => { + const result = await nth(toAsyncIterable([] as number[]), 2); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = await nth([1, 2, 3, 4, 5], 2); - const expected = 3; - assertEquals(result, expected); - assertType>(true); - }); +await test("last with iterable with non empty iterable", async () => { + const result = await nth([1, 2, 3, 4, 5], 2); + const expected = 3; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with empty iterable", async () => { - const result = await nth([] as number[], 2); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); - }); +await test("last with iterable with empty iterable", async () => { + const result = await nth([] as number[], 2); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the index is not 0 nor positive safe integer", () => { - assertThrows(() => nth([], NaN), RangeError); - assertThrows(() => nth([], Infinity), RangeError); - assertThrows(() => nth([], -Infinity), RangeError); - assertThrows(() => nth([], -1), RangeError); - assertThrows(() => nth([], 1.1), RangeError); - }); - }); +await test("last with iterable last throws RangeError", () => { + assertThrows(() => nth([], NaN), RangeError); + assertThrows(() => nth([], Infinity), RangeError); + assertThrows(() => nth([], -Infinity), RangeError); + assertThrows(() => nth([], -1), RangeError); + assertThrows(() => nth([], 1.1), RangeError); }); diff --git a/async/pairwise_test.ts b/async/pairwise_test.ts index 4372693..f08d505 100644 --- a/async/pairwise_test.ts +++ b/async/pairwise_test.ts @@ -1,52 +1,47 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { pairwise } from "./pairwise.ts"; -Deno.test("pairwise", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = pairwise(toAsyncIterable([1, 2, 3, 4, 5])); - const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("pairwise with async iterable with non empty iterable", async () => { + const result = pairwise(toAsyncIterable([1, 2, 3, 4, 5])); + const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with single value iterable", async () => { - const result = pairwise(toAsyncIterable([1])); - const expected: number[][] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("pairwise with async iterable with single value iterable", async () => { + const result = pairwise(toAsyncIterable([1])); + const expected: number[][] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with empty iterable", async () => { - const result = pairwise(toAsyncIterable([] as number[])); - const expected: number[][] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("pairwise with async iterable with empty iterable", async () => { + const result = pairwise(toAsyncIterable([] as number[])); + const expected: number[][] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = pairwise([1, 2, 3, 4, 5]); - const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("pairwise with iterable with non empty iterable", async () => { + const result = pairwise([1, 2, 3, 4, 5]); + const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with single value iterable", async () => { - const result = pairwise([1]); - const expected: number[][] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("pairwise with iterable with single value iterable", async () => { + const result = pairwise([1]); + const expected: number[][] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with empty iterable", async () => { - const result = pairwise([] as number[]); - const expected: number[][] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("pairwise with iterable with empty iterable", async () => { + const result = pairwise([] as number[]); + const expected: number[][] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/async/partition_test.ts b/async/partition_test.ts index 9d13ff2..4ba6e4d 100644 --- a/async/partition_test.ts +++ b/async/partition_test.ts @@ -1,99 +1,94 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { partition } from "./partition.ts"; -Deno.test("partition", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const values: number[] = []; - const indices: number[] = []; - const [left, right] = await partition( - toAsyncIterable([1, 2, 3, 4, 5]), - (value, index) => { - values.push(value); - indices.push(index); - return value % 2 === 0; - }, - ); - assertEquals(left, [2, 4]); - assertEquals(right, [1, 3, 5]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - assertType>(true); - }); - - await t.step("with non empty iterable (promise)", async () => { - const values: number[] = []; - const indices: number[] = []; - const [left, right] = await partition( - toAsyncIterable([1, 2, 3, 4, 5]), - (value, index) => { - values.push(value); - indices.push(index); - return Promise.resolve(value % 2 === 0); - }, - ); - assertEquals(left, [2, 4]); - assertEquals(right, [1, 3, 5]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - assertType>(true); - }); +await test("partition with async iterable with non empty iterable", async () => { + const values: number[] = []; + const indices: number[] = []; + const [left, right] = await partition( + toAsyncIterable([1, 2, 3, 4, 5]), + (value, index) => { + values.push(value); + indices.push(index); + return value % 2 === 0; + }, + ); + assertEquals(left, [2, 4]); + assertEquals(right, [1, 3, 5]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); + assertType>(true); +}); - await t.step("with empty iterable", async () => { - const [left, right] = await partition( - toAsyncIterable([] as number[]), - (v) => v % 2 === 0, - ); - assertEquals(left, []); - assertEquals(right, []); - assertType>(true); - assertType>(true); - }); - }); +await test("partition with async iterable with non empty iterable (promise)", async () => { + const values: number[] = []; + const indices: number[] = []; + const [left, right] = await partition( + toAsyncIterable([1, 2, 3, 4, 5]), + (value, index) => { + values.push(value); + indices.push(index); + return Promise.resolve(value % 2 === 0); + }, + ); + assertEquals(left, [2, 4]); + assertEquals(right, [1, 3, 5]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); + assertType>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const values: number[] = []; - const indices: number[] = []; - const [left, right] = await partition([1, 2, 3, 4, 5], (value, index) => { - values.push(value); - indices.push(index); - return value % 2 === 0; - }); - assertEquals(left, [2, 4]); - assertEquals(right, [1, 3, 5]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - assertType>(true); - }); +await test("partition with async iterable with empty iterable", async () => { + const [left, right] = await partition( + toAsyncIterable([] as number[]), + (v) => v % 2 === 0, + ); + assertEquals(left, []); + assertEquals(right, []); + assertType>(true); + assertType>(true); +}); - await t.step("with non empty iterable (promise)", async () => { - const values: number[] = []; - const indices: number[] = []; - const [left, right] = await partition([1, 2, 3, 4, 5], (value, index) => { - values.push(value); - indices.push(index); - return Promise.resolve(value % 2 === 0); - }); - assertEquals(left, [2, 4]); - assertEquals(right, [1, 3, 5]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - assertType>(true); - }); +await test("partition with iterable with non empty iterable", async () => { + const values: number[] = []; + const indices: number[] = []; + const [left, right] = await partition([1, 2, 3, 4, 5], (value, index) => { + values.push(value); + indices.push(index); + return value % 2 === 0; + }); + assertEquals(left, [2, 4]); + assertEquals(right, [1, 3, 5]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); + assertType>(true); +}); - await t.step("with empty iterable", async () => { - const [left, right] = await partition([] as number[], (v) => v % 2 === 0); - assertEquals(left, []); - assertEquals(right, []); - assertType>(true); - assertType>(true); - }); +await test("partition with iterable with non empty iterable (promise)", async () => { + const values: number[] = []; + const indices: number[] = []; + const [left, right] = await partition([1, 2, 3, 4, 5], (value, index) => { + values.push(value); + indices.push(index); + return Promise.resolve(value % 2 === 0); }); + assertEquals(left, [2, 4]); + assertEquals(right, [1, 3, 5]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); + assertType>(true); +}); + +await test("partition with iterable with empty iterable", async () => { + const [left, right] = await partition([] as number[], (v) => v % 2 === 0); + assertEquals(left, []); + assertEquals(right, []); + assertType>(true); + assertType>(true); }); diff --git a/async/reduce_test.ts b/async/reduce_test.ts index fa3628e..8c036ab 100644 --- a/async/reduce_test.ts +++ b/async/reduce_test.ts @@ -1,175 +1,170 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { reduce } from "./reduce.ts"; -Deno.test("reduce", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with initial", async () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = await reduce( - toAsyncIterable([1, 2, 3, 4, 5]), - (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return acc + value; - }, - 5, - ); - assertEquals(result, 20); - assertEquals(accumulators, [5, 6, 8, 11, 15]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); - - await t.step("with initial promise", async () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = await reduce( - toAsyncIterable([1, 2, 3, 4, 5]), - (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return Promise.resolve(acc + value); - }, - 5, - ); - assertEquals(result, 20); - assertEquals(accumulators, [5, 6, 8, 11, 15]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); +await test("reduce with async iterable with initial", async () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = await reduce( + toAsyncIterable([1, 2, 3, 4, 5]), + (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return acc + value; + }, + 5, + ); + assertEquals(result, 20); + assertEquals(accumulators, [5, 6, 8, 11, 15]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); - await t.step("without initial", async () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = await reduce( - toAsyncIterable([1, 2, 3, 4, 5]), - (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return acc + value; - }, - ); - assertEquals(result, 15); - assertEquals(accumulators, [1, 3, 6, 10]); - assertEquals(values, [2, 3, 4, 5]); - assertEquals(indices, [1, 2, 3, 4]); - assertType>(true); - }); +await test("reduce with async iterable with initial promise", async () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = await reduce( + toAsyncIterable([1, 2, 3, 4, 5]), + (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return Promise.resolve(acc + value); + }, + 5, + ); + assertEquals(result, 20); + assertEquals(accumulators, [5, 6, 8, 11, 15]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); - await t.step("without initial promise", async () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = await reduce( - toAsyncIterable([1, 2, 3, 4, 5]), - (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return Promise.resolve(acc + value); - }, - ); - assertEquals(result, 15); - assertEquals(accumulators, [1, 3, 6, 10]); - assertEquals(values, [2, 3, 4, 5]); - assertEquals(indices, [1, 2, 3, 4]); - assertType>(true); - }); +await test("reduce with async iterable without initial", async () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = await reduce( + toAsyncIterable([1, 2, 3, 4, 5]), + (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return acc + value; + }, + ); + assertEquals(result, 15); + assertEquals(accumulators, [1, 3, 6, 10]); + assertEquals(values, [2, 3, 4, 5]); + assertEquals(indices, [1, 2, 3, 4]); + assertType>(true); +}); - await t.step("without initial / with empty iterable", async () => { - const result = await reduce( - toAsyncIterable([] as number[]), - (acc, v) => acc + v, - ); - assertEquals(result, undefined); - assertType>(true); - }); - }); +await test("reduce with async iterable without initial promise", async () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = await reduce( + toAsyncIterable([1, 2, 3, 4, 5]), + (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return Promise.resolve(acc + value); + }, + ); + assertEquals(result, 15); + assertEquals(accumulators, [1, 3, 6, 10]); + assertEquals(values, [2, 3, 4, 5]); + assertEquals(indices, [1, 2, 3, 4]); + assertType>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with initial", async () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = await reduce([1, 2, 3, 4, 5], (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return acc + value; - }, 5); - assertEquals(result, 20); - assertEquals(accumulators, [5, 6, 8, 11, 15]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); +await test("reduce with async iterable without initial / with empty iterable", async () => { + const result = await reduce( + toAsyncIterable([] as number[]), + (acc, v) => acc + v, + ); + assertEquals(result, undefined); + assertType>(true); +}); - await t.step("with initial promise", async () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = await reduce([1, 2, 3, 4, 5], (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return Promise.resolve(acc + value); - }, 5); - assertEquals(result, 20); - assertEquals(accumulators, [5, 6, 8, 11, 15]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); +await test("reduce with iterable with initial", async () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = await reduce([1, 2, 3, 4, 5], (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return acc + value; + }, 5); + assertEquals(result, 20); + assertEquals(accumulators, [5, 6, 8, 11, 15]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); - await t.step("without initial", async () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = await reduce([1, 2, 3, 4, 5], (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return acc + value; - }); - assertEquals(result, 15); - assertEquals(accumulators, [1, 3, 6, 10]); - assertEquals(values, [2, 3, 4, 5]); - assertEquals(indices, [1, 2, 3, 4]); - assertType>(true); - }); +await test("reduce with iterable with initial promise", async () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = await reduce([1, 2, 3, 4, 5], (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return Promise.resolve(acc + value); + }, 5); + assertEquals(result, 20); + assertEquals(accumulators, [5, 6, 8, 11, 15]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); - await t.step("without initial promise", async () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = await reduce([1, 2, 3, 4, 5], (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return Promise.resolve(acc + value); - }); - assertEquals(result, 15); - assertEquals(accumulators, [1, 3, 6, 10]); - assertEquals(values, [2, 3, 4, 5]); - assertEquals(indices, [1, 2, 3, 4]); - assertType>(true); - }); +await test("reduce with iterable without initial", async () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = await reduce([1, 2, 3, 4, 5], (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return acc + value; + }); + assertEquals(result, 15); + assertEquals(accumulators, [1, 3, 6, 10]); + assertEquals(values, [2, 3, 4, 5]); + assertEquals(indices, [1, 2, 3, 4]); + assertType>(true); +}); - await t.step("without initial / with empty iterable", async () => { - const result = await reduce([] as number[], (acc, v) => acc + v); - assertEquals(result, undefined); - assertType>(true); - }); +await test("reduce with iterable without initial promise", async () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = await reduce([1, 2, 3, 4, 5], (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return Promise.resolve(acc + value); }); + assertEquals(result, 15); + assertEquals(accumulators, [1, 3, 6, 10]); + assertEquals(values, [2, 3, 4, 5]); + assertEquals(indices, [1, 2, 3, 4]); + assertType>(true); +}); + +await test("reduce with iterable without initial / with empty iterable", async () => { + const result = await reduce([] as number[], (acc, v) => acc + v); + assertEquals(result, undefined); + assertType>(true); }); diff --git a/async/repeat_test.ts b/async/repeat_test.ts index c9bf7a0..6143c67 100644 --- a/async/repeat_test.ts +++ b/async/repeat_test.ts @@ -1,69 +1,62 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { repeat } from "./repeat.ts"; -Deno.test("repeat", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = repeat(toAsyncIterable([0, 1, 2]), 2); - const expected = [0, 1, 2, 0, 1, 2]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("repeat with async iterable with non empty iterable", async () => { + const result = repeat(toAsyncIterable([0, 1, 2]), 2); + const expected = [0, 1, 2, 0, 1, 2]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with single value iterable", async () => { - const result = repeat(toAsyncIterable([0]), 2); - const expected = [0, 0]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("repeat with async iterable with single value iterable", async () => { + const result = repeat(toAsyncIterable([0]), 2); + const expected = [0, 0]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with empty iterable", async () => { - const result = repeat(toAsyncIterable([] as number[]), 2); - const expected: number[] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("repeat with async iterable with empty iterable", async () => { + const result = repeat(toAsyncIterable([] as number[]), 2); + const expected: number[] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with non empty iterable", async () => { - const result = repeat([0, 1, 2], 2); - const expected = [0, 1, 2, 0, 1, 2]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("repeat with iterable with non empty iterable", async () => { + const result = repeat([0, 1, 2], 2); + const expected = [0, 1, 2, 0, 1, 2]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with single value iterable", async () => { - const result = repeat([0], 2); - const expected = [0, 0]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("repeat with iterable with single value iterable", async () => { + const result = repeat([0], 2); + const expected = [0, 0]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with empty iterable", async () => { - const result = repeat([] as number[], 2); - const expected: number[] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("repeat with iterable with empty iterable", async () => { + const result = repeat([] as number[], 2); + const expected: number[] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with n=0", async () => { - const result = repeat([0, 1, 2], 0); - const expected: number[] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("repeat with n=0", async () => { + const result = repeat([0, 1, 2], 0); + const expected: number[] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the limit is not 0 nor positive safe integer", () => { - assertThrows(() => repeat([], NaN), RangeError); - assertThrows(() => repeat([], Infinity), RangeError); - assertThrows(() => repeat([], -Infinity), RangeError); - assertThrows(() => repeat([], -1), RangeError); - assertThrows(() => repeat([], 1.1), RangeError); - }); - }); +await test("repeat throws RangeError", () => { + assertThrows(() => repeat([], NaN), RangeError); + assertThrows(() => repeat([], Infinity), RangeError); + assertThrows(() => repeat([], -Infinity), RangeError); + assertThrows(() => repeat([], -1), RangeError); + assertThrows(() => repeat([], 1.1), RangeError); }); diff --git a/async/some_test.ts b/async/some_test.ts index c20568c..997f613 100644 --- a/async/some_test.ts +++ b/async/some_test.ts @@ -1,76 +1,71 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { some } from "./some.ts"; -Deno.test("some", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("true", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await some( - toAsyncIterable([1, 2, 3, 4, 5]), - (v, index) => { - values.push(v); - indices.push(index); - return v > 2; - }, - ); - const expected = true; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>(true); - }); +await test("some with async iterable true", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await some( + toAsyncIterable([1, 2, 3, 4, 5]), + (v, index) => { + values.push(v); + indices.push(index); + return v > 2; + }, + ); + const expected = true; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>(true); +}); - await t.step("false", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await some( - toAsyncIterable([1, 2, 3, 4, 5]), - (v, index) => { - values.push(v); - indices.push(index); - return v > 5; - }, - ); - const expected = false; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); - }); +await test("some with async iterable false", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await some( + toAsyncIterable([1, 2, 3, 4, 5]), + (v, index) => { + values.push(v); + indices.push(index); + return v > 5; + }, + ); + const expected = false; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("true", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await some([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v > 2; - }); - const expected = true; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>(true); - }); +await test("some with iterable true", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await some([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v > 2; + }); + const expected = true; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>(true); +}); - await t.step("false", async () => { - const values: number[] = []; - const indices: number[] = []; - const result = await some([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v > 5; - }); - const expected = false; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); +await test("some with iterable false", async () => { + const values: number[] = []; + const indices: number[] = []; + const result = await some([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v > 5; }); + const expected = false; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); }); diff --git a/async/take_test.ts b/async/take_test.ts index fd52b79..0d5c9ce 100644 --- a/async/take_test.ts +++ b/async/take_test.ts @@ -1,59 +1,52 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { iter } from "./iter.ts"; import { take } from "./take.ts"; -Deno.test("take", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with positive limit", async () => { - const result = take(toAsyncIterable([0, 1, 2, 3, 4]), 2); - const expected = [0, 1]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("take with async iterable with positive limit", async () => { + const result = take(toAsyncIterable([0, 1, 2, 3, 4]), 2); + const expected = [0, 1]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with 0 limit", async () => { - const result = take(toAsyncIterable([0, 1, 2, 3, 4]), 0); - const expected: number[] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("take with async iterable with 0 limit", async () => { + const result = take(toAsyncIterable([0, 1, 2, 3, 4]), 0); + const expected: number[] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with positive limit", async () => { - const result = take([0, 1, 2, 3, 4], 2); - const expected = [0, 1]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("take with iterable with positive limit", async () => { + const result = take([0, 1, 2, 3, 4], 2); + const expected = [0, 1]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with 0 limit", async () => { - const result = take([0, 1, 2, 3, 4], 0); - const expected: number[] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("take with iterable with 0 limit", async () => { + const result = take([0, 1, 2, 3, 4], 0); + const expected: number[] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("will stop consuming once limit items is taken", async () => { - const it = iter([0, 1, 2, 3, 4]); - const result = take(it, 3); - const expected: number[] = [0, 1, 2]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - // Ensure the iterator is NOT fully consumed - assertEquals(await Array.fromAsync(it), [3, 4]); - }); +await test("take will stop consuming once limit items is taken", async () => { + const it = iter([0, 1, 2, 3, 4]); + const result = take(it, 3); + const expected: number[] = [0, 1, 2]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); + // Ensure the iterator is NOT fully consumed + assertEquals(await Array.fromAsync(it), [3, 4]); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the limit is not 0 nor positive safe integer", () => { - assertThrows(() => take([], NaN), RangeError); - assertThrows(() => take([], Infinity), RangeError); - assertThrows(() => take([], -Infinity), RangeError); - assertThrows(() => take([], -1), RangeError); - assertThrows(() => take([], 1.1), RangeError); - }); - }); +await test("take throws RangeError", () => { + assertThrows(() => take([], NaN), RangeError); + assertThrows(() => take([], Infinity), RangeError); + assertThrows(() => take([], -Infinity), RangeError); + assertThrows(() => take([], -1), RangeError); + assertThrows(() => take([], 1.1), RangeError); }); diff --git a/async/take_while_test.ts b/async/take_while_test.ts index 15df815..b3e11d0 100644 --- a/async/take_while_test.ts +++ b/async/take_while_test.ts @@ -1,69 +1,64 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { takeWhile } from "./take_while.ts"; -Deno.test("takeWhile", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("with some true", async () => { - const result = takeWhile(toAsyncIterable([0, 1, 2, 3, 4]), (v) => v < 2); - const expected = [0, 1]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("takeWhile with async iterable with some true", async () => { + const result = takeWhile(toAsyncIterable([0, 1, 2, 3, 4]), (v) => v < 2); + const expected = [0, 1]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with some promise true", async () => { - const result = takeWhile( - toAsyncIterable([0, 1, 2, 3, 4]), - (v) => Promise.resolve(v < 2), - ); - const expected = [0, 1]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("takeWhile with async iterable with some promise true", async () => { + const result = takeWhile( + toAsyncIterable([0, 1, 2, 3, 4]), + (v) => Promise.resolve(v < 2), + ); + const expected = [0, 1]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with all true", async () => { - const result = takeWhile(toAsyncIterable([0, 1, 2, 3, 4]), () => true); - const expected = [0, 1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("takeWhile with async iterable with all true", async () => { + const result = takeWhile(toAsyncIterable([0, 1, 2, 3, 4]), () => true); + const expected = [0, 1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with all false", async () => { - const result = takeWhile(toAsyncIterable([0, 1, 2, 3, 4]), () => false); - const expected: number[] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("takeWhile with async iterable with all false", async () => { + const result = takeWhile(toAsyncIterable([0, 1, 2, 3, 4]), () => false); + const expected: number[] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("with some true", async () => { - const result = takeWhile([0, 1, 2, 3, 4], (v) => v < 2); - const expected = [0, 1]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("takeWhile with iterable with some true", async () => { + const result = takeWhile([0, 1, 2, 3, 4], (v) => v < 2); + const expected = [0, 1]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with some promise true", async () => { - const result = takeWhile([0, 1, 2, 3, 4], (v) => Promise.resolve(v < 2)); - const expected = [0, 1]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("takeWhile with iterable with some promise true", async () => { + const result = takeWhile([0, 1, 2, 3, 4], (v) => Promise.resolve(v < 2)); + const expected = [0, 1]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with all true", async () => { - const result = takeWhile([0, 1, 2, 3, 4], () => true); - const expected = [0, 1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("takeWhile with iterable with all true", async () => { + const result = takeWhile([0, 1, 2, 3, 4], () => true); + const expected = [0, 1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with all false", async () => { - const result = takeWhile([0, 1, 2, 3, 4], () => false); - const expected: number[] = []; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("takeWhile with iterable with all false", async () => { + const result = takeWhile([0, 1, 2, 3, 4], () => false); + const expected: number[] = []; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/async/to_async_iterable_test.ts b/async/to_async_iterable_test.ts index 96c31ea..6c1d7b1 100644 --- a/async/to_async_iterable_test.ts +++ b/async/to_async_iterable_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; -Deno.test("toAsyncIterable", async () => { +test("toAsyncIterable", async () => { const result = toAsyncIterable([1, 2, 3, 4, 5]); const expected = [1, 2, 3, 4, 5]; assertEquals(await Array.fromAsync(result), expected); diff --git a/async/uniq_test.ts b/async/uniq_test.ts index 74afd0d..434c532 100644 --- a/async/uniq_test.ts +++ b/async/uniq_test.ts @@ -1,90 +1,85 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { uniq } from "./uniq.ts"; -Deno.test("uniq", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("default", async () => { - const result = uniq( - toAsyncIterable([1, 2, 2, 3, 3, 3]), - ); - const expected = [1, 2, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("uniq with async iterable default", async () => { + const result = uniq( + toAsyncIterable([1, 2, 2, 3, 3, 3]), + ); + const expected = [1, 2, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with identify", async () => { - const values: number[] = []; - const indices: number[] = []; - const identities: number[] = []; - const result = uniq( - toAsyncIterable([1, 2, 3, 4, 5, 6, 7, 8, 9]), - (v, index) => { - values.push(v); - indices.push(index); - const id = v % 4; - identities.push(id); - return id; - }, - ); - const expected = [1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5, 6, 7, 8, 9]); - assertEquals(indices, [0, 1, 2, 3, 4, 5, 6, 7, 8]); - assertEquals(identities, [1, 2, 3, 0, 1, 2, 3, 0, 1]); - assertType>>(true); - }); +await test("uniq with async iterable with identify", async () => { + const values: number[] = []; + const indices: number[] = []; + const identities: number[] = []; + const result = uniq( + toAsyncIterable([1, 2, 3, 4, 5, 6, 7, 8, 9]), + (v, index) => { + values.push(v); + indices.push(index); + const id = v % 4; + identities.push(id); + return id; + }, + ); + const expected = [1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5, 6, 7, 8, 9]); + assertEquals(indices, [0, 1, 2, 3, 4, 5, 6, 7, 8]); + assertEquals(identities, [1, 2, 3, 0, 1, 2, 3, 0, 1]); + assertType>>(true); +}); - await t.step("with identify promise", async () => { - const result = uniq( - toAsyncIterable([1, 2, 3, 4, 5, 6, 7, 8, 9]), - (v) => Promise.resolve(v % 4), - ); - const expected = [1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("uniq with async iterable with identify promise", async () => { + const result = uniq( + toAsyncIterable([1, 2, 3, 4, 5, 6, 7, 8, 9]), + (v) => Promise.resolve(v % 4), + ); + const expected = [1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with iterable", async (t) => { - await t.step("default", async () => { - const result = uniq([1, 2, 2, 3, 3, 3]); - const expected = [1, 2, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("uniq with iterable default", async () => { + const result = uniq([1, 2, 2, 3, 3, 3]); + const expected = [1, 2, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with identify", async () => { - const values: number[] = []; - const indices: number[] = []; - const identities: number[] = []; - const result = uniq( - [1, 2, 3, 4, 5, 6, 7, 8, 9], - (v, index) => { - values.push(v); - indices.push(index); - const id = v % 4; - identities.push(id); - return id; - }, - ); - const expected = [1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertEquals(values, [1, 2, 3, 4, 5, 6, 7, 8, 9]); - assertEquals(indices, [0, 1, 2, 3, 4, 5, 6, 7, 8]); - assertEquals(identities, [1, 2, 3, 0, 1, 2, 3, 0, 1]); - assertType>>(true); - }); +await test("uniq with iterable with identify", async () => { + const values: number[] = []; + const indices: number[] = []; + const identities: number[] = []; + const result = uniq( + [1, 2, 3, 4, 5, 6, 7, 8, 9], + (v, index) => { + values.push(v); + indices.push(index); + const id = v % 4; + identities.push(id); + return id; + }, + ); + const expected = [1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertEquals(values, [1, 2, 3, 4, 5, 6, 7, 8, 9]); + assertEquals(indices, [0, 1, 2, 3, 4, 5, 6, 7, 8]); + assertEquals(identities, [1, 2, 3, 0, 1, 2, 3, 0, 1]); + assertType>>(true); +}); - await t.step("with identify promise", async () => { - const result = uniq( - [1, 2, 3, 4, 5, 6, 7, 8, 9], - (v) => Promise.resolve(v % 4), - ); - const expected = [1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); - }); +await test("uniq with iterable with identify promise", async () => { + const result = uniq( + [1, 2, 3, 4, 5, 6, 7, 8, 9], + (v) => Promise.resolve(v % 4), + ); + const expected = [1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/async/zip_test.ts b/async/zip_test.ts index 498faa4..ef77db1 100644 --- a/async/zip_test.ts +++ b/async/zip_test.ts @@ -1,96 +1,91 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { toAsyncIterable } from "./to_async_iterable.ts"; import { zip } from "./zip.ts"; -Deno.test("zip", async (t) => { - await t.step("with async iterable", async (t) => { - await t.step("zip with two iterables", async () => { - const result = zip( - toAsyncIterable([1, 2, 3]), - toAsyncIterable(["a", "b", "c"]), - ); - const expected = [[1, "a"], [2, "b"], [3, "c"]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("zip with two iterables", async () => { + const result = zip( + toAsyncIterable([1, 2, 3]), + toAsyncIterable(["a", "b", "c"]), + ); + const expected = [[1, "a"], [2, "b"], [3, "c"]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("zip with two in-balanced iterables", async () => { - const result = zip( - toAsyncIterable([1, 2, 3, 4, 5]), - toAsyncIterable(["a", "b", "c"]), - ); - const expected = [[1, "a"], [2, "b"], [3, "c"]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("zip with two in-balanced iterables", async () => { + const result = zip( + toAsyncIterable([1, 2, 3, 4, 5]), + toAsyncIterable(["a", "b", "c"]), + ); + const expected = [[1, "a"], [2, "b"], [3, "c"]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("zip with three iterables", async () => { - const result = zip( - toAsyncIterable([1, 2, 3]), - toAsyncIterable(["a", "b", "c"]), - [true, false, true], - ); - const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; - assertEquals(await Array.fromAsync(result), expected); - assertType< - IsExact> - >( - true, - ); - }); +await test("zip with three iterables", async () => { + const result = zip( + toAsyncIterable([1, 2, 3]), + toAsyncIterable(["a", "b", "c"]), + [true, false, true], + ); + const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; + assertEquals(await Array.fromAsync(result), expected); + assertType< + IsExact> + >( + true, + ); +}); - await t.step("zip with three in-balanced iterables", async () => { - const result = zip( - toAsyncIterable([1, 2, 3, 4, 5]), - toAsyncIterable(["a", "b", "c"]), - [true, false, true], - ); - const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; - assertEquals(await Array.fromAsync(result), expected); - assertType< - IsExact> - >( - true, - ); - }); - }); +await test("zip with three in-balanced iterables", async () => { + const result = zip( + toAsyncIterable([1, 2, 3, 4, 5]), + toAsyncIterable(["a", "b", "c"]), + [true, false, true], + ); + const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; + assertEquals(await Array.fromAsync(result), expected); + assertType< + IsExact> + >( + true, + ); +}); - await t.step("with iterable", async (t) => { - await t.step("zip with two iterables", async () => { - const result = zip([1, 2, 3], ["a", "b", "c"]); - const expected = [[1, "a"], [2, "b"], [3, "c"]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("zip with two iterables", async () => { + const result = zip([1, 2, 3], ["a", "b", "c"]); + const expected = [[1, "a"], [2, "b"], [3, "c"]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("zip with two in-balanced iterables", async () => { - const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"]); - const expected = [[1, "a"], [2, "b"], [3, "c"]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("zip with two in-balanced iterables", async () => { + const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"]); + const expected = [[1, "a"], [2, "b"], [3, "c"]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("zip with three iterables", async () => { - const result = zip([1, 2, 3], ["a", "b", "c"], [true, false, true]); - const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; - assertEquals(await Array.fromAsync(result), expected); - assertType< - IsExact> - >( - true, - ); - }); +await test("zip with three iterables", async () => { + const result = zip([1, 2, 3], ["a", "b", "c"], [true, false, true]); + const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; + assertEquals(await Array.fromAsync(result), expected); + assertType< + IsExact> + >( + true, + ); +}); - await t.step("zip with three in-balanced iterables", async () => { - const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"], [true, false, true]); - const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; - assertEquals(await Array.fromAsync(result), expected); - assertType< - IsExact> - >( - true, - ); - }); - }); +await test("zip with three in-balanced iterables", async () => { + const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"], [true, false, true]); + const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; + assertEquals(await Array.fromAsync(result), expected); + assertType< + IsExact> + >( + true, + ); }); diff --git a/chain_test.ts b/chain_test.ts index 8ff6566..2ba1e74 100644 --- a/chain_test.ts +++ b/chain_test.ts @@ -1,35 +1,34 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { chain } from "./chain.ts"; -Deno.test("chain", async (t) => { - await t.step("with empty iterables", () => { - const result = chain([] as number[], [] as string[]); - const expected = [] as (number | string)[]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("chain with empty iterables", () => { + const result = chain([] as number[], [] as string[]); + const expected = [] as (number | string)[]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with iterables", () => { - const result = chain( - [1, 2, 3], - ["a", "b"], - ); - const expected = [1, 2, 3, "a", "b"]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("chain with iterables", () => { + const result = chain( + [1, 2, 3], + ["a", "b"], + ); + const expected = [1, 2, 3, "a", "b"]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with multiple iterables", () => { - const result = chain( - [1, 2, 3], - ["a", "b"], - [true], - ); - const expected = [1, 2, 3, "a", "b", true]; - assertEquals(Array.from(result), expected); - assertType>>( - true, - ); - }); +await test("chain with multiple iterables", () => { + const result = chain( + [1, 2, 3], + ["a", "b"], + [true], + ); + const expected = [1, 2, 3, "a", "b", true]; + assertEquals(Array.from(result), expected); + assertType>>( + true, + ); }); diff --git a/chunked_test.ts b/chunked_test.ts index df35a94..2f66ae1 100644 --- a/chunked_test.ts +++ b/chunked_test.ts @@ -1,44 +1,41 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { chunked } from "./chunked.ts"; -Deno.test("chunked", async (t) => { - await t.step("the length is divisible by the size", () => { - const result = chunked([1, 2, 3, 4, 5, 6], 2); - const expected = [[1, 2], [3, 4], [5, 6]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("chunked the length is divisible by the size", () => { + const result = chunked([1, 2, 3, 4, 5, 6], 2); + const expected = [[1, 2], [3, 4], [5, 6]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("the length is not divisible by the size", () => { - const result = chunked([1, 2, 3, 4, 5], 2); - const expected = [[1, 2], [3, 4], [5]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("chunked the length is not divisible by the size", () => { + const result = chunked([1, 2, 3, 4, 5], 2); + const expected = [[1, 2], [3, 4], [5]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("the length is equal to the size", () => { - const result = chunked([1, 2, 3, 4, 5], 5); - const expected = [[1, 2, 3, 4, 5]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("chunked the length is equal to the size", () => { + const result = chunked([1, 2, 3, 4, 5], 5); + const expected = [[1, 2, 3, 4, 5]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("the length is less than the size", () => { - const result = chunked([1, 2, 3, 4, 5], 6); - const expected = [[1, 2, 3, 4, 5]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("chunked the length is less than the size", () => { + const result = chunked([1, 2, 3, 4, 5], 6); + const expected = [[1, 2, 3, 4, 5]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the length is not positive safe integer", () => { - assertThrows(() => chunked([], NaN), RangeError); - assertThrows(() => chunked([], Infinity), RangeError); - assertThrows(() => chunked([], -Infinity), RangeError); - assertThrows(() => chunked([], -1), RangeError); - assertThrows(() => chunked([], 1.1), RangeError); - assertThrows(() => chunked([], 0), RangeError); - }); - }); +await test("chunked throws RangeError", () => { + assertThrows(() => chunked([], NaN), RangeError); + assertThrows(() => chunked([], Infinity), RangeError); + assertThrows(() => chunked([], -Infinity), RangeError); + assertThrows(() => chunked([], -1), RangeError); + assertThrows(() => chunked([], 1.1), RangeError); + assertThrows(() => chunked([], 0), RangeError); }); diff --git a/compact_test.ts b/compact_test.ts index db11f93..e4172a2 100644 --- a/compact_test.ts +++ b/compact_test.ts @@ -1,43 +1,42 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { compact } from "./compact.ts"; -Deno.test("compact", async (t) => { - await t.step("without undefined/null", () => { - const result = compact([1, 2, 3, 4, 5]); - const expected = [1, 2, 3, 4, 5]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +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>>(true); +}); - await t.step("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>>(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>>(true); +}); - await t.step("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>>(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>>(true); +}); - await t.step("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>>(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>>(true); }); diff --git a/compress_test.ts b/compress_test.ts index 8ac5986..5bc5684 100644 --- a/compress_test.ts +++ b/compress_test.ts @@ -1,26 +1,25 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { compress } from "./compress.ts"; -Deno.test("compress", async (t) => { - await t.step("the iterable and the selectors are same length", () => { - const result = compress([1, 2, 3, 4, 5], [true, false, true, false, true]); - const expected = [1, 3, 5]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("compress the iterable and the selectors are same length", () => { + const result = compress([1, 2, 3, 4, 5], [true, false, true, false, true]); + const expected = [1, 3, 5]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("the iterable is larger than the selectors", () => { - const result = compress([1, 2, 3, 4, 5], [true, false, true]); - const expected = [1, 3]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("compress the iterable is larger than the selectors", () => { + const result = compress([1, 2, 3, 4, 5], [true, false, true]); + const expected = [1, 3]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("the iterable is smaller than the selector", () => { - const result = compress([1, 2, 3], [true, false, true, false, true]); - const expected = [1, 3]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("compress the iterable is smaller than the selector", () => { + const result = compress([1, 2, 3], [true, false, true, false, true]); + const expected = [1, 3]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/count_test.ts b/count_test.ts index da031fe..f6e311d 100644 --- a/count_test.ts +++ b/count_test.ts @@ -1,73 +1,70 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { take } from "./take.ts"; import { count } from "./count.ts"; -Deno.test("count", async (t) => { - await t.step("default", () => { - const result = count(); - const expected = [0, 1, 2]; - assertEquals(Array.from(take(result, 3)), expected); - assertType>>(true); - }); +await test("count default", () => { + const result = count(); + const expected = [0, 1, 2]; + assertEquals(Array.from(take(result, 3)), expected); + assertType>>(true); +}); - await t.step("with positive start", () => { - const result = count(1); - const expected = [1, 2, 3]; - assertEquals(Array.from(take(result, 3)), expected); - assertType>>(true); - }); +await test("count with positive start", () => { + const result = count(1); + const expected = [1, 2, 3]; + assertEquals(Array.from(take(result, 3)), expected); + assertType>>(true); +}); - await t.step("with negative start", () => { - const result = count(-1); - const expected = [-1, 0, 1]; - assertEquals(Array.from(take(result, 3)), expected); - assertType>>(true); - }); +await test("count with negative start", () => { + const result = count(-1); + const expected = [-1, 0, 1]; + assertEquals(Array.from(take(result, 3)), expected); + assertType>>(true); +}); - await t.step("with float start", () => { - const result = count(1.1); - const expected = [1.1, 2.1, 3.1]; - assertEquals(Array.from(take(result, 3)), expected); - assertType>>(true); - }); +await test("count with float start", () => { + const result = count(1.1); + const expected = [1.1, 2.1, 3.1]; + assertEquals(Array.from(take(result, 3)), expected); + assertType>>(true); +}); - await t.step("with start and positive step", () => { - const result = count(1, 2); - const expected = [1, 3, 5]; - assertEquals(Array.from(take(result, 3)), expected); - assertType>>(true); - }); +await test("count with start and positive step", () => { + const result = count(1, 2); + const expected = [1, 3, 5]; + assertEquals(Array.from(take(result, 3)), expected); + assertType>>(true); +}); - await t.step("with start and negative step", () => { - const result = count(1, -1); - const expected = [1, 0, -1]; - assertEquals(Array.from(take(result, 3)), expected); - assertType>>(true); - }); +await test("count with start and negative step", () => { + const result = count(1, -1); + const expected = [1, 0, -1]; + assertEquals(Array.from(take(result, 3)), expected); + assertType>>(true); +}); - await t.step("with start and float step", () => { - const result = count(1, 0.2); - const expected = [1.0, 1.2, 1.4]; - assertEquals(Array.from(take(result, 3)), expected); - assertType>>(true); - }); +await test("count with start and float step", () => { + const result = count(1, 0.2); + const expected = [1.0, 1.2, 1.4]; + assertEquals(Array.from(take(result, 3)), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the start is not finite", () => { - assertThrows(() => count(NaN), RangeError); - assertThrows(() => count(Infinity), RangeError); - assertThrows(() => count(-Infinity), RangeError); - }); +await test("count throws RangeError if the start is not finite", () => { + assertThrows(() => count(NaN), RangeError); + assertThrows(() => count(Infinity), RangeError); + assertThrows(() => count(-Infinity), RangeError); +}); - await t.step("if the step is not finite", () => { - assertThrows(() => count(0, NaN), RangeError); - assertThrows(() => count(0, Infinity), RangeError); - assertThrows(() => count(0, -Infinity), RangeError); - }); +await test("count throws RangeError if the step is not finite", () => { + assertThrows(() => count(0, NaN), RangeError); + assertThrows(() => count(0, Infinity), RangeError); + assertThrows(() => count(0, -Infinity), RangeError); +}); - await t.step("if the step is 0", () => { - assertThrows(() => count(0, 0), RangeError); - }); - }); +await test("count throws RangeError if the step is 0", () => { + assertThrows(() => count(0, 0), RangeError); }); diff --git a/cycle_test.ts b/cycle_test.ts index 784d2a2..512e27d 100644 --- a/cycle_test.ts +++ b/cycle_test.ts @@ -1,27 +1,26 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { take } from "./take.ts"; import { cycle } from "./cycle.ts"; -Deno.test("cycle", async (t) => { - await t.step("with non empty iterable", () => { - const result = cycle([0, 1, 2]); - const expected = [0, 1, 2, 0, 1]; - assertEquals(Array.from(take(result, 5)), expected); - assertType>>(true); - }); +await test("cycle with non empty iterable", () => { + const result = cycle([0, 1, 2]); + const expected = [0, 1, 2, 0, 1]; + assertEquals(Array.from(take(result, 5)), expected); + assertType>>(true); +}); - await t.step("with single value iterable", () => { - const result = cycle([0]); - const expected = [0, 0, 0, 0, 0]; - assertEquals(Array.from(take(result, 5)), expected); - assertType>>(true); - }); +await test("cycle with single value iterable", () => { + const result = cycle([0]); + const expected = [0, 0, 0, 0, 0]; + assertEquals(Array.from(take(result, 5)), expected); + assertType>>(true); +}); - await t.step("with empty iterable", () => { - const result = cycle([] as number[]); - const expected: number[] = []; - assertEquals(Array.from(take(result, 5)), expected); - assertType>>(true); - }); +await test("cycle with empty iterable", () => { + const result = cycle([] as number[]); + const expected: number[] = []; + assertEquals(Array.from(take(result, 5)), expected); + assertType>>(true); }); diff --git a/deno.jsonc b/deno.jsonc index d902dc2..9ebf782 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -259,6 +259,7 @@ "@core/iterutil/zip": "./zip.ts", "@core/pipe": "jsr:@core/pipe@^0.2.0", "@core/unknownutil": "jsr:@core/unknownutil@^4.0.1", + "@cross/test": "jsr:@cross/test@^0.0.9", "@std/assert": "jsr:@std/assert@^1.0.2", "@std/jsonc": "jsr:@std/jsonc@^1.0.0", "@std/path": "jsr:@std/path@^1.0.2", diff --git a/drop_test.ts b/drop_test.ts index 8a717c8..a24069f 100644 --- a/drop_test.ts +++ b/drop_test.ts @@ -1,29 +1,26 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { drop } from "./drop.ts"; -Deno.test("drop", async (t) => { - await t.step("with positive limit", () => { - const result = drop([0, 1, 2, 3, 4], 2); - const expected = [2, 3, 4]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("drop with positive limit", () => { + const result = drop([0, 1, 2, 3, 4], 2); + const expected = [2, 3, 4]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with 0 limit", () => { - const result = drop([0, 1, 2, 3, 4], 0); - const expected = [0, 1, 2, 3, 4]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("drop with 0 limit", () => { + const result = drop([0, 1, 2, 3, 4], 0); + const expected = [0, 1, 2, 3, 4]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the limit is not 0 nor positive safe integer", () => { - assertThrows(() => drop([], NaN), RangeError); - assertThrows(() => drop([], Infinity), RangeError); - assertThrows(() => drop([], -Infinity), RangeError); - assertThrows(() => drop([], -1), RangeError); - assertThrows(() => drop([], 1.1), RangeError); - }); - }); +await test("drop throws RangeError", () => { + assertThrows(() => drop([], NaN), RangeError); + assertThrows(() => drop([], Infinity), RangeError); + assertThrows(() => drop([], -Infinity), RangeError); + assertThrows(() => drop([], -1), RangeError); + assertThrows(() => drop([], 1.1), RangeError); }); diff --git a/drop_while_test.ts b/drop_while_test.ts index e269a29..85fd766 100644 --- a/drop_while_test.ts +++ b/drop_while_test.ts @@ -1,34 +1,33 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { dropWhile } from "./drop_while.ts"; -Deno.test("dropWhile", async (t) => { - await t.step("with some true", () => { - const values: number[] = []; - const indices: number[] = []; - const result = dropWhile([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v < 3; - }); - const expected = [3, 4, 5]; - assertEquals(Array.from(result), expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>>(true); +await test("dropWhile with some true", () => { + const values: number[] = []; + const indices: number[] = []; + const result = dropWhile([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v < 3; }); + const expected = [3, 4, 5]; + assertEquals(Array.from(result), expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>>(true); +}); - await t.step("with all true", () => { - const result = dropWhile([1, 2, 3, 4, 5], () => true); - const expected: number[] = []; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("dropWhile with all true", () => { + const result = dropWhile([1, 2, 3, 4, 5], () => true); + const expected: number[] = []; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with all false", () => { - const result = dropWhile([1, 2, 3, 4, 5], () => false); - const expected = [1, 2, 3, 4, 5]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("dropWhile with all false", () => { + const result = dropWhile([1, 2, 3, 4, 5], () => false); + const expected = [1, 2, 3, 4, 5]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/enumerate_test.ts b/enumerate_test.ts index 45e0900..5ac0c5d 100644 --- a/enumerate_test.ts +++ b/enumerate_test.ts @@ -1,72 +1,69 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { enumerate } from "./enumerate.ts"; -Deno.test("enumerate", async (t) => { - await t.step("default", () => { - const result = enumerate([0, 1, 2]); - const expected = [[0, 0], [1, 1], [2, 2]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate default", () => { + const result = enumerate([0, 1, 2]); + const expected = [[0, 0], [1, 1], [2, 2]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with positive start", () => { - const result = enumerate([0, 1, 2], 1); - const expected = [[1, 0], [2, 1], [3, 2]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate with positive start", () => { + const result = enumerate([0, 1, 2], 1); + const expected = [[1, 0], [2, 1], [3, 2]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with negative start", () => { - const result = enumerate([0, 1, 2], -1); - const expected = [[-1, 0], [0, 1], [1, 2]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate with negative start", () => { + const result = enumerate([0, 1, 2], -1); + const expected = [[-1, 0], [0, 1], [1, 2]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with float start", () => { - const result = enumerate([0, 1, 2], 1.1); - const expected = [[1.1, 0], [2.1, 1], [3.1, 2]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate with float start", () => { + const result = enumerate([0, 1, 2], 1.1); + const expected = [[1.1, 0], [2.1, 1], [3.1, 2]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with start and positive step", () => { - const result = enumerate([0, 1, 2], 1, 2); - const expected = [[1, 0], [3, 1], [5, 2]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate with start and positive step", () => { + const result = enumerate([0, 1, 2], 1, 2); + const expected = [[1, 0], [3, 1], [5, 2]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with start and negative step", () => { - const result = enumerate([0, 1, 2], 1, -1); - const expected = [[1, 0], [0, 1], [-1, 2]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate with start and negative step", () => { + const result = enumerate([0, 1, 2], 1, -1); + const expected = [[1, 0], [0, 1], [-1, 2]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with start and float step", () => { - const result = enumerate([0, 1, 2], 1, 0.2); - const expected = [[1, 0], [1.2, 1], [1.4, 2]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate with start and float step", () => { + const result = enumerate([0, 1, 2], 1, 0.2); + const expected = [[1, 0], [1.2, 1], [1.4, 2]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the start is not finite", () => { - assertThrows(() => enumerate([], NaN), RangeError); - assertThrows(() => enumerate([], Infinity), RangeError); - assertThrows(() => enumerate([], -Infinity), RangeError); - }); +await test("enumerate throws RangeError if the start is not finite", () => { + assertThrows(() => enumerate([], NaN), RangeError); + assertThrows(() => enumerate([], Infinity), RangeError); + assertThrows(() => enumerate([], -Infinity), RangeError); +}); - await t.step("if the step is not finite", () => { - assertThrows(() => enumerate([], 0, NaN), RangeError); - assertThrows(() => enumerate([], 0, Infinity), RangeError); - assertThrows(() => enumerate([], 0, -Infinity), RangeError); - }); +await test("enumerate throws RangeError if the step is not finite", () => { + assertThrows(() => enumerate([], 0, NaN), RangeError); + assertThrows(() => enumerate([], 0, Infinity), RangeError); + assertThrows(() => enumerate([], 0, -Infinity), RangeError); +}); - await t.step("if the step is 0", () => { - assertThrows(() => enumerate([], 0, 0), RangeError); - }); - }); +await test("enumerate throws RangeError if the step is 0", () => { + assertThrows(() => enumerate([], 0, 0), RangeError); }); diff --git a/every_test.ts b/every_test.ts index 35f91ac..b4ee00c 100644 --- a/every_test.ts +++ b/every_test.ts @@ -1,38 +1,37 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { every } from "./every.ts"; -Deno.test("every", async (t) => { - await t.step("returns true if all elements satisfy the function", () => { +await test("every returns true if all elements satisfy the function", () => { + const values: number[] = []; + const indices: number[] = []; + const result = every([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v < 6; + }); + const expected = true; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); + +await test( + "every returns false if not all elements satisfy the function", + () => { const values: number[] = []; const indices: number[] = []; const result = every([1, 2, 3, 4, 5], (v, index) => { values.push(v); indices.push(index); - return v < 6; + return v < 3; }); - const expected = true; + const expected = false; assertEquals(result, expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); assertType>(true); - }); - - await t.step( - "returns false if not all elements satisfy the function", - () => { - const values: number[] = []; - const indices: number[] = []; - const result = every([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v < 3; - }); - const expected = false; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>(true); - }, - ); -}); + }, +); diff --git a/filter_test.ts b/filter_test.ts index 76891e7..e49c3e9 100644 --- a/filter_test.ts +++ b/filter_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { filter } from "./filter.ts"; -Deno.test("filter", () => { +test("filter", () => { const values: number[] = []; const indices: number[] = []; const result = filter([1, 2, 3, 4, 5], (v, index) => { diff --git a/find_test.ts b/find_test.ts index 68a2009..487fd10 100644 --- a/find_test.ts +++ b/find_test.ts @@ -1,27 +1,26 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { find } from "./find.ts"; -Deno.test("find", async (t) => { - await t.step("found", () => { - const values: number[] = []; - const indices: number[] = []; - const result = find([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v % 2 === 0; - }); - const expected = 2; - assertEquals(result, expected); - assertEquals(values, [1, 2]); - assertEquals(indices, [0, 1]); - assertType>(true); +await test("find found", () => { + const values: number[] = []; + const indices: number[] = []; + const result = find([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v % 2 === 0; }); + const expected = 2; + assertEquals(result, expected); + assertEquals(values, [1, 2]); + assertEquals(indices, [0, 1]); + assertType>(true); +}); - await t.step("not found", () => { - const result = find([1, 2, 3, 4, 5], () => false); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); +await test("find not found", () => { + const result = find([1, 2, 3, 4, 5], () => false); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); }); diff --git a/first_test.ts b/first_test.ts index f76a546..4396e66 100644 --- a/first_test.ts +++ b/first_test.ts @@ -1,19 +1,18 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { first } from "./first.ts"; -Deno.test("first", async (t) => { - await t.step("with non empty iterable", () => { - const result = first([1, 2, 3, 4, 5]); - const expected = 1; - assertEquals(result, expected); - assertType>(true); - }); +await test("first with non empty iterable", () => { + const result = first([1, 2, 3, 4, 5]); + const expected = 1; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with empty iterable", () => { - const result = first([] as number[]); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); +await test("first with empty iterable", () => { + const result = first([] as number[]); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); }); diff --git a/flat_map_test.ts b/flat_map_test.ts index 5488ac6..589b694 100644 --- a/flat_map_test.ts +++ b/flat_map_test.ts @@ -1,27 +1,26 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { flatMap } from "./flat_map.ts"; -Deno.test("flatMap", async (t) => { - await t.step("single nest", () => { - const values: number[] = []; - const indices: number[] = []; - const result = flatMap([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return [v, v]; - }); - const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; - assertEquals(Array.from(result), expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>>(true); +await test("flatMap single nest", () => { + const values: number[] = []; + const indices: number[] = []; + const result = flatMap([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return [v, v]; }); + const expected = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]; + assertEquals(Array.from(result), expected); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>>(true); +}); - await t.step("multi nest", () => { - const result = flatMap([1, 2, 3, 4, 5], (v) => [[v, v]]); - const expected = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("flatMap multi nest", () => { + const result = flatMap([1, 2, 3, 4, 5], (v) => [[v, v]]); + const expected = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/flatten_test.ts b/flatten_test.ts index 2e4ca2e..2277793 100644 --- a/flatten_test.ts +++ b/flatten_test.ts @@ -1,19 +1,18 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { flatten } from "./flatten.ts"; -Deno.test("flatten", async (t) => { - await t.step("single nest", () => { - const result = flatten([[1, 2], [3, 4], [5]]); - const expected = [1, 2, 3, 4, 5]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("flatten single nest", () => { + const result = flatten([[1, 2], [3, 4], [5]]); + const expected = [1, 2, 3, 4, 5]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("multi nest", () => { - const result = flatten([[[1, 2], [3, 4]], [[5]]]); - const expected = [[1, 2], [3, 4], [5]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("flatten multi nest", () => { + const result = flatten([[[1, 2], [3, 4]], [[5]]]); + const expected = [[1, 2], [3, 4], [5]]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/for_each_test.ts b/for_each_test.ts index c9da733..50610d9 100644 --- a/for_each_test.ts +++ b/for_each_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { forEach } from "./for_each.ts"; -Deno.test("forEach", () => { +test("forEach", () => { const values: number[] = []; const indices: number[] = []; forEach([1, 2, 3, 4, 5], (v, index) => { diff --git a/iter_test.ts b/iter_test.ts index 4da62b9..fb0447a 100644 --- a/iter_test.ts +++ b/iter_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { iter } from "./iter.ts"; -Deno.test("iter", () => { +test("iter", () => { const it = iter([0, 1, 2, 3, 4, 5]); assertEquals(it.next(), { done: false, value: 0 }); assertEquals(it.next(), { done: false, value: 1 }); diff --git a/last_test.ts b/last_test.ts index 50a859b..83a5af9 100644 --- a/last_test.ts +++ b/last_test.ts @@ -1,19 +1,18 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { last } from "./last.ts"; -Deno.test("last", async (t) => { - await t.step("with non empty iterable", () => { - const result = last([1, 2, 3, 4, 5]); - const expected = 5; - assertEquals(result, expected); - assertType>(true); - }); +await test("last with non empty iterable", () => { + const result = last([1, 2, 3, 4, 5]); + const expected = 5; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with empty iterable", () => { - const result = last([] as number[]); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); +await test("last with empty iterable", () => { + const result = last([] as number[]); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); }); diff --git a/map_test.ts b/map_test.ts index d83b624..5fbba06 100644 --- a/map_test.ts +++ b/map_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { map } from "./map.ts"; -Deno.test("map", () => { +test("map", () => { const values: number[] = []; const indices: number[] = []; const result = map([1, 2, 3, 4, 5], (v, index) => { diff --git a/mod_test.ts b/mod_test.ts index 4030b75..66d5ec8 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cross/test"; import { assertArrayIncludes } from "@std/assert"; import { basename, globToRegExp, join } from "@std/path"; import { ensure, is } from "@core/unknownutil"; @@ -9,23 +10,23 @@ const excludes = [ "*_bench.ts", ]; -Deno.test("mod.ts must exports all exports in public modules", async () => { +test("mod.ts must exports all exports in public modules", async () => { const modExports = await listModExports("./mod.ts"); const pubExports = []; for await (const name of iterPublicModules(".")) { pubExports.push(...await listModExports(`./${name}.ts`)); } assertArrayIncludes(modExports, pubExports); -}); +}, { skip: !("Deno" in globalThis) }); -Deno.test("JSR exports must have all exports in mod.ts", async () => { +test("JSR exports must have all exports in mod.ts", async () => { const jsrExportEntries = await listJsrExportEntries(); const modExportEntries: [string, string][] = []; for await (const name of iterPublicModules(".")) { modExportEntries.push([`./${name.replaceAll("_", "-")}`, `./${name}.ts`]); } assertArrayIncludes(jsrExportEntries, modExportEntries); -}); +}, { skip: !("Deno" in globalThis) }); async function* iterPublicModules(relpath: string): AsyncIterable { const patterns = excludes.map((p) => globToRegExp(p)); diff --git a/nth_test.ts b/nth_test.ts index c56f330..f0adbf4 100644 --- a/nth_test.ts +++ b/nth_test.ts @@ -1,29 +1,26 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { nth } from "./nth.ts"; -Deno.test("nth", async (t) => { - await t.step("with non empty iterable", () => { - const result = nth([1, 2, 3, 4, 5], 2); - const expected = 3; - assertEquals(result, expected); - assertType>(true); - }); +await test("nth with non empty iterable", () => { + const result = nth([1, 2, 3, 4, 5], 2); + const expected = 3; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("with empty iterable", () => { - const result = nth([] as number[], 2); - const expected = undefined; - assertEquals(result, expected); - assertType>(true); - }); +await test("nth with empty iterable", () => { + const result = nth([] as number[], 2); + const expected = undefined; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the index is not 0 nor positive safe integer", () => { - assertThrows(() => nth([], NaN), RangeError); - assertThrows(() => nth([], Infinity), RangeError); - assertThrows(() => nth([], -Infinity), RangeError); - assertThrows(() => nth([], -1), RangeError); - assertThrows(() => nth([], 1.1), RangeError); - }); - }); +await test("nth throws RangeError", () => { + assertThrows(() => nth([], NaN), RangeError); + assertThrows(() => nth([], Infinity), RangeError); + assertThrows(() => nth([], -Infinity), RangeError); + assertThrows(() => nth([], -1), RangeError); + assertThrows(() => nth([], 1.1), RangeError); }); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..ecbb697 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,139 @@ +{ + "name": "iterutil", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "@core/pipe": "npm:@jsr/core__pipe@^0.2.0-pre.0", + "@core/unknownutil": "npm:@jsr/core__unknownutil@^4.2.0", + "@cross/test": "npm:@jsr/cross__test@^0.0.9", + "@std/assert": "npm:@jsr/std__assert@^1.0.2", + "@std/jsonc": "npm:@jsr/std__jsonc@^1.0.0-rc.3", + "@std/path": "npm:@jsr/std__path@^1.0.2", + "@std/testing": "npm:@jsr/std__testing@^1.0.0-rc.5" + } + }, + "node_modules/@core/pipe": { + "name": "@jsr/core__pipe", + "version": "0.2.0-pre.0", + "resolved": "https://npm.jsr.io/~/11/@jsr/core__pipe/0.2.0-pre.0.tgz", + "integrity": "sha512-cumolb49PjxtO+CZq+d/DSYK070S8Tq40Cn4FKfDOsLMExIHZaRbfYZIbop+67dk9oc9MjUiWbfVR7Rgx2ZAyw==" + }, + "node_modules/@core/unknownutil": { + "name": "@jsr/core__unknownutil", + "version": "4.2.0", + "resolved": "https://npm.jsr.io/~/11/@jsr/core__unknownutil/4.2.0.tgz", + "integrity": "sha512-HA5TxLa7E1mSNwiG1oRPfeq09SSrr6OH9TIeM5ECy14Vzv3hnsxxQO4il6Nt24HwMwFt2NkJ/RUqWD07Kbyg4g==" + }, + "node_modules/@cross/test": { + "name": "@jsr/cross__test", + "version": "0.0.9", + "resolved": "https://npm.jsr.io/~/11/@jsr/cross__test/0.0.9.tgz", + "integrity": "sha512-zwDSXQHw8n6k/gBj1Q67Td34Lb1PfkzLTggXnNZzcRO9SxcdAlzyOKFCF62kTFM7ZjVPqYvqu2gHzMLtj6cayw==", + "dependencies": { + "@jsr/cross__runtime": "^1.0.0" + } + }, + "node_modules/@jsr/cross__runtime": { + "version": "1.0.0", + "resolved": "https://npm.jsr.io/~/11/@jsr/cross__runtime/1.0.0.tgz", + "integrity": "sha512-wUtjVBTk65ae4AKQRnxD5x3h4vVmopdKAYie/uS01Qolii2XQ81bKtRTvJ4kx133GYYgIAgyl3ihQ0OK8LcPmQ==" + }, + "node_modules/@jsr/std__assert": { + "version": "1.0.2", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__assert/1.0.2.tgz", + "integrity": "sha512-xujHXXeT3zvMNZeCXiDyfiITaqP4rgH8wqHNUD0Iyr4c2R0Ea//zJ4pASA1utIEIxeVu1jpeSlHU4+pagscqgQ==", + "dependencies": { + "@jsr/std__internal": "^1.0.1" + } + }, + "node_modules/@jsr/std__async": { + "version": "1.0.3", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__async/1.0.3.tgz", + "integrity": "sha512-j5NZqYHN/czhfjBKh0jvPU5IRhP3Y5Lk7X3qL5ghw0gDSwI8h/kzlxSMV98ML0L6tXN9SvZU8lqa8Q5evtL4sA==" + }, + "node_modules/@jsr/std__bytes": { + "version": "1.0.2", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__bytes/1.0.2.tgz", + "integrity": "sha512-bkZ1rllRB1qsxFbPqtO1VAYTW2+3ZDmf6pcy8xihKS33r0Z1ly6/E/5DoapnJsNy05LdnANUySWt5kj/awgGdg==" + }, + "node_modules/@jsr/std__data-structures": { + "version": "1.0.1", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__data-structures/1.0.1.tgz", + "integrity": "sha512-rxVsLaPwJEZNqVAfvOSfVw9WKgLwzUgwUIs7aMjKogGSPBSJkwXED6a3zL4eIrXQR+HR3+E0/Y10XYifu0gHkw==" + }, + "node_modules/@jsr/std__fs": { + "version": "1.0.1", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__fs/1.0.1.tgz", + "integrity": "sha512-QXNJz3X3IBYhxC1KEhtNPCUrtS8bofqxlVVN8ONrWXm0V9LbaJKJzsKsH3Z2KvdDmdHF3u+sNjRpafbJkOYedg==", + "dependencies": { + "@jsr/std__path": "^1.0.2" + } + }, + "node_modules/@jsr/std__internal": { + "version": "1.0.1", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__internal/1.0.1.tgz", + "integrity": "sha512-ssI1kvluIero6cCfiWNmYItqCR8QpQB+STBJoe/xQVZ79SDpoqjK5VF2Eq/2M+Dz8WbqHVmrXRCaGN162x+Ebw==" + }, + "node_modules/@jsr/std__json": { + "version": "1.0.0-rc.3", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__json/1.0.0-rc.3.tgz", + "integrity": "sha512-nsHLvMmWTir390Ce3BUlteMF94vqRGpy3MVBi1fGmX7PqnWjpkThBmZJ9vpxME5HAkmA2sBaAOd0FqfQYlR0hw==", + "dependencies": { + "@jsr/std__streams": "^1.0.0-rc.4" + } + }, + "node_modules/@jsr/std__path": { + "version": "1.0.2", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__path/1.0.2.tgz", + "integrity": "sha512-VadQVUlJZhIjRi8RcDQcNzqKcowfEdqntIXhphae0MeHaC1y60OiFealO25WTzBTHqBC58KFNlM7KWH+tepgOg==" + }, + "node_modules/@jsr/std__streams": { + "version": "1.0.1", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__streams/1.0.1.tgz", + "integrity": "sha512-riI7IEm66WrrL2dhSRxm1DQdD1zkI+K/ZUQABaj4hSTysURew4No66TGZNKgS2pZMz6LnWol72pz5dmYTbZlyQ==", + "dependencies": { + "@jsr/std__bytes": "^1.0.2-rc.3" + } + }, + "node_modules/@std/assert": { + "name": "@jsr/std__assert", + "version": "1.0.2", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__assert/1.0.2.tgz", + "integrity": "sha512-xujHXXeT3zvMNZeCXiDyfiITaqP4rgH8wqHNUD0Iyr4c2R0Ea//zJ4pASA1utIEIxeVu1jpeSlHU4+pagscqgQ==", + "dependencies": { + "@jsr/std__internal": "^1.0.1" + } + }, + "node_modules/@std/jsonc": { + "name": "@jsr/std__jsonc", + "version": "1.0.0-rc.3", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__jsonc/1.0.0-rc.3.tgz", + "integrity": "sha512-4qWZ9mrCieAfQQSdLuSPIUqShG0vJbzA0jmm1ON58VbfQGmftRgC1vfVqRAOpgBwm5GhDZzI+MLhRRqEAF8XSg==", + "dependencies": { + "@jsr/std__json": "^1.0.0-rc.3" + } + }, + "node_modules/@std/path": { + "name": "@jsr/std__path", + "version": "1.0.2", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__path/1.0.2.tgz", + "integrity": "sha512-VadQVUlJZhIjRi8RcDQcNzqKcowfEdqntIXhphae0MeHaC1y60OiFealO25WTzBTHqBC58KFNlM7KWH+tepgOg==" + }, + "node_modules/@std/testing": { + "name": "@jsr/std__testing", + "version": "1.0.0-rc.5", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__testing/1.0.0-rc.5.tgz", + "integrity": "sha512-p4Fa2fFk3qS9VMkpCCTmo/Jgwz7h6+iXBPbDVSgy2lbAyBDGWVw8d4S0qx8i7O6TQkSgEHyB4bP9z8HYao7NyQ==", + "dependencies": { + "@jsr/std__assert": "^1.0.1", + "@jsr/std__async": "^1.0.1", + "@jsr/std__data-structures": "^1.0.1", + "@jsr/std__fs": "^1.0.0", + "@jsr/std__internal": "^1.0.1", + "@jsr/std__path": "^1.0.2" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..c873dee --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "type": "module", + "dependencies": { + "@core/pipe": "npm:@jsr/core__pipe@^0.2.0-pre.0", + "@core/unknownutil": "npm:@jsr/core__unknownutil@^4.2.0", + "@cross/test": "npm:@jsr/cross__test@^0.0.9", + "@std/assert": "npm:@jsr/std__assert@^1.0.2", + "@std/jsonc": "npm:@jsr/std__jsonc@^1.0.0-rc.3", + "@std/path": "npm:@jsr/std__path@^1.0.2", + "@std/testing": "npm:@jsr/std__testing@^1.0.0-rc.5" + } +} diff --git a/pairwise_test.ts b/pairwise_test.ts index 58c1bc1..b345774 100644 --- a/pairwise_test.ts +++ b/pairwise_test.ts @@ -1,26 +1,25 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pairwise } from "./pairwise.ts"; -Deno.test("pairwise", async (t) => { - await t.step("with non empty iterable", () => { - const result = pairwise([1, 2, 3, 4, 5]); - const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("pairwise with non empty iterable", () => { + const result = pairwise([1, 2, 3, 4, 5]); + const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with single value iterable", () => { - const result = pairwise([1]); - const expected: number[][] = []; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("pairwise with single value iterable", () => { + const result = pairwise([1]); + const expected: number[][] = []; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with empty iterable", () => { - const result = pairwise([] as number[]); - const expected: number[][] = []; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("pairwise with empty iterable", () => { + const result = pairwise([] as number[]); + const expected: number[][] = []; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/partition_test.ts b/partition_test.ts index d49bc26..18f29cd 100644 --- a/partition_test.ts +++ b/partition_test.ts @@ -1,29 +1,28 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { partition } from "./partition.ts"; -Deno.test("partition", async (t) => { - await t.step("with non empty iterable", () => { - const values: number[] = []; - const indices: number[] = []; - const [left, right] = partition([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v % 2 === 0; - }); - assertEquals(left, [2, 4]); - assertEquals(right, [1, 3, 5]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - assertType>(true); +await test("partition with non empty iterable", () => { + const values: number[] = []; + const indices: number[] = []; + const [left, right] = partition([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v % 2 === 0; }); + assertEquals(left, [2, 4]); + assertEquals(right, [1, 3, 5]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); + assertType>(true); +}); - await t.step("with empty iterable", () => { - const [left, right] = partition([] as number[], (v) => v % 2 === 0); - assertEquals(left, []); - assertEquals(right, []); - assertType>(true); - assertType>(true); - }); +await test("partition with empty iterable", () => { + const [left, right] = partition([] as number[], (v) => v % 2 === 0); + assertEquals(left, []); + assertEquals(right, []); + assertType>(true); + assertType>(true); }); diff --git a/pipe/async/chain.ts b/pipe/async/chain.ts index fb5a959..1049799 100644 --- a/pipe/async/chain.ts +++ b/pipe/async/chain.ts @@ -1,4 +1,4 @@ -import { type Chain, chain as base } from "@core/iterutil/async/chain"; +import { type Chain, chain as base } from "../../async/chain.ts"; /** * Returns an operator that chains multiple iterables to the iterable. diff --git a/pipe/async/chain_test.ts b/pipe/async/chain_test.ts index 87f07ae..c55d605 100644 --- a/pipe/async/chain_test.ts +++ b/pipe/async/chain_test.ts @@ -1,20 +1,19 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { chain } from "./chain.ts"; -Deno.test("chain", async (t) => { - await t.step("usage", async () => { - const result = pipe( - [1, 2, 3], - chain(["a", "b"], [true]), - ); - const expected = [1, 2, 3, "a", "b", true]; - assertEquals(await Array.fromAsync(result), expected); - assertType< - IsExact> - >( - true, - ); - }); +await test("chain usage", async () => { + const result = pipe( + [1, 2, 3], + chain(["a", "b"], [true]), + ); + const expected = [1, 2, 3, "a", "b", true]; + assertEquals(await Array.fromAsync(result), expected); + assertType< + IsExact> + >( + true, + ); }); diff --git a/pipe/async/chunked.ts b/pipe/async/chunked.ts index 05a9a2b..b464335 100644 --- a/pipe/async/chunked.ts +++ b/pipe/async/chunked.ts @@ -1,4 +1,4 @@ -import { chunked as base } from "@core/iterutil/async/chunked"; +import { chunked as base } from "../../async/chunked.ts"; /** * Returns an operator that chunks the iterable into arrays of `size`. diff --git a/pipe/async/chunked_test.ts b/pipe/async/chunked_test.ts index e1c8a42..230eac7 100644 --- a/pipe/async/chunked_test.ts +++ b/pipe/async/chunked_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { chunked } from "./chunked.ts"; -Deno.test("chunked", async (t) => { - await t.step("usage", async () => { - const result = pipe([1, 2, 3, 4, 5, 6], chunked(2)); - const expected = [[1, 2], [3, 4], [5, 6]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("chunked usage", async () => { + const result = pipe([1, 2, 3, 4, 5, 6], chunked(2)); + const expected = [[1, 2], [3, 4], [5, 6]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/compact.ts b/pipe/async/compact.ts index c948c8f..7b292d3 100644 --- a/pipe/async/compact.ts +++ b/pipe/async/compact.ts @@ -1,4 +1,4 @@ -import { compact } from "@core/iterutil/async/compact"; +import { compact } from "../../async/compact.ts"; export { /** diff --git a/pipe/async/compact_test.ts b/pipe/async/compact_test.ts index 0745363..0e831d3 100644 --- a/pipe/async/compact_test.ts +++ b/pipe/async/compact_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { compact } from "./compact.ts"; -Deno.test("compact", async (t) => { - await t.step("usage", async () => { - const result = pipe([1, undefined, 2, null, 3], compact); - const expected = [1, 2, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compact usage", async () => { + const result = pipe([1, undefined, 2, null, 3], compact); + const expected = [1, 2, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/compress.ts b/pipe/async/compress.ts index 65a3261..df28bfb 100644 --- a/pipe/async/compress.ts +++ b/pipe/async/compress.ts @@ -1,4 +1,4 @@ -import { compress as base } from "@core/iterutil/async/compress"; +import { compress as base } from "../../async/compress.ts"; /** * Returns an operator that compresses an iterable by selecting elements using a selector iterable. diff --git a/pipe/async/compress_test.ts b/pipe/async/compress_test.ts index 3b800bd..4de7318 100644 --- a/pipe/async/compress_test.ts +++ b/pipe/async/compress_test.ts @@ -1,16 +1,15 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { compress } from "./compress.ts"; -Deno.test("compress", async (t) => { - await t.step("usage", async () => { - const result = pipe( - [1, 2, 3, 4, 5], - compress([true, false, true, false, true]), - ); - const expected = [1, 3, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("compress usage", async () => { + const result = pipe( + [1, 2, 3, 4, 5], + compress([true, false, true, false, true]), + ); + const expected = [1, 3, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/cycle.ts b/pipe/async/cycle.ts index 889f99c..4309edd 100644 --- a/pipe/async/cycle.ts +++ b/pipe/async/cycle.ts @@ -1,4 +1,4 @@ -import { cycle } from "@core/iterutil/async/cycle"; +import { cycle } from "../../async/cycle.ts"; export { /** diff --git a/pipe/async/cycle_test.ts b/pipe/async/cycle_test.ts index 5555703..bdf6f2f 100644 --- a/pipe/async/cycle_test.ts +++ b/pipe/async/cycle_test.ts @@ -1,14 +1,13 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { take } from "./take.ts"; import { cycle } from "./cycle.ts"; -Deno.test("cycle", async (t) => { - await t.step("usage", async () => { - const result = pipe([0, 1, 2], cycle, take(5)); - const expected = [0, 1, 2, 0, 1]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("cycle usage", async () => { + const result = pipe([0, 1, 2], cycle, take(5)); + const expected = [0, 1, 2, 0, 1]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/drop.ts b/pipe/async/drop.ts index e479b19..5a7b4ba 100644 --- a/pipe/async/drop.ts +++ b/pipe/async/drop.ts @@ -1,4 +1,4 @@ -import { drop as base } from "@core/iterutil/async/drop"; +import { drop as base } from "../../async/drop.ts"; /** * Returns an operator that drops the first `limit` items from the iterable. diff --git a/pipe/async/drop_test.ts b/pipe/async/drop_test.ts index da1b68e..b28d078 100644 --- a/pipe/async/drop_test.ts +++ b/pipe/async/drop_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { drop } from "./drop.ts"; -Deno.test("drop", async (t) => { - await t.step("usage", async () => { - const result = pipe([0, 1, 2, 3, 4], drop(2)); - const expected = [2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("drop usage", async () => { + const result = pipe([0, 1, 2, 3, 4], drop(2)); + const expected = [2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/drop_while.ts b/pipe/async/drop_while.ts index c82534a..27c3977 100644 --- a/pipe/async/drop_while.ts +++ b/pipe/async/drop_while.ts @@ -1,4 +1,4 @@ -import { dropWhile as base } from "@core/iterutil/async/drop-while"; +import { dropWhile as base } from "../../async/drop_while.ts"; /** * Returns an operator that drops elements from the iterable while the predicate returns true. diff --git a/pipe/async/drop_while_test.ts b/pipe/async/drop_while_test.ts index 90dec97..f1ba4bd 100644 --- a/pipe/async/drop_while_test.ts +++ b/pipe/async/drop_while_test.ts @@ -1,16 +1,15 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { dropWhile } from "./drop_while.ts"; -Deno.test("dropWhile", async (t) => { - await t.step("usage", async () => { - const result = pipe( - [0, 1, 2, 3, 4], - dropWhile((v) => v < 2), - ); - const expected = [2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("dropWhile usage", async () => { + const result = pipe( + [0, 1, 2, 3, 4], + dropWhile((v) => v < 2), + ); + const expected = [2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/enumerate.ts b/pipe/async/enumerate.ts index 6135971..2487f19 100644 --- a/pipe/async/enumerate.ts +++ b/pipe/async/enumerate.ts @@ -1,4 +1,4 @@ -import { enumerate as base } from "@core/iterutil/async/enumerate"; +import { enumerate as base } from "../../async/enumerate.ts"; /** * Returns an operator that enumerates the iterable. diff --git a/pipe/async/enumerate_test.ts b/pipe/async/enumerate_test.ts index bb733fb..e129911 100644 --- a/pipe/async/enumerate_test.ts +++ b/pipe/async/enumerate_test.ts @@ -1,27 +1,26 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { enumerate } from "./enumerate.ts"; -Deno.test("enumerate", async (t) => { - await t.step("usage 1", async () => { - const result = pipe(["a", "b", "c"], enumerate()); - const expected = [[0, "a"], [1, "b"], [2, "c"]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("enumerate usage 1", async () => { + const result = pipe(["a", "b", "c"], enumerate()); + const expected = [[0, "a"], [1, "b"], [2, "c"]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("usage 2", async () => { - const result = pipe(["a", "b", "c"], enumerate(1)); - const expected = [[1, "a"], [2, "b"], [3, "c"]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("enumerate usage 2", async () => { + const result = pipe(["a", "b", "c"], enumerate(1)); + const expected = [[1, "a"], [2, "b"], [3, "c"]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("usage 3", async () => { - const result = pipe(["a", "b", "c"], enumerate(1, 2)); - const expected = [[1, "a"], [3, "b"], [5, "c"]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("enumerate usage 3", async () => { + const result = pipe(["a", "b", "c"], enumerate(1, 2)); + const expected = [[1, "a"], [3, "b"], [5, "c"]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/every.ts b/pipe/async/every.ts index fb73d7d..f77e364 100644 --- a/pipe/async/every.ts +++ b/pipe/async/every.ts @@ -1,4 +1,4 @@ -import { every as base } from "@core/iterutil/async/every"; +import { every as base } from "../../async/every.ts"; /** * Returns an operator that tests whether every element in the iterable satisfies the provided testing function. diff --git a/pipe/async/every_test.ts b/pipe/async/every_test.ts index f370c9f..1aecc1c 100644 --- a/pipe/async/every_test.ts +++ b/pipe/async/every_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { every } from "./every.ts"; -Deno.test("every", async (t) => { - await t.step("usage", async () => { - const result = await pipe([1, 2, 3], every((v) => v > 0)); - const expected = true; - assertEquals(result, expected); - assertType>(true); - }); +await test("every usage", async () => { + const result = await pipe([1, 2, 3], every((v) => v > 0)); + const expected = true; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/async/filter.ts b/pipe/async/filter.ts index 0bce187..be160af 100644 --- a/pipe/async/filter.ts +++ b/pipe/async/filter.ts @@ -1,4 +1,4 @@ -import { filter as base } from "@core/iterutil/async/filter"; +import { filter as base } from "../../async/filter.ts"; /** * Returns an operator that filters an iterable based on a function. diff --git a/pipe/async/filter_test.ts b/pipe/async/filter_test.ts index 8498e72..f327bf6 100644 --- a/pipe/async/filter_test.ts +++ b/pipe/async/filter_test.ts @@ -1,9 +1,10 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { filter } from "./filter.ts"; -Deno.test("filter", async () => { +test("filter usage", async () => { const result = pipe( [1, 2, 3, 4, 5], filter((v) => v % 2 === 0), diff --git a/pipe/async/find.ts b/pipe/async/find.ts index f2ab497..8236ae2 100644 --- a/pipe/async/find.ts +++ b/pipe/async/find.ts @@ -1,4 +1,4 @@ -import { find as base } from "@core/iterutil/async/find"; +import { find as base } from "../../async/find.ts"; /** * Returns an operator that finds the first element that satisfies the provided testing function. diff --git a/pipe/async/find_test.ts b/pipe/async/find_test.ts index 4f6b09a..28a6636 100644 --- a/pipe/async/find_test.ts +++ b/pipe/async/find_test.ts @@ -1,16 +1,15 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { find } from "./find.ts"; -Deno.test("find", async (t) => { - await t.step("usage", async () => { - const result = await pipe( - [1, 2, 3, 4, 5], - find((v) => v % 2 === 0), - ); - const expected = 2; - assertEquals(result, expected); - assertType>(true); - }); +await test("find usage", async () => { + const result = await pipe( + [1, 2, 3, 4, 5], + find((v) => v % 2 === 0), + ); + const expected = 2; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/async/first.ts b/pipe/async/first.ts index 0ccf5b7..fa33a95 100644 --- a/pipe/async/first.ts +++ b/pipe/async/first.ts @@ -1,4 +1,4 @@ -import { first } from "@core/iterutil/async/first"; +import { first } from "../../async/first.ts"; export { /** diff --git a/pipe/async/first_test.ts b/pipe/async/first_test.ts index 698d07f..3420de1 100644 --- a/pipe/async/first_test.ts +++ b/pipe/async/first_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { first } from "./first.ts"; -Deno.test("first", async (t) => { - await t.step("usage", async () => { - const result = await pipe([1, 2, 3], first); - const expected = 1; - assertEquals(result, expected); - assertType>(true); - }); +await test("first usage", async () => { + const result = await pipe([1, 2, 3], first); + const expected = 1; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/async/flat_map.ts b/pipe/async/flat_map.ts index 2c683ac..6336178 100644 --- a/pipe/async/flat_map.ts +++ b/pipe/async/flat_map.ts @@ -1,4 +1,4 @@ -import { flatMap as base } from "@core/iterutil/async/flat-map"; +import { flatMap as base } from "../../async/flat_map.ts"; /** * Returns an operator that flat maps the iterable. diff --git a/pipe/async/flat_map_test.ts b/pipe/async/flat_map_test.ts index d7254ea..ad93c0f 100644 --- a/pipe/async/flat_map_test.ts +++ b/pipe/async/flat_map_test.ts @@ -1,16 +1,15 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { flatMap } from "./flat_map.ts"; -Deno.test("flatMap", async (t) => { - await t.step("usage", async () => { - const result = pipe( - [1, 2, 3], - flatMap((v) => [v, v]), - ); - const expected = [1, 1, 2, 2, 3, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("flatMap usage", async () => { + const result = pipe( + [1, 2, 3], + flatMap((v) => [v, v]), + ); + const expected = [1, 1, 2, 2, 3, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/flatten.ts b/pipe/async/flatten.ts index 03735fb..7c3d5f4 100644 --- a/pipe/async/flatten.ts +++ b/pipe/async/flatten.ts @@ -1,4 +1,4 @@ -import { flatten } from "@core/iterutil/async/flatten"; +import { flatten } from "../../async/flatten.ts"; export { /** diff --git a/pipe/async/flatten_test.ts b/pipe/async/flatten_test.ts index 8f0520e..aa8f839 100644 --- a/pipe/async/flatten_test.ts +++ b/pipe/async/flatten_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { flatten } from "./flatten.ts"; -Deno.test("flatten", async (t) => { - await t.step("usage", async () => { - const result = pipe([[1, 2], [3, 4], [5]], flatten); - const expected = [1, 2, 3, 4, 5]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("flatten usage", async () => { + const result = pipe([[1, 2], [3, 4], [5]], flatten); + const expected = [1, 2, 3, 4, 5]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/for_each.ts b/pipe/async/for_each.ts index 71a3194..5ede3c2 100644 --- a/pipe/async/for_each.ts +++ b/pipe/async/for_each.ts @@ -1,4 +1,4 @@ -import { forEach as base } from "@core/iterutil/async/for-each"; +import { forEach as base } from "../../async/for_each.ts"; /** * Returns an operator that calls the given function for each value in the iterable. diff --git a/pipe/async/for_each_test.ts b/pipe/async/for_each_test.ts index 54f4674..9c79ea7 100644 --- a/pipe/async/for_each_test.ts +++ b/pipe/async/for_each_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { pipe } from "@core/pipe"; import { forEach } from "./for_each.ts"; -Deno.test("forEach", async () => { +test("forEach usage", async () => { const values: number[] = []; await pipe( [1, 2, 3, 4, 5], diff --git a/pipe/async/last.ts b/pipe/async/last.ts index 558aa0a..6a09734 100644 --- a/pipe/async/last.ts +++ b/pipe/async/last.ts @@ -1,4 +1,4 @@ -import { last } from "@core/iterutil/async/last"; +import { last } from "../../async/last.ts"; export { /** diff --git a/pipe/async/last_test.ts b/pipe/async/last_test.ts index dec0ef2..e765b9d 100644 --- a/pipe/async/last_test.ts +++ b/pipe/async/last_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { last } from "./last.ts"; -Deno.test("last", async (t) => { - await t.step("usage", async () => { - const result = await pipe([1, 2, 3], last); - const expected = 3; - assertEquals(result, expected); - assertType>(true); - }); +await test("last usage", async () => { + const result = await pipe([1, 2, 3], last); + const expected = 3; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/async/map.ts b/pipe/async/map.ts index 6e3f179..539707b 100644 --- a/pipe/async/map.ts +++ b/pipe/async/map.ts @@ -1,4 +1,4 @@ -import { map as base } from "@core/iterutil/async/map"; +import { map as base } from "../../async/map.ts"; /** * Returns an operator that maps the iterable using the provided function. diff --git a/pipe/async/map_test.ts b/pipe/async/map_test.ts index 9f3c730..0a9ebc7 100644 --- a/pipe/async/map_test.ts +++ b/pipe/async/map_test.ts @@ -1,9 +1,10 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { map } from "./map.ts"; -Deno.test("map", async () => { +test("map usage", async () => { const result = pipe( [1, 2, 3, 4, 5], map((v) => v * 2), diff --git a/pipe/async/mod_test.ts b/pipe/async/mod_test.ts index 1324a57..c89e25b 100644 --- a/pipe/async/mod_test.ts +++ b/pipe/async/mod_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cross/test"; import { assertArrayIncludes } from "@std/assert"; import { basename, globToRegExp, join } from "@std/path"; import { ensure, is } from "@core/unknownutil"; @@ -9,16 +10,16 @@ const excludes = [ "*_bench.ts", ]; -Deno.test("mod.ts must exports all exports in public modules", async () => { +test("mod.ts must exports all exports in public modules", async () => { const modExports = await listModExports("./mod.ts"); const pubExports = []; for await (const name of iterPublicModules(".")) { pubExports.push(...await listModExports(`./${name}.ts`)); } assertArrayIncludes(modExports, pubExports); -}); +}, { skip: !("Deno" in globalThis) }); -Deno.test("JSR exports must have all exports in mod.ts", async () => { +test("JSR exports must have all exports in mod.ts", async () => { const jsrExportEntries = await listJsrExportEntries(); const modExportEntries: [string, string][] = []; for await (const name of iterPublicModules(".")) { @@ -28,7 +29,7 @@ Deno.test("JSR exports must have all exports in mod.ts", async () => { ]); } assertArrayIncludes(jsrExportEntries, modExportEntries); -}); +}, { skip: !("Deno" in globalThis) }); async function* iterPublicModules(relpath: string): AsyncIterable { const patterns = excludes.map((p) => globToRegExp(p)); diff --git a/pipe/async/nth.ts b/pipe/async/nth.ts index 3fbf27c..2b0d847 100644 --- a/pipe/async/nth.ts +++ b/pipe/async/nth.ts @@ -1,4 +1,4 @@ -import { nth as base } from "@core/iterutil/async/nth"; +import { nth as base } from "../../async/nth.ts"; /** * Returns an operator that returns the n-th element of an iterable. If the length of the iterable is less, returns `undefined`. diff --git a/pipe/async/nth_test.ts b/pipe/async/nth_test.ts index 491edd9..4b50b58 100644 --- a/pipe/async/nth_test.ts +++ b/pipe/async/nth_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { nth } from "./nth.ts"; -Deno.test("nth", async (t) => { - await t.step("usage", async () => { - const result = await pipe([1, 2, 3], nth(1)); - const expected = 2; - assertEquals(result, expected); - assertType>(true); - }); +await test("nth usage", async () => { + const result = await pipe([1, 2, 3], nth(1)); + const expected = 2; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/async/pairwise.ts b/pipe/async/pairwise.ts index 2215798..19d0863 100644 --- a/pipe/async/pairwise.ts +++ b/pipe/async/pairwise.ts @@ -1,4 +1,4 @@ -import { pairwise } from "@core/iterutil/async/pairwise"; +import { pairwise } from "../../async/pairwise.ts"; export { /** diff --git a/pipe/async/pairwise_test.ts b/pipe/async/pairwise_test.ts index a42b0dd..41a0ff6 100644 --- a/pipe/async/pairwise_test.ts +++ b/pipe/async/pairwise_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { pairwise } from "./pairwise.ts"; -Deno.test("pairwise", async (t) => { - await t.step("usage", async () => { - const result = pipe([1, 2, 3, 4, 5], pairwise); - const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("pairwise usage", async () => { + const result = pipe([1, 2, 3, 4, 5], pairwise); + const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/partition.ts b/pipe/async/partition.ts index 869cfec..68c6d42 100644 --- a/pipe/async/partition.ts +++ b/pipe/async/partition.ts @@ -1,4 +1,4 @@ -import { partition as base } from "@core/iterutil/async/partition"; +import { partition as base } from "../../async/partition.ts"; /** * Returns an operator that partitions the iterable using the provided function. diff --git a/pipe/async/partition_test.ts b/pipe/async/partition_test.ts index 882c840..4d988fa 100644 --- a/pipe/async/partition_test.ts +++ b/pipe/async/partition_test.ts @@ -1,17 +1,16 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { partition } from "./partition.ts"; -Deno.test("partition", async (t) => { - await t.step("usage", async () => { - const [left, right] = await pipe( - [1, 2, 3, 4, 5], - partition((v) => v % 2 === 0), - ); - assertEquals(left, [2, 4]); - assertEquals(right, [1, 3, 5]); - assertType>(true); - assertType>(true); - }); +await test("partition usage", async () => { + const [left, right] = await pipe( + [1, 2, 3, 4, 5], + partition((v) => v % 2 === 0), + ); + assertEquals(left, [2, 4]); + assertEquals(right, [1, 3, 5]); + assertType>(true); + assertType>(true); }); diff --git a/pipe/async/reduce.ts b/pipe/async/reduce.ts index afee24c..7d02e09 100644 --- a/pipe/async/reduce.ts +++ b/pipe/async/reduce.ts @@ -1,4 +1,4 @@ -import { reduce as base } from "@core/iterutil/async/reduce"; +import { reduce as base } from "../../async/reduce.ts"; /** * Returns an operator that reduces an iterable into a single value. diff --git a/pipe/async/reduce_test.ts b/pipe/async/reduce_test.ts index e9b3654..12ef661 100644 --- a/pipe/async/reduce_test.ts +++ b/pipe/async/reduce_test.ts @@ -1,24 +1,23 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { reduce } from "./reduce.ts"; -Deno.test("reduce", async (t) => { - await t.step("usage 1", async () => { - const result = await pipe( - [1, 2, 3, 4, 5], - reduce((acc, v) => acc + v), - ); - assertEquals(result, 15); - assertType>(true); - }); +await test("reduce usage 1", async () => { + const result = await pipe( + [1, 2, 3, 4, 5], + reduce((acc, v) => acc + v), + ); + assertEquals(result, 15); + assertType>(true); +}); - await t.step("usage 2", async () => { - const result = await pipe( - [1, 2, 3, 4, 5], - reduce((acc, v) => acc + v, ""), - ); - assertEquals(result, "12345"); - assertType>(true); - }); +await test("reduce usage 2", async () => { + const result = await pipe( + [1, 2, 3, 4, 5], + reduce((acc, v) => acc + v, ""), + ); + assertEquals(result, "12345"); + assertType>(true); }); diff --git a/pipe/async/repeat.ts b/pipe/async/repeat.ts index 2c9deaa..d24f1a6 100644 --- a/pipe/async/repeat.ts +++ b/pipe/async/repeat.ts @@ -1,4 +1,4 @@ -import { repeat as base } from "@core/iterutil/async/repeat"; +import { repeat as base } from "../../async/repeat.ts"; /** * An operator to return a function that repeats the elements of an iterable. diff --git a/pipe/async/repeat_test.ts b/pipe/async/repeat_test.ts index b2179ff..e17c301 100644 --- a/pipe/async/repeat_test.ts +++ b/pipe/async/repeat_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { repeat } from "./repeat.ts"; -Deno.test("repeat", async (t) => { - await t.step("usage", async () => { - const result = pipe([0, 1, 2], repeat(2)); - const expected = [0, 1, 2, 0, 1, 2]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("repeat usage", async () => { + const result = pipe([0, 1, 2], repeat(2)); + const expected = [0, 1, 2, 0, 1, 2]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/some.ts b/pipe/async/some.ts index 6087160..43ed69d 100644 --- a/pipe/async/some.ts +++ b/pipe/async/some.ts @@ -1,4 +1,4 @@ -import { some as base } from "@core/iterutil/async/some"; +import { some as base } from "../../async/some.ts"; /** * Returns an operator that tests whether at least one element in the iterable satisfies the provided testing function. diff --git a/pipe/async/some_test.ts b/pipe/async/some_test.ts index 40b51f1..54b0dd9 100644 --- a/pipe/async/some_test.ts +++ b/pipe/async/some_test.ts @@ -1,20 +1,19 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { some } from "./some.ts"; -Deno.test("some", async (t) => { - await t.step("usage 1", async () => { - const result = await pipe([1, 2, 3], some((v) => v % 2 === 0)); - const expected = true; - assertEquals(result, expected); - assertType>(true); - }); +await test("some usage 1", async () => { + const result = await pipe([1, 2, 3], some((v) => v % 2 === 0)); + const expected = true; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("usage 2", async () => { - const result = await pipe([1, 3, 5], some((v) => v % 2 === 0)); - const expected = false; - assertEquals(result, expected); - assertType>(true); - }); +await test("some usage 2", async () => { + const result = await pipe([1, 3, 5], some((v) => v % 2 === 0)); + const expected = false; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/async/take.ts b/pipe/async/take.ts index cd967f9..c333ac8 100644 --- a/pipe/async/take.ts +++ b/pipe/async/take.ts @@ -1,4 +1,4 @@ -import { take as base } from "@core/iterutil/async/take"; +import { take as base } from "../../async/take.ts"; /** * Returns an operator that takes the first `limit` items from the iterable. * diff --git a/pipe/async/take_test.ts b/pipe/async/take_test.ts index 278d808..917dfbf 100644 --- a/pipe/async/take_test.ts +++ b/pipe/async/take_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { take } from "./take.ts"; -Deno.test("take", async (t) => { - await t.step("usage 1", async () => { - const result = pipe([1, 2, 3, 4, 5], take(2)); - const expected = [1, 2]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("take usage 1", async () => { + const result = pipe([1, 2, 3, 4, 5], take(2)); + const expected = [1, 2]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/take_while.ts b/pipe/async/take_while.ts index 1caa658..bc2ece5 100644 --- a/pipe/async/take_while.ts +++ b/pipe/async/take_while.ts @@ -1,4 +1,4 @@ -import { takeWhile as base } from "@core/iterutil/async/take-while"; +import { takeWhile as base } from "../../async/take_while.ts"; /** * Returns an operator that takes elements from the iterable while the predicate returns `true`. diff --git a/pipe/async/take_while_test.ts b/pipe/async/take_while_test.ts index 8f1b453..d1dc3f2 100644 --- a/pipe/async/take_while_test.ts +++ b/pipe/async/take_while_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { takeWhile } from "./take_while.ts"; -Deno.test("takeWhile", async (t) => { - await t.step("usage", async () => { - const result = pipe([1, 2, 3, 4, 5], takeWhile((v) => v < 4)); - const expected = [1, 2, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("takeWhile usage", async () => { + const result = pipe([1, 2, 3, 4, 5], takeWhile((v) => v < 4)); + const expected = [1, 2, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/uniq.ts b/pipe/async/uniq.ts index 09e61a4..b31b1bc 100644 --- a/pipe/async/uniq.ts +++ b/pipe/async/uniq.ts @@ -1,4 +1,4 @@ -import { uniq as base } from "@core/iterutil/async/uniq"; +import { uniq as base } from "../../async/uniq.ts"; /** * Returns an operator that yields the unique elements of the iterable. diff --git a/pipe/async/uniq_test.ts b/pipe/async/uniq_test.ts index 9cfac74..ee44720 100644 --- a/pipe/async/uniq_test.ts +++ b/pipe/async/uniq_test.ts @@ -1,23 +1,22 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { uniq } from "./uniq.ts"; -Deno.test("uniq", async (t) => { - await t.step("usage 1", async () => { - const result = pipe([1, 2, 2, 3, 3, 3], uniq()); - const expected = [1, 2, 3]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("uniq usage 1", async () => { + const result = pipe([1, 2, 2, 3, 3, 3], uniq()); + const expected = [1, 2, 3]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); +}); - await t.step("with identify", async () => { - const result = pipe( - [1, 2, 3, 4, 5, 6, 7, 8, 9], - uniq((v) => v % 4), - ); - const expected = [1, 2, 3, 4]; - assertEquals(await Array.fromAsync(result), expected); - assertType>>(true); - }); +await test("uniq with identify", async () => { + const result = pipe( + [1, 2, 3, 4, 5, 6, 7, 8, 9], + uniq((v) => v % 4), + ); + const expected = [1, 2, 3, 4]; + assertEquals(await Array.fromAsync(result), expected); + assertType>>(true); }); diff --git a/pipe/async/zip.ts b/pipe/async/zip.ts index 1f8bdc9..ec0b93f 100644 --- a/pipe/async/zip.ts +++ b/pipe/async/zip.ts @@ -1,4 +1,4 @@ -import { type Zip, zip as base } from "@core/iterutil/async/zip"; +import { type Zip, zip as base } from "../../async/zip.ts"; /** * Returns an operator that zips the provided iterables with the iterable. diff --git a/pipe/async/zip_test.ts b/pipe/async/zip_test.ts index d21bc1d..a9a93c6 100644 --- a/pipe/async/zip_test.ts +++ b/pipe/async/zip_test.ts @@ -1,17 +1,16 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { zip } from "./zip.ts"; -Deno.test("zip", async (t) => { - await t.step("usage", async () => { - const result = pipe([1, 2, 3], zip(["a", "b", "c"], [true, false, true])); - const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; - assertEquals(await Array.fromAsync(result), expected); - assertType< - IsExact> - >( - true, - ); - }); +await test("zip usage", async () => { + const result = pipe([1, 2, 3], zip(["a", "b", "c"], [true, false, true])); + const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; + assertEquals(await Array.fromAsync(result), expected); + assertType< + IsExact> + >( + true, + ); }); diff --git a/pipe/chain.ts b/pipe/chain.ts index 5ef7a88..d8c6125 100644 --- a/pipe/chain.ts +++ b/pipe/chain.ts @@ -1,4 +1,4 @@ -import { type Chain, chain as base } from "@core/iterutil/chain"; +import { type Chain, chain as base } from "../chain.ts"; /** * Returns an operator that chains multiple iterables to the iterable. diff --git a/pipe/chain_test.ts b/pipe/chain_test.ts index 8c7860d..0f51d1c 100644 --- a/pipe/chain_test.ts +++ b/pipe/chain_test.ts @@ -1,18 +1,17 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { chain } from "./chain.ts"; -Deno.test("chain", async (t) => { - await t.step("usage", () => { - const result = pipe( - [1, 2, 3], - chain(["a", "b"], [true]), - ); - const expected = [1, 2, 3, "a", "b", true]; - assertEquals(Array.from(result), expected); - assertType>>( - true, - ); - }); +await test("chain usage", () => { + const result = pipe( + [1, 2, 3], + chain(["a", "b"], [true]), + ); + const expected = [1, 2, 3, "a", "b", true]; + assertEquals(Array.from(result), expected); + assertType>>( + true, + ); }); diff --git a/pipe/chunked.ts b/pipe/chunked.ts index 8269ae4..c08b4fd 100644 --- a/pipe/chunked.ts +++ b/pipe/chunked.ts @@ -1,4 +1,4 @@ -import { chunked as base } from "@core/iterutil/chunked"; +import { chunked as base } from "../chunked.ts"; /** * Returns an operator that chunks the iterable into arrays of `size`. diff --git a/pipe/chunked_test.ts b/pipe/chunked_test.ts index ca6ff01..ee1986c 100644 --- a/pipe/chunked_test.ts +++ b/pipe/chunked_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { chunked } from "./chunked.ts"; -Deno.test("chunked", async (t) => { - await t.step("usage", () => { - const result = pipe([1, 2, 3, 4, 5, 6], chunked(2)); - const expected = [[1, 2], [3, 4], [5, 6]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("chunked usage", () => { + const result = pipe([1, 2, 3, 4, 5, 6], chunked(2)); + const expected = [[1, 2], [3, 4], [5, 6]]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/compact.ts b/pipe/compact.ts index 1c1ac6b..ff5b241 100644 --- a/pipe/compact.ts +++ b/pipe/compact.ts @@ -1,4 +1,4 @@ -import { compact } from "@core/iterutil/compact"; +import { compact } from "../compact.ts"; export { /** diff --git a/pipe/compact_test.ts b/pipe/compact_test.ts index 4c31d61..feb6fa8 100644 --- a/pipe/compact_test.ts +++ b/pipe/compact_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { compact } from "./compact.ts"; -Deno.test("compact", async (t) => { - await t.step("usage", () => { - const result = pipe([1, undefined, 2, null, 3], compact); - const expected = [1, 2, 3]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("compact usage", () => { + const result = pipe([1, undefined, 2, null, 3], compact); + const expected = [1, 2, 3]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/compress.ts b/pipe/compress.ts index b963ed0..b7bd875 100644 --- a/pipe/compress.ts +++ b/pipe/compress.ts @@ -1,4 +1,4 @@ -import { compress as base } from "@core/iterutil/compress"; +import { compress as base } from "../compress.ts"; /** * Returns an operator that compresses an iterable by selecting elements using a selector iterable. diff --git a/pipe/compress_test.ts b/pipe/compress_test.ts index a082bc3..c0f98f1 100644 --- a/pipe/compress_test.ts +++ b/pipe/compress_test.ts @@ -1,16 +1,15 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { compress } from "./compress.ts"; -Deno.test("compress", async (t) => { - await t.step("usage", () => { - const result = pipe( - [1, 2, 3, 4, 5], - compress([true, false, true, false, true]), - ); - const expected = [1, 3, 5]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("compress usage", () => { + const result = pipe( + [1, 2, 3, 4, 5], + compress([true, false, true, false, true]), + ); + const expected = [1, 3, 5]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/cycle.ts b/pipe/cycle.ts index c6de48f..9bd1628 100644 --- a/pipe/cycle.ts +++ b/pipe/cycle.ts @@ -1,4 +1,4 @@ -import { cycle } from "@core/iterutil/cycle"; +import { cycle } from "../cycle.ts"; export { /** diff --git a/pipe/cycle_test.ts b/pipe/cycle_test.ts index efde2ea..b5ee2e0 100644 --- a/pipe/cycle_test.ts +++ b/pipe/cycle_test.ts @@ -1,14 +1,13 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { take } from "./take.ts"; import { cycle } from "./cycle.ts"; -Deno.test("cycle", async (t) => { - await t.step("usage", () => { - const result = pipe([0, 1, 2], cycle, take(5)); - const expected = [0, 1, 2, 0, 1]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("cycle usage", () => { + const result = pipe([0, 1, 2], cycle, take(5)); + const expected = [0, 1, 2, 0, 1]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/drop.ts b/pipe/drop.ts index 0d2316b..5a327e0 100644 --- a/pipe/drop.ts +++ b/pipe/drop.ts @@ -1,4 +1,4 @@ -import { drop as base } from "@core/iterutil/drop"; +import { drop as base } from "../drop.ts"; /** * Returns an operator that drops the first `limit` items from the iterable. diff --git a/pipe/drop_test.ts b/pipe/drop_test.ts index e137b0b..cf50d09 100644 --- a/pipe/drop_test.ts +++ b/pipe/drop_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { drop } from "./drop.ts"; -Deno.test("drop", async (t) => { - await t.step("usage", () => { - const result = pipe([0, 1, 2, 3, 4], drop(2)); - const expected = [2, 3, 4]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("drop usage", () => { + const result = pipe([0, 1, 2, 3, 4], drop(2)); + const expected = [2, 3, 4]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/drop_while.ts b/pipe/drop_while.ts index 2412989..e35c5cd 100644 --- a/pipe/drop_while.ts +++ b/pipe/drop_while.ts @@ -1,4 +1,4 @@ -import { dropWhile as base } from "@core/iterutil/drop-while"; +import { dropWhile as base } from "../drop_while.ts"; /** * Returns an operator that drops elements from the iterable while the predicate returns true. diff --git a/pipe/drop_while_test.ts b/pipe/drop_while_test.ts index 31271e5..b04e225 100644 --- a/pipe/drop_while_test.ts +++ b/pipe/drop_while_test.ts @@ -1,16 +1,15 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { dropWhile } from "./drop_while.ts"; -Deno.test("dropWhile", async (t) => { - await t.step("usage", () => { - const result = pipe( - [0, 1, 2, 3, 4], - dropWhile((v) => v < 2), - ); - const expected = [2, 3, 4]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("dropWhile usage", () => { + const result = pipe( + [0, 1, 2, 3, 4], + dropWhile((v) => v < 2), + ); + const expected = [2, 3, 4]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/enumerate.ts b/pipe/enumerate.ts index 34eb37d..7c16eac 100644 --- a/pipe/enumerate.ts +++ b/pipe/enumerate.ts @@ -1,4 +1,4 @@ -import { enumerate as base } from "@core/iterutil/enumerate"; +import { enumerate as base } from "../enumerate.ts"; /** * Returns an operator that enumerates the iterable. diff --git a/pipe/enumerate_test.ts b/pipe/enumerate_test.ts index fab47bf..48a89ba 100644 --- a/pipe/enumerate_test.ts +++ b/pipe/enumerate_test.ts @@ -1,27 +1,26 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { enumerate } from "./enumerate.ts"; -Deno.test("enumerate", async (t) => { - await t.step("usage 1", () => { - const result = pipe(["a", "b", "c"], enumerate()); - const expected = [[0, "a"], [1, "b"], [2, "c"]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate usage 1", () => { + const result = pipe(["a", "b", "c"], enumerate()); + const expected = [[0, "a"], [1, "b"], [2, "c"]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("usage 2", () => { - const result = pipe(["a", "b", "c"], enumerate(1)); - const expected = [[1, "a"], [2, "b"], [3, "c"]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate usage 2", () => { + const result = pipe(["a", "b", "c"], enumerate(1)); + const expected = [[1, "a"], [2, "b"], [3, "c"]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("usage 3", () => { - const result = pipe(["a", "b", "c"], enumerate(1, 2)); - const expected = [[1, "a"], [3, "b"], [5, "c"]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("enumerate usage 3", () => { + const result = pipe(["a", "b", "c"], enumerate(1, 2)); + const expected = [[1, "a"], [3, "b"], [5, "c"]]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/every.ts b/pipe/every.ts index 519bcea..abedf90 100644 --- a/pipe/every.ts +++ b/pipe/every.ts @@ -1,4 +1,4 @@ -import { every as base } from "@core/iterutil/every"; +import { every as base } from "../every.ts"; /** * Returns an operator that tests whether every element in the iterable satisfies the provided testing function. diff --git a/pipe/every_test.ts b/pipe/every_test.ts index 0f47f24..df6ebce 100644 --- a/pipe/every_test.ts +++ b/pipe/every_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { every } from "./every.ts"; -Deno.test("every", async (t) => { - await t.step("usage", () => { - const result = pipe([1, 2, 3], every((v) => v > 0)); - const expected = true; - assertEquals(result, expected); - assertType>(true); - }); +await test("every usage", () => { + const result = pipe([1, 2, 3], every((v) => v > 0)); + const expected = true; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/filter.ts b/pipe/filter.ts index 4b54f14..065ded8 100644 --- a/pipe/filter.ts +++ b/pipe/filter.ts @@ -1,4 +1,4 @@ -import { filter as base } from "@core/iterutil/filter"; +import { filter as base } from "../filter.ts"; /** * Returns an operator that filters an iterable based on a function. diff --git a/pipe/filter_test.ts b/pipe/filter_test.ts index 8121546..04058ef 100644 --- a/pipe/filter_test.ts +++ b/pipe/filter_test.ts @@ -1,9 +1,10 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { filter } from "./filter.ts"; -Deno.test("filter", () => { +test("filter usage", () => { const result = pipe( [1, 2, 3, 4, 5], filter((v) => v % 2 === 0), diff --git a/pipe/find.ts b/pipe/find.ts index 7b901b9..8a74833 100644 --- a/pipe/find.ts +++ b/pipe/find.ts @@ -1,4 +1,4 @@ -import { find as base } from "@core/iterutil/find"; +import { find as base } from "../find.ts"; /** * Returns an operator that finds the first element that satisfies the provided testing function. diff --git a/pipe/find_test.ts b/pipe/find_test.ts index 147488e..10147df 100644 --- a/pipe/find_test.ts +++ b/pipe/find_test.ts @@ -1,16 +1,15 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { find } from "./find.ts"; -Deno.test("find", async (t) => { - await t.step("usage", () => { - const result = pipe( - [1, 2, 3, 4, 5], - find((v) => v % 2 === 0), - ); - const expected = 2; - assertEquals(result, expected); - assertType>(true); - }); +await test("find usage", () => { + const result = pipe( + [1, 2, 3, 4, 5], + find((v) => v % 2 === 0), + ); + const expected = 2; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/first.ts b/pipe/first.ts index 76cf671..c10cf7e 100644 --- a/pipe/first.ts +++ b/pipe/first.ts @@ -1,4 +1,4 @@ -import { first } from "@core/iterutil/first"; +import { first } from "../first.ts"; export { /** diff --git a/pipe/first_test.ts b/pipe/first_test.ts index 46499e5..8eeff25 100644 --- a/pipe/first_test.ts +++ b/pipe/first_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { first } from "./first.ts"; -Deno.test("first", async (t) => { - await t.step("usage", () => { - const result = pipe([1, 2, 3], first); - const expected = 1; - assertEquals(result, expected); - assertType>(true); - }); +await test("first usage", () => { + const result = pipe([1, 2, 3], first); + const expected = 1; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/flat_map.ts b/pipe/flat_map.ts index 24e840d..8437076 100644 --- a/pipe/flat_map.ts +++ b/pipe/flat_map.ts @@ -1,4 +1,4 @@ -import { flatMap as base } from "@core/iterutil/flat-map"; +import { flatMap as base } from "../flat_map.ts"; /** * Returns an operator that flat maps the iterable. diff --git a/pipe/flat_map_test.ts b/pipe/flat_map_test.ts index 4d515a5..a3561f1 100644 --- a/pipe/flat_map_test.ts +++ b/pipe/flat_map_test.ts @@ -1,16 +1,15 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { flatMap } from "./flat_map.ts"; -Deno.test("flatMap", async (t) => { - await t.step("usage", () => { - const result = pipe( - [1, 2, 3], - flatMap((v) => [v, v]), - ); - const expected = [1, 1, 2, 2, 3, 3]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("flatMap usage", () => { + const result = pipe( + [1, 2, 3], + flatMap((v) => [v, v]), + ); + const expected = [1, 1, 2, 2, 3, 3]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/flatten.ts b/pipe/flatten.ts index 8291fd1..ebc1f05 100644 --- a/pipe/flatten.ts +++ b/pipe/flatten.ts @@ -1,4 +1,4 @@ -import { flatten } from "@core/iterutil/flatten"; +import { flatten } from "../flatten.ts"; export { /** diff --git a/pipe/flatten_test.ts b/pipe/flatten_test.ts index ed6c324..3a2c518 100644 --- a/pipe/flatten_test.ts +++ b/pipe/flatten_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { flatten } from "./flatten.ts"; -Deno.test("flatten", async (t) => { - await t.step("usage", () => { - const result = pipe([[1, 2], [3, 4], [5]], flatten); - const expected = [1, 2, 3, 4, 5]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("flatten usage", () => { + const result = pipe([[1, 2], [3, 4], [5]], flatten); + const expected = [1, 2, 3, 4, 5]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/for_each.ts b/pipe/for_each.ts index 6d282ea..b592dda 100644 --- a/pipe/for_each.ts +++ b/pipe/for_each.ts @@ -1,4 +1,4 @@ -import { forEach as base } from "@core/iterutil/for-each"; +import { forEach as base } from "../for_each.ts"; /** * Returns an operator that calls the given function for each value in the iterable. diff --git a/pipe/for_each_test.ts b/pipe/for_each_test.ts index af16710..7cd77a6 100644 --- a/pipe/for_each_test.ts +++ b/pipe/for_each_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { pipe } from "@core/pipe"; import { forEach } from "./for_each.ts"; -Deno.test("forEach", () => { +test("forEach usage", () => { const values: number[] = []; pipe( [1, 2, 3, 4, 5], diff --git a/pipe/last.ts b/pipe/last.ts index 23fae91..c84652c 100644 --- a/pipe/last.ts +++ b/pipe/last.ts @@ -1,4 +1,4 @@ -import { last } from "@core/iterutil/last"; +import { last } from "../last.ts"; export { /** diff --git a/pipe/last_test.ts b/pipe/last_test.ts index 6479013..3691fd4 100644 --- a/pipe/last_test.ts +++ b/pipe/last_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { last } from "./last.ts"; -Deno.test("last", async (t) => { - await t.step("usage", () => { - const result = pipe([1, 2, 3], last); - const expected = 3; - assertEquals(result, expected); - assertType>(true); - }); +await test("last usage", () => { + const result = pipe([1, 2, 3], last); + const expected = 3; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/map.ts b/pipe/map.ts index dbd51c0..d649c59 100644 --- a/pipe/map.ts +++ b/pipe/map.ts @@ -1,4 +1,4 @@ -import { map as base } from "@core/iterutil/map"; +import { map as base } from "../map.ts"; /** * Returns an operator that maps the iterable using the provided function. diff --git a/pipe/map_test.ts b/pipe/map_test.ts index 6f53640..87ade1a 100644 --- a/pipe/map_test.ts +++ b/pipe/map_test.ts @@ -1,9 +1,10 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { map } from "./map.ts"; -Deno.test("map", () => { +test("map usage", () => { const result = pipe( [1, 2, 3, 4, 5], map((v) => v * 2), diff --git a/pipe/mod_test.ts b/pipe/mod_test.ts index d7a6ef1..c343488 100644 --- a/pipe/mod_test.ts +++ b/pipe/mod_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cross/test"; import { assertArrayIncludes } from "@std/assert"; import { basename, globToRegExp, join } from "@std/path"; import { ensure, is } from "@core/unknownutil"; @@ -9,16 +10,16 @@ const excludes = [ "*_bench.ts", ]; -Deno.test("mod.ts must exports all exports in public modules", async () => { +test("mod.ts must exports all exports in public modules", async () => { const modExports = await listModExports("./mod.ts"); const pubExports = []; for await (const name of iterPublicModules(".")) { pubExports.push(...await listModExports(`./${name}.ts`)); } assertArrayIncludes(modExports, pubExports); -}); +}, { skip: !("Deno" in globalThis) }); -Deno.test("JSR exports must have all exports in mod.ts", async () => { +test("JSR exports must have all exports in mod.ts", async () => { const jsrExportEntries = await listJsrExportEntries(); const modExportEntries: [string, string][] = []; for await (const name of iterPublicModules(".")) { @@ -28,7 +29,7 @@ Deno.test("JSR exports must have all exports in mod.ts", async () => { ]); } assertArrayIncludes(jsrExportEntries, modExportEntries); -}); +}, { skip: !("Deno" in globalThis) }); async function* iterPublicModules(relpath: string): AsyncIterable { const patterns = excludes.map((p) => globToRegExp(p)); diff --git a/pipe/nth.ts b/pipe/nth.ts index 2368cc3..d3b2e0f 100644 --- a/pipe/nth.ts +++ b/pipe/nth.ts @@ -1,4 +1,4 @@ -import { nth as base } from "@core/iterutil/nth"; +import { nth as base } from "../nth.ts"; /** * Returns an operator that returns the n-th element of an iterable. If the length of the iterable is less, returns `undefined`. diff --git a/pipe/nth_test.ts b/pipe/nth_test.ts index 5215509..bdd3a19 100644 --- a/pipe/nth_test.ts +++ b/pipe/nth_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { nth } from "./nth.ts"; -Deno.test("nth", async (t) => { - await t.step("usage", () => { - const result = pipe([1, 2, 3], nth(1)); - const expected = 2; - assertEquals(result, expected); - assertType>(true); - }); +await test("nth usage", () => { + const result = pipe([1, 2, 3], nth(1)); + const expected = 2; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/pairwise.ts b/pipe/pairwise.ts index 6ef0503..80d2311 100644 --- a/pipe/pairwise.ts +++ b/pipe/pairwise.ts @@ -1,4 +1,4 @@ -import { pairwise } from "@core/iterutil/pairwise"; +import { pairwise } from "../pairwise.ts"; export { /** diff --git a/pipe/pairwise_test.ts b/pipe/pairwise_test.ts index b4e2f7a..c285e7a 100644 --- a/pipe/pairwise_test.ts +++ b/pipe/pairwise_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { pairwise } from "./pairwise.ts"; -Deno.test("pairwise", async (t) => { - await t.step("usage", () => { - const result = pipe([1, 2, 3, 4, 5], pairwise); - const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("pairwise usage", () => { + const result = pipe([1, 2, 3, 4, 5], pairwise); + const expected = [[1, 2], [2, 3], [3, 4], [4, 5]]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/partition.ts b/pipe/partition.ts index ad646ec..76c92ce 100644 --- a/pipe/partition.ts +++ b/pipe/partition.ts @@ -1,4 +1,4 @@ -import { partition as base } from "@core/iterutil/partition"; +import { partition as base } from "../partition.ts"; /** * Returns an operator that partitions the iterable using the provided function. diff --git a/pipe/partition_test.ts b/pipe/partition_test.ts index 5a9c693..d521e2c 100644 --- a/pipe/partition_test.ts +++ b/pipe/partition_test.ts @@ -1,17 +1,16 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { partition } from "./partition.ts"; -Deno.test("partition", async (t) => { - await t.step("usage", () => { - const [left, right] = pipe( - [1, 2, 3, 4, 5], - partition((v) => v % 2 === 0), - ); - assertEquals(left, [2, 4]); - assertEquals(right, [1, 3, 5]); - assertType>(true); - assertType>(true); - }); +await test("partition usage", () => { + const [left, right] = pipe( + [1, 2, 3, 4, 5], + partition((v) => v % 2 === 0), + ); + assertEquals(left, [2, 4]); + assertEquals(right, [1, 3, 5]); + assertType>(true); + assertType>(true); }); diff --git a/pipe/reduce.ts b/pipe/reduce.ts index 28e8883..5badffb 100644 --- a/pipe/reduce.ts +++ b/pipe/reduce.ts @@ -1,4 +1,4 @@ -import { reduce as base } from "@core/iterutil/reduce"; +import { reduce as base } from "../reduce.ts"; /** * Returns an operator that reduces an iterable into a single value. diff --git a/pipe/reduce_test.ts b/pipe/reduce_test.ts index 77055f7..986e918 100644 --- a/pipe/reduce_test.ts +++ b/pipe/reduce_test.ts @@ -1,24 +1,23 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { reduce } from "./reduce.ts"; -Deno.test("reduce", async (t) => { - await t.step("usage 1", () => { - const result = pipe( - [1, 2, 3, 4, 5], - reduce((acc, v) => acc + v), - ); - assertEquals(result, 15); - assertType>(true); - }); +await test("reduce usage 1", () => { + const result = pipe( + [1, 2, 3, 4, 5], + reduce((acc, v) => acc + v), + ); + assertEquals(result, 15); + assertType>(true); +}); - await t.step("usage 2", () => { - const result = pipe( - [1, 2, 3, 4, 5], - reduce((acc, v) => acc + v, ""), - ); - assertEquals(result, "12345"); - assertType>(true); - }); +await test("reduce usage 2", () => { + const result = pipe( + [1, 2, 3, 4, 5], + reduce((acc, v) => acc + v, ""), + ); + assertEquals(result, "12345"); + assertType>(true); }); diff --git a/pipe/repeat.ts b/pipe/repeat.ts index de4d9ee..3613c8a 100644 --- a/pipe/repeat.ts +++ b/pipe/repeat.ts @@ -1,4 +1,4 @@ -import { repeat as base } from "@core/iterutil/repeat"; +import { repeat as base } from "../repeat.ts"; /** * An operator to return a function that repeats the elements of an iterable. diff --git a/pipe/repeat_test.ts b/pipe/repeat_test.ts index 07aff1e..7b5abe9 100644 --- a/pipe/repeat_test.ts +++ b/pipe/repeat_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { repeat } from "./repeat.ts"; -Deno.test("repeat", async (t) => { - await t.step("usage", () => { - const result = pipe([0, 1, 2], repeat(2)); - const expected = [0, 1, 2, 0, 1, 2]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("repeat usage", () => { + const result = pipe([0, 1, 2], repeat(2)); + const expected = [0, 1, 2, 0, 1, 2]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/some.ts b/pipe/some.ts index 2ad91ce..80453ac 100644 --- a/pipe/some.ts +++ b/pipe/some.ts @@ -1,4 +1,4 @@ -import { some as base } from "@core/iterutil/some"; +import { some as base } from "../some.ts"; /** * Returns an operator that tests whether at least one element in the iterable satisfies the provided testing function. diff --git a/pipe/some_test.ts b/pipe/some_test.ts index 8a535aa..ee51f31 100644 --- a/pipe/some_test.ts +++ b/pipe/some_test.ts @@ -1,20 +1,19 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { some } from "./some.ts"; -Deno.test("some", async (t) => { - await t.step("usage 1", () => { - const result = pipe([1, 2, 3], some((v) => v % 2 === 0)); - const expected = true; - assertEquals(result, expected); - assertType>(true); - }); +await test("some usage 1", () => { + const result = pipe([1, 2, 3], some((v) => v % 2 === 0)); + const expected = true; + assertEquals(result, expected); + assertType>(true); +}); - await t.step("usage 2", () => { - const result = pipe([1, 3, 5], some((v) => v % 2 === 0)); - const expected = false; - assertEquals(result, expected); - assertType>(true); - }); +await test("some usage 2", () => { + const result = pipe([1, 3, 5], some((v) => v % 2 === 0)); + const expected = false; + assertEquals(result, expected); + assertType>(true); }); diff --git a/pipe/take.ts b/pipe/take.ts index c56c864..dd3c1c3 100644 --- a/pipe/take.ts +++ b/pipe/take.ts @@ -1,4 +1,4 @@ -import { take as base } from "@core/iterutil/take"; +import { take as base } from "../take.ts"; /** * Returns an operator that takes the first `limit` items from the iterable. * diff --git a/pipe/take_test.ts b/pipe/take_test.ts index 1cc1d09..59607fa 100644 --- a/pipe/take_test.ts +++ b/pipe/take_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { take } from "./take.ts"; -Deno.test("take", async (t) => { - await t.step("usage 1", () => { - const result = pipe([1, 2, 3, 4, 5], take(2)); - const expected = [1, 2]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("take usage", () => { + const result = pipe([1, 2, 3, 4, 5], take(2)); + const expected = [1, 2]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/take_while.ts b/pipe/take_while.ts index 8e405da..fc9451c 100644 --- a/pipe/take_while.ts +++ b/pipe/take_while.ts @@ -1,4 +1,4 @@ -import { takeWhile as base } from "@core/iterutil/take-while"; +import { takeWhile as base } from "../take_while.ts"; /** * Returns an operator that takes elements from the iterable while the predicate returns `true`. diff --git a/pipe/take_while_test.ts b/pipe/take_while_test.ts index 8e75291..10a4d5c 100644 --- a/pipe/take_while_test.ts +++ b/pipe/take_while_test.ts @@ -1,13 +1,12 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { takeWhile } from "./take_while.ts"; -Deno.test("takeWhile", async (t) => { - await t.step("usage", () => { - const result = pipe([1, 2, 3, 4, 5], takeWhile((v) => v < 4)); - const expected = [1, 2, 3]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("takeWhile usage", () => { + const result = pipe([1, 2, 3, 4, 5], takeWhile((v) => v < 4)); + const expected = [1, 2, 3]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/uniq.ts b/pipe/uniq.ts index 29a64e1..b149c75 100644 --- a/pipe/uniq.ts +++ b/pipe/uniq.ts @@ -1,4 +1,4 @@ -import { uniq as base } from "@core/iterutil/uniq"; +import { uniq as base } from "../uniq.ts"; /** * Returns an operator that yields the unique elements of the iterable. diff --git a/pipe/uniq_test.ts b/pipe/uniq_test.ts index db7ffe9..7435c9d 100644 --- a/pipe/uniq_test.ts +++ b/pipe/uniq_test.ts @@ -1,23 +1,22 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { uniq } from "./uniq.ts"; -Deno.test("uniq", async (t) => { - await t.step("usage 1", () => { - const result = pipe([1, 2, 2, 3, 3, 3], uniq()); - const expected = [1, 2, 3]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("uniq usage 1", () => { + const result = pipe([1, 2, 2, 3, 3, 3], uniq()); + const expected = [1, 2, 3]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with identify", () => { - const result = pipe( - [1, 2, 3, 4, 5, 6, 7, 8, 9], - uniq((v) => v % 4), - ); - const expected = [1, 2, 3, 4]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("uniq with identify", () => { + const result = pipe( + [1, 2, 3, 4, 5, 6, 7, 8, 9], + uniq((v) => v % 4), + ); + const expected = [1, 2, 3, 4]; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/pipe/zip.ts b/pipe/zip.ts index e554c2c..97949cc 100644 --- a/pipe/zip.ts +++ b/pipe/zip.ts @@ -1,4 +1,4 @@ -import { type Zip, zip as base } from "@core/iterutil/zip"; +import { type Zip, zip as base } from "../zip.ts"; /** * Returns an operator that zips the provided iterables with the iterable. diff --git a/pipe/zip_test.ts b/pipe/zip_test.ts index ecd3dc4..ddcdb56 100644 --- a/pipe/zip_test.ts +++ b/pipe/zip_test.ts @@ -1,15 +1,14 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { pipe } from "@core/pipe"; import { zip } from "./zip.ts"; -Deno.test("zip", async (t) => { - await t.step("usage", () => { - const result = pipe([1, 2, 3], zip(["a", "b", "c"], [true, false, true])); - const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; - assertEquals(Array.from(result), expected); - assertType>>( - true, - ); - }); +await test("zip usage", () => { + const result = pipe([1, 2, 3], zip(["a", "b", "c"], [true, false, true])); + const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; + assertEquals(Array.from(result), expected); + assertType>>( + true, + ); }); diff --git a/range_test.ts b/range_test.ts index 5f24330..61808a6 100644 --- a/range_test.ts +++ b/range_test.ts @@ -1,139 +1,130 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { range } from "./range.ts"; -Deno.test("range", async (t) => { - await t.step("without step", async (t) => { - await t.step("with 0 to 0", () => { - const result = range(0, 0); - assertEquals(Array.from(result), [0]); - assertType>>(true); - }); - - await t.step("with 0 to 2", () => { - const result = range(0, 2); - assertEquals(Array.from(result), [0, 1, 2]); - assertType>>(true); - }); - - await t.step("with 0 to -2", () => { - const result = range(0, -2); - assertEquals(Array.from(result), [0, -1, -2]); - assertType>>(true); - }); - - await t.step("with 2 to 0", () => { - const result = range(2, 0); - assertEquals(Array.from(result), [2, 1, 0]); - assertType>>(true); - }); - - await t.step("with -2 to 0", () => { - const result = range(-2, 0); - assertEquals(Array.from(result), [-2, -1, 0]); - assertType>>(true); - }); - - await t.step("with -2 to 2", () => { - const result = range(-2, 2); - assertEquals(Array.from(result), [-2, -1, 0, 1, 2]); - assertType>>(true); - }); - - await t.step("with 2 to -2", () => { - const result = range(2, -2); - assertEquals(Array.from(result), [2, 1, 0, -1, -2]); - assertType>>(true); - }); - - await t.step("throws RangeError", async (t) => { - await t.step("if the start is not finite", () => { - assertThrows(() => range(NaN, 0), RangeError); - assertThrows(() => range(Infinity, 0), RangeError); - assertThrows(() => range(-Infinity, 0), RangeError); - }); - - await t.step("if the end is not finite", () => { - assertThrows(() => range(0, NaN), RangeError); - assertThrows(() => range(0, Infinity), RangeError); - assertThrows(() => range(0, -Infinity), RangeError); - }); - }); - }); - - await t.step("with step", async (t) => { - await t.step("with 0 to 0", () => { - const result = range(0, 0, 2); - assertEquals(Array.from(result), [0]); - assertType>>(true); - }); - - await t.step("with 0 to 2", () => { - const result = range(0, 2, 2); - assertEquals(Array.from(result), [0, 2]); - assertType>>(true); - }); - - await t.step("with 0 to -2", () => { - const result = range(0, -2, -2); - assertEquals(Array.from(result), [0, -2]); - assertType>>(true); - }); - - await t.step("with 2 to 0", () => { - const result = range(2, 0, -2); - assertEquals(Array.from(result), [2, 0]); - assertType>>(true); - }); - - await t.step("with -2 to 0", () => { - const result = range(-2, 0, 2); - assertEquals(Array.from(result), [-2, 0]); - assertType>>(true); - }); - - await t.step("with -2 to 2", () => { - const result = range(-2, 2, 2); - assertEquals(Array.from(result), [-2, 0, 2]); - assertType>>(true); - }); - - await t.step("throws RangeError", async (t) => { - await t.step("if the start is not finite", () => { - assertThrows(() => range(NaN, 0, 2), RangeError); - assertThrows(() => range(Infinity, 0, 2), RangeError); - assertThrows(() => range(-Infinity, 0, 2), RangeError); - }); - - await t.step("if the end is not finite", () => { - assertThrows(() => range(0, NaN, 2), RangeError); - assertThrows(() => range(0, Infinity, 2), RangeError); - assertThrows(() => range(0, -Infinity, 2), RangeError); - }); - - await t.step("if the step is not finite", () => { - assertThrows(() => range(0, 0, NaN), RangeError); - assertThrows(() => range(0, 0, Infinity), RangeError); - assertThrows(() => range(0, 0, -Infinity), RangeError); - }); - - await t.step("if the step is 0", () => { - assertThrows(() => range(0, 0, 0), RangeError); - }); - - await t.step( - "if the start is greater than stop for positive step", - () => { - assertThrows(() => range(1, 0, 1), RangeError); - }, - ); - - await t.step( - "if the start is less than stop for negative step", - () => { - assertThrows(() => range(0, 1, -1), RangeError); - }, - ); - }); - }); +await test("range without step with 0 to 0", () => { + const result = range(0, 0); + assertEquals(Array.from(result), [0]); + assertType>>(true); }); + +await test("range without step with 0 to 2", () => { + const result = range(0, 2); + assertEquals(Array.from(result), [0, 1, 2]); + assertType>>(true); +}); + +await test("range without step with 0 to -2", () => { + const result = range(0, -2); + assertEquals(Array.from(result), [0, -1, -2]); + assertType>>(true); +}); + +await test("range without step with 2 to 0", () => { + const result = range(2, 0); + assertEquals(Array.from(result), [2, 1, 0]); + assertType>>(true); +}); + +await test("range without step with -2 to 0", () => { + const result = range(-2, 0); + assertEquals(Array.from(result), [-2, -1, 0]); + assertType>>(true); +}); + +await test("range without step with -2 to 2", () => { + const result = range(-2, 2); + assertEquals(Array.from(result), [-2, -1, 0, 1, 2]); + assertType>>(true); +}); + +await test("range without step with 2 to -2", () => { + const result = range(2, -2); + assertEquals(Array.from(result), [2, 1, 0, -1, -2]); + assertType>>(true); +}); + +await test("range without step throws RangeError if the start is not finite", () => { + assertThrows(() => range(NaN, 0), RangeError); + assertThrows(() => range(Infinity, 0), RangeError); + assertThrows(() => range(-Infinity, 0), RangeError); +}); + +await test("range without step throws RangeError if the end is not finite", () => { + assertThrows(() => range(0, NaN), RangeError); + assertThrows(() => range(0, Infinity), RangeError); + assertThrows(() => range(0, -Infinity), RangeError); +}); + +await test("range with step with 0 to 0", () => { + const result = range(0, 0, 2); + assertEquals(Array.from(result), [0]); + assertType>>(true); +}); + +await test("range with step with 0 to 2", () => { + const result = range(0, 2, 2); + assertEquals(Array.from(result), [0, 2]); + assertType>>(true); +}); + +await test("range with step with 0 to -2", () => { + const result = range(0, -2, -2); + assertEquals(Array.from(result), [0, -2]); + assertType>>(true); +}); + +await test("range with step with 2 to 0", () => { + const result = range(2, 0, -2); + assertEquals(Array.from(result), [2, 0]); + assertType>>(true); +}); + +await test("range with step with -2 to 0", () => { + const result = range(-2, 0, 2); + assertEquals(Array.from(result), [-2, 0]); + assertType>>(true); +}); + +await test("range with step with -2 to 2", () => { + const result = range(-2, 2, 2); + assertEquals(Array.from(result), [-2, 0, 2]); + assertType>>(true); +}); + +await test("range with step throws RangeError if the start is not finite", () => { + assertThrows(() => range(NaN, 0, 2), RangeError); + assertThrows(() => range(Infinity, 0, 2), RangeError); + assertThrows(() => range(-Infinity, 0, 2), RangeError); +}); + +await test("range with step throws RangeError if the end is not finite", () => { + assertThrows(() => range(0, NaN, 2), RangeError); + assertThrows(() => range(0, Infinity, 2), RangeError); + assertThrows(() => range(0, -Infinity, 2), RangeError); +}); + +await test("range with step throws RangeError if the step is not finite", () => { + assertThrows(() => range(0, 0, NaN), RangeError); + assertThrows(() => range(0, 0, Infinity), RangeError); + assertThrows(() => range(0, 0, -Infinity), RangeError); +}); + +await test("range with step throws RangeError if the step is 0", () => { + assertThrows(() => range(0, 0, 0), RangeError); +}); + +await test( + "range with step throws RangeError if the start is greater than stop for positive step", + () => { + assertThrows(() => range(1, 0, 1), RangeError); + }, +); + +await test( + "range with step throws RangeError if the start is less than stop for negative step", + () => { + assertThrows(() => range(0, 1, -1), RangeError); + }, +); diff --git a/reduce_test.ts b/reduce_test.ts index 4a593fd..16f2dfd 100644 --- a/reduce_test.ts +++ b/reduce_test.ts @@ -1,45 +1,44 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { reduce } from "./reduce.ts"; -Deno.test("reduce", async (t) => { - await t.step("with initial", () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = reduce([1, 2, 3, 4, 5], (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return acc + value; - }, 5); - assertEquals(result, 20); - assertEquals(accumulators, [5, 6, 8, 11, 15]); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }); +await test("reduce with initial", () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = reduce([1, 2, 3, 4, 5], (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return acc + value; + }, 5); + assertEquals(result, 20); + assertEquals(accumulators, [5, 6, 8, 11, 15]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); + assertType>(true); +}); - await t.step("without initial", () => { - const accumulators: number[] = []; - const values: number[] = []; - const indices: number[] = []; - const result = reduce([1, 2, 3, 4, 5], (acc, value, index) => { - accumulators.push(acc); - values.push(value); - indices.push(index); - return acc + value; - }); - assertEquals(result, 15); - assertEquals(accumulators, [1, 3, 6, 10]); - assertEquals(values, [2, 3, 4, 5]); - assertEquals(indices, [1, 2, 3, 4]); - assertType>(true); +await test("reduce without initial", () => { + const accumulators: number[] = []; + const values: number[] = []; + const indices: number[] = []; + const result = reduce([1, 2, 3, 4, 5], (acc, value, index) => { + accumulators.push(acc); + values.push(value); + indices.push(index); + return acc + value; }); + assertEquals(result, 15); + assertEquals(accumulators, [1, 3, 6, 10]); + assertEquals(values, [2, 3, 4, 5]); + assertEquals(indices, [1, 2, 3, 4]); + assertType>(true); +}); - await t.step("without initial / with empty iterable", () => { - const result = reduce([] as number[], (acc, v) => acc + v); - assertEquals(result, undefined); - assertType>(true); - }); +await test("reduce without initial / with empty iterable", () => { + const result = reduce([] as number[], (acc, v) => acc + v); + assertEquals(result, undefined); + assertType>(true); }); diff --git a/repeat_test.ts b/repeat_test.ts index f60dfe7..b054548 100644 --- a/repeat_test.ts +++ b/repeat_test.ts @@ -1,43 +1,40 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { repeat } from "./repeat.ts"; -Deno.test("repeat", async (t) => { - await t.step("with non empty iterable", () => { - const result = repeat([0, 1, 2], 2); - const expected = [0, 1, 2, 0, 1, 2]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("repeat with non empty iterable", () => { + const result = repeat([0, 1, 2], 2); + const expected = [0, 1, 2, 0, 1, 2]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with single value iterable", () => { - const result = repeat([0], 2); - const expected = [0, 0]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("repeat with single value iterable", () => { + const result = repeat([0], 2); + const expected = [0, 0]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with empty iterable", () => { - const result = repeat([] as number[], 2); - const expected: number[] = []; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("repeat with empty iterable", () => { + const result = repeat([] as number[], 2); + const expected: number[] = []; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with n=0", () => { - const result = repeat([0, 1, 2], 0); - const expected: number[] = []; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("repeat with n=0", () => { + const result = repeat([0, 1, 2], 0); + const expected: number[] = []; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the limit is not 0 nor positive safe integer", () => { - assertThrows(() => repeat([], NaN), RangeError); - assertThrows(() => repeat([], Infinity), RangeError); - assertThrows(() => repeat([], -Infinity), RangeError); - assertThrows(() => repeat([], -1), RangeError); - assertThrows(() => repeat([], 1.1), RangeError); - }); - }); +await test("repeat throws RangeError", () => { + assertThrows(() => repeat([], NaN), RangeError); + assertThrows(() => repeat([], Infinity), RangeError); + assertThrows(() => repeat([], -Infinity), RangeError); + assertThrows(() => repeat([], -1), RangeError); + assertThrows(() => repeat([], 1.1), RangeError); }); diff --git a/some_test.ts b/some_test.ts index 7d93d2f..db7b63a 100644 --- a/some_test.ts +++ b/some_test.ts @@ -1,38 +1,37 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { some } from "./some.ts"; -Deno.test("some", async (t) => { - await t.step("returns true if some elements satisfy the function", () => { +await test("some returns true if some elements satisfy the function", () => { + const values: number[] = []; + const indices: number[] = []; + const result = some([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v > 2; + }); + const expected = true; + assertEquals(result, expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>(true); +}); + +await test( + "some returns false if no elements satisfy the function", + () => { const values: number[] = []; const indices: number[] = []; const result = some([1, 2, 3, 4, 5], (v, index) => { values.push(v); indices.push(index); - return v > 2; + return v > 5; }); - const expected = true; + const expected = false; assertEquals(result, expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); + assertEquals(values, [1, 2, 3, 4, 5]); + assertEquals(indices, [0, 1, 2, 3, 4]); assertType>(true); - }); - - await t.step( - "returns false if no elements satisfy the function", - () => { - const values: number[] = []; - const indices: number[] = []; - const result = some([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v > 5; - }); - const expected = false; - assertEquals(result, expected); - assertEquals(values, [1, 2, 3, 4, 5]); - assertEquals(indices, [0, 1, 2, 3, 4]); - assertType>(true); - }, - ); -}); + }, +); diff --git a/take_test.ts b/take_test.ts index 607f2cb..7943421 100644 --- a/take_test.ts +++ b/take_test.ts @@ -1,40 +1,37 @@ +import { test } from "@cross/test"; import { assertEquals, assertThrows } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { iter } from "./iter.ts"; import { take } from "./take.ts"; -Deno.test("take", async (t) => { - await t.step("with positive limit", () => { - const result = take([0, 1, 2, 3, 4], 2); - const expected = [0, 1]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("take with positive limit", () => { + const result = take([0, 1, 2, 3, 4], 2); + const expected = [0, 1]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with 0 limit", () => { - const result = take([0, 1, 2, 3, 4], 0); - const expected: number[] = []; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("take with 0 limit", () => { + const result = take([0, 1, 2, 3, 4], 0); + const expected: number[] = []; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("will stop consuming once limit items is taken", () => { - const it = iter([0, 1, 2, 3, 4]); - const result = take(it, 3); - const expected: number[] = [0, 1, 2]; - assertEquals(Array.from(result), expected); - assertType>>(true); - // Ensure the iterator is NOT fully consumed - assertEquals(Array.from(it), [3, 4]); - }); +await test("take will stop consuming once limit items is taken", () => { + const it = iter([0, 1, 2, 3, 4]); + const result = take(it, 3); + const expected: number[] = [0, 1, 2]; + assertEquals(Array.from(result), expected); + assertType>>(true); + // Ensure the iterator is NOT fully consumed + assertEquals(Array.from(it), [3, 4]); +}); - await t.step("throws RangeError", async (t) => { - await t.step("if the limit is not 0 nor positive safe integer", () => { - assertThrows(() => take([], NaN), RangeError); - assertThrows(() => take([], Infinity), RangeError); - assertThrows(() => take([], -Infinity), RangeError); - assertThrows(() => take([], -1), RangeError); - assertThrows(() => take([], 1.1), RangeError); - }); - }); +await test("take throws RangeError", () => { + assertThrows(() => take([], NaN), RangeError); + assertThrows(() => take([], Infinity), RangeError); + assertThrows(() => take([], -Infinity), RangeError); + assertThrows(() => take([], -1), RangeError); + assertThrows(() => take([], 1.1), RangeError); }); diff --git a/take_while_test.ts b/take_while_test.ts index 203ee53..d367692 100644 --- a/take_while_test.ts +++ b/take_while_test.ts @@ -1,34 +1,33 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { takeWhile } from "./take_while.ts"; -Deno.test("takeWhile", async (t) => { - await t.step("with some true", () => { - const values: number[] = []; - const indices: number[] = []; - const result = takeWhile([1, 2, 3, 4, 5], (v, index) => { - values.push(v); - indices.push(index); - return v < 3; - }); - const expected = [1, 2]; - assertEquals(Array.from(result), expected); - assertEquals(values, [1, 2, 3]); - assertEquals(indices, [0, 1, 2]); - assertType>>(true); +await test("takeWhile with some true", () => { + const values: number[] = []; + const indices: number[] = []; + const result = takeWhile([1, 2, 3, 4, 5], (v, index) => { + values.push(v); + indices.push(index); + return v < 3; }); + const expected = [1, 2]; + assertEquals(Array.from(result), expected); + assertEquals(values, [1, 2, 3]); + assertEquals(indices, [0, 1, 2]); + assertType>>(true); +}); - await t.step("with all true", () => { - const result = takeWhile([1, 2, 3, 4, 5], () => true); - const expected = [1, 2, 3, 4, 5]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("takeWhile with all true", () => { + const result = takeWhile([1, 2, 3, 4, 5], () => true); + const expected = [1, 2, 3, 4, 5]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with all false", () => { - const result = takeWhile([1, 2, 3, 4, 5], () => false); - const expected: number[] = []; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("takeWhile with all false", () => { + const result = takeWhile([1, 2, 3, 4, 5], () => false); + const expected: number[] = []; + assertEquals(Array.from(result), expected); + assertType>>(true); }); diff --git a/uniq_test.ts b/uniq_test.ts index 9100ec0..66ad83a 100644 --- a/uniq_test.ts +++ b/uniq_test.ts @@ -1,34 +1,33 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { uniq } from "./uniq.ts"; -Deno.test("uniq", async (t) => { - await t.step("default", () => { - const result = uniq([1, 2, 2, 3, 3, 3]); - const expected = [1, 2, 3]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("uniq default", () => { + const result = uniq([1, 2, 2, 3, 3, 3]); + const expected = [1, 2, 3]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("with identify", () => { - const values: number[] = []; - const indices: number[] = []; - const identities: number[] = []; - const result = uniq( - [1, 2, 3, 4, 5, 6, 7, 8, 9], - (v, index) => { - values.push(v); - indices.push(index); - const id = v % 4; - identities.push(id); - return id; - }, - ); - const expected = [1, 2, 3, 4]; - assertEquals(Array.from(result), expected); - assertEquals(values, [1, 2, 3, 4, 5, 6, 7, 8, 9]); - assertEquals(indices, [0, 1, 2, 3, 4, 5, 6, 7, 8]); - assertEquals(identities, [1, 2, 3, 0, 1, 2, 3, 0, 1]); - assertType>>(true); - }); +await test("uniq with identify", () => { + const values: number[] = []; + const indices: number[] = []; + const identities: number[] = []; + const result = uniq( + [1, 2, 3, 4, 5, 6, 7, 8, 9], + (v, index) => { + values.push(v); + indices.push(index); + const id = v % 4; + identities.push(id); + return id; + }, + ); + const expected = [1, 2, 3, 4]; + assertEquals(Array.from(result), expected); + assertEquals(values, [1, 2, 3, 4, 5, 6, 7, 8, 9]); + assertEquals(indices, [0, 1, 2, 3, 4, 5, 6, 7, 8]); + assertEquals(identities, [1, 2, 3, 0, 1, 2, 3, 0, 1]); + assertType>>(true); }); diff --git a/zip_test.ts b/zip_test.ts index 940e464..aad521b 100644 --- a/zip_test.ts +++ b/zip_test.ts @@ -1,37 +1,36 @@ +import { test } from "@cross/test"; import { assertEquals } from "@std/assert"; import { assertType, type IsExact } from "@std/testing/types"; import { zip } from "./zip.ts"; -Deno.test("zip", async (t) => { - await t.step("zip with two iterables", () => { - const result = zip([1, 2, 3], ["a", "b", "c"]); - const expected = [[1, "a"], [2, "b"], [3, "c"]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("zip with two iterables", () => { + const result = zip([1, 2, 3], ["a", "b", "c"]); + const expected = [[1, "a"], [2, "b"], [3, "c"]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("zip with two in-balanced iterables", () => { - const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"]); - const expected = [[1, "a"], [2, "b"], [3, "c"]]; - assertEquals(Array.from(result), expected); - assertType>>(true); - }); +await test("zip with two in-balanced iterables", () => { + const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"]); + const expected = [[1, "a"], [2, "b"], [3, "c"]]; + assertEquals(Array.from(result), expected); + assertType>>(true); +}); - await t.step("zip with three iterables", () => { - const result = zip([1, 2, 3], ["a", "b", "c"], [true, false, true]); - const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; - assertEquals(Array.from(result), expected); - assertType>>( - true, - ); - }); +await test("zip with three iterables", () => { + const result = zip([1, 2, 3], ["a", "b", "c"], [true, false, true]); + const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; + assertEquals(Array.from(result), expected); + assertType>>( + true, + ); +}); - await t.step("zip with three in-balanced iterables", () => { - const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"], [true, false, true]); - const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; - assertEquals(Array.from(result), expected); - assertType>>( - true, - ); - }); +await test("zip with three in-balanced iterables", () => { + const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"], [true, false, true]); + const expected = [[1, "a", true], [2, "b", false], [3, "c", true]]; + assertEquals(Array.from(result), expected); + assertType>>( + true, + ); });