Skip to content

Commit

Permalink
test: use @cross/test instead
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Aug 19, 2024
1 parent 579f7fb commit 89709da
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 135 deletions.
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;
},
);
});

0 comments on commit 89709da

Please sign in to comment.