From 93992029bd349185d15de02e0f633e95c62695a9 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 9 Nov 2025 12:34:02 -0800 Subject: tostring test, fixes --- tests/type-consistency/spec/index.ts | 3 ++- tests/type-consistency/spec/tostring.ts | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/type-consistency/spec/tostring.ts (limited to 'tests/type-consistency/spec') diff --git a/tests/type-consistency/spec/index.ts b/tests/type-consistency/spec/index.ts index 4532493..b2da682 100644 --- a/tests/type-consistency/spec/index.ts +++ b/tests/type-consistency/spec/index.ts @@ -1,5 +1,6 @@ import array from "./array"; import functions from "./function"; import types from "./types"; +import tostring from "./tostring"; -export default [array, functions, types]; +export default [array, functions, types, tostring]; diff --git a/tests/type-consistency/spec/tostring.ts b/tests/type-consistency/spec/tostring.ts new file mode 100644 index 0000000..4fcb803 --- /dev/null +++ b/tests/type-consistency/spec/tostring.ts @@ -0,0 +1,41 @@ +import path from "path"; +import { createTestHarness } from "../harness"; + +export default createTestHarness({ + harnessName: "ToString", + generatedPath: path.join(__dirname, "..", "generated"), +}) + .createFunctionTest({ + name: "Passes through strings literally", + program: "fn(x, tostring(x))", + cases: [ + { input: "hello", output: "hello" }, + { input: "1", output: "1" }, + { input: "[1,2,3]", output: "[1,2,3]" }, + ], + }) + .createFunctionTest({ + name: "Is idempotent", + program: "fn(x, tostring(tostring(x)))", + cases: [ + { input: "hello", output: "hello" }, + { input: "1", output: "1" }, + { input: "[1,2,3]", output: "[1,2,3]" }, + ], + }) + .createFunctionTest({ + name: "Handles primitives", + program: "fn(x, tostring(x))", + cases: [ + { input: 5, output: "5" }, + { input: true, output: "true" }, + ], + }) + .createFunctionTest({ + name: "Handles arrays and nested arrays", + program: "fn(x, tostring(x))", + cases: [ + { input: [1, 2, 3], output: "[1, 2, 3]" }, + { input: [1, 2, [3, 4, 5]], output: "[1, 2, [3, 4, 5]]" }, + ], + }); -- cgit v1.2.3-70-g09d2