-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from jsr-core/support-node
feat: add tests for supporting Node
- Loading branch information
Showing
178 changed files
with
3,204 additions
and
3,249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/docs | ||
deno.lock | ||
.coverage | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@jsr:registry=https://npm.jsr.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IsExact<typeof result, AsyncIterable<number | string>>>(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<IsExact<typeof result, AsyncIterable<number | string>>>(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<IsExact<typeof result, AsyncIterable<number | string>>>(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<IsExact<typeof result, AsyncIterable<number | string>>>(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<typeof result, AsyncIterable<number | string | boolean>> | ||
>( | ||
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<typeof result, AsyncIterable<number | string | boolean>> | ||
>( | ||
true, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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<IsExact<typeof result, AsyncIterable<number[]>>>(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); | ||
}); |
Oops, something went wrong.