From c54f646e52062e1fcf5e9cd85fee1271c7adc902 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2026 03:34:17 +0000 Subject: [PATCH] test: add tests for truncate utility in format.ts Implemented tests for the `truncate` string utility function covering happy paths (strings shorter, exactly matching, and longer than the limit) and edge cases including empty strings, limits of 0 or 1, and negative limit boundaries. These changes increase test coverage without altering any core logic. Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com> --- tests/format.test.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/format.test.ts diff --git a/tests/format.test.ts b/tests/format.test.ts new file mode 100644 index 0000000..97e1e1c --- /dev/null +++ b/tests/format.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, it } from "vitest"; +import { truncate } from "../src/tui/lib/format.js"; + +describe("truncate", () => { + it("returns the original string if it is shorter than the limit", () => { + expect(truncate("hello", 10)).toBe("hello"); + }); + + it("returns the original string if its length is exactly the limit", () => { + expect(truncate("hello", 5)).toBe("hello"); + }); + + it("truncates and appends an ellipsis if the string is longer than the limit", () => { + expect(truncate("hello world", 5)).toBe("hell…"); + expect(truncate("hello world", 8)).toBe("hello w…"); + }); + + it("handles empty strings correctly", () => { + expect(truncate("", 5)).toBe(""); + expect(truncate("", 0)).toBe(""); + }); + + it("handles limit of 0 correctly", () => { + expect(truncate("hello", 0)).toBe("…"); + }); + + it("handles limit of 1 correctly", () => { + expect(truncate("hello", 1)).toBe("…"); + }); + + it("handles negative limits correctly", () => { + expect(truncate("hello", -5)).toBe("…"); + }); +});