diff options
Diffstat (limited to 'src/utils/anonymous.test.ts')
-rw-r--r-- | src/utils/anonymous.test.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/utils/anonymous.test.ts b/src/utils/anonymous.test.ts index 2da613f..45896bf 100644 --- a/src/utils/anonymous.test.ts +++ b/src/utils/anonymous.test.ts @@ -9,6 +9,7 @@ import { identity, instanciate, pass, + transform, } from "./anonymous.ts"; import { assertSpyCalls, spy } from "@std/testing/mock"; import { FALSE, TRUE } from "../../tests/fixtures/test_data.ts"; @@ -128,3 +129,34 @@ describe("extremeBy", () => { assertEquals(extremeBy(data, "min"), Infinity); }); }); + +describe("transform", () => { + it("applies the function to the input", () => { + const result = transform(5, (x) => x * 2); + assertEquals(result, 10); + }); + + it("works with strings", () => { + const result = transform("hello", (x) => x.toUpperCase()); + assertEquals(result, "HELLO"); + }); + + it("works with objects", () => { + const input = { a: 1, b: 2 }; + const result = transform(input, ({ a, b }) => a + b); + assertEquals(result, 3); + }); + + it("returns the correct type", () => { + const TRUE = true; + const FALSE = false; + const result = transform(TRUE, (x) => !x); + assertEquals(result, FALSE); + }); + + it("works with identity function", () => { + const input = [1, 2, 3]; + const result = transform(input, identity); + assertEquals(result, input); + }); +}); |