From 0af094770c4ebabc56ff761a8bd215bc397c0f7e Mon Sep 17 00:00:00 2001 From: João Augusto Costa Branco Marado Torres Date: Tue, 5 Aug 2025 18:50:37 +0100 Subject: refactor: reading page review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Augusto Costa Branco Marado Torres --- src/utils/anonymous.test.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/utils/anonymous.test.ts') 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); + }); +}); -- cgit v1.2.3