Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/test-node.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/docs
deno.lock
.coverage
node_modules
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@jsr:registry=https://npm.jsr.io
1 change: 1 addition & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"imports": {
"@core/pipe": "./mod.ts",
"@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",
Expand Down
259 changes: 124 additions & 135 deletions mod_test.ts
Original file line number Diff line number Diff line change
@@ -1,151 +1,140 @@
import { test } from "@cross/test";
import { assertEquals } from "@std/assert";
import { assertType, type IsExact } from "@std/testing/types";
import { pipe } from "./mod.ts";

Deno.test("pipe", async (t) => {
await t.step("with no operators", async (t) => {
await t.step("should return the input", () => {
assertEquals(pipe(1), 1);
});
});
await test("pipe with no operators should return the input", () => {
assertEquals(pipe(1), 1);
});

await t.step("with one operator", async (t) => {
await t.step("should return operator applied value", () => {
assertEquals(pipe(1, (v) => v * 2), 2);
});
await test("pipe with one operator should return operator applied value", () => {
assertEquals(pipe(1, (v) => v * 2), 2);
});

await t.step("should resolve the type properly", () => {
pipe(1, (v) => {
assertType<IsExact<typeof v, number>>(true);
return v.toString();
});
});
await test("pipe with one operator should resolve the type properly", () => {
pipe(1, (v) => {
assertType<IsExact<typeof v, number>>(true);
return v.toString();
});
});

await t.step("with two operators", async (t) => {
await t.step("should return operator applied value", () => {
assertEquals(pipe(1, (v) => v * 2, (v) => v * 2), 4);
});
await test("pipe with two operators should return operator applied value", () => {
assertEquals(pipe(1, (v) => v * 2, (v) => v * 2), 4);
});

await t.step("should resolve the type properly", () => {
pipe(1, (v) => {
assertType<IsExact<typeof v, number>>(true);
return v.toString();
}, (v) => {
assertType<IsExact<typeof v, string>>(true);
return v.length;
});
});
await test("pipe with two operators should resolve the type properly", () => {
pipe(1, (v) => {
assertType<IsExact<typeof v, number>>(true);
return v.toString();
}, (v) => {
assertType<IsExact<typeof v, string>>(true);
return v.length;
});
});

await t.step("with three operators", async (t) => {
await t.step("should return operator applied value", () => {
assertEquals(pipe(1, (v) => v * 2, (v) => v * 2, (v) => v * 2), 8);
});
await test("pipe with three operators should return operator applied value", () => {
assertEquals(pipe(1, (v) => v * 2, (v) => v * 2, (v) => v * 2), 8);
});

await t.step("should resolve the type properly", () => {
pipe(1, (v) => {
assertType<IsExact<typeof v, number>>(true);
return v.toString();
}, (v) => {
assertType<IsExact<typeof v, string>>(true);
return v.length;
}, (v) => {
assertType<IsExact<typeof v, number>>(true);
return v.toString();
});
});
await test("pipe with three operators should resolve the type properly", () => {
pipe(1, (v) => {
assertType<IsExact<typeof v, number>>(true);
return v.toString();
}, (v) => {
assertType<IsExact<typeof v, string>>(true);
return v.length;
}, (v) => {
assertType<IsExact<typeof v, number>>(true);
return v.toString();
});
});

await t.step(`with twenty operators`, async (t) => {
await t.step("should return operator applied value", () => {
assertEquals(pipe(1, ...Array(20).fill((v: number) => v * 2)), 2 ** 20);
});
await test("pipe with twenty operators should return operator applied value", () => {
assertEquals(pipe(1, ...Array(20).fill((v: number) => v * 2)), 2 ** 20);
});

await t.step("should resolve the type properly", () => {
pipe(
1,
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
);
});
});
await test("pipe with twenty operators should resolve the type properly", () => {
pipe(
1,
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
(v) => {
assertType<IsExact<typeof v, number>>(true);
return v;
},
);
});
Loading