-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
579f7fb
commit 89709da
Showing
2 changed files
with
125 additions
and
135 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
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,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; | ||
}, | ||
); | ||
}); |