Something went wrong. Try again.
My pi setup: tools and prompts for multi model agentic coding
Something went wrong. Try again.
4.6 kB · 154 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155import { describe, expect, it } from "vitest";import { isBlank, isPresent, truncate } from "./string";
describe("string utilities", () => { describe("truncate", () => { it("should truncate long strings", () => { const result = truncate("This is a very long string", 10); expect(result).toBe("This is a ..."); });
it("should return original string if within limit", () => { const result = truncate("Short", 10); expect(result).toBe("Short"); });
it("should handle exact length", () => { const result = truncate("Exactly10!", 10); expect(result).toBe("Exactly10!"); });
it("should handle empty string", () => { const result = truncate("", 10); expect(result).toBe(""); });
it("should handle zero max length", () => { const result = truncate("Test", 0); expect(result).toBe("..."); });
it("should handle very short max length", () => { const result = truncate("Test", 2); expect(result).toBe("Te..."); });
it("should handle negative max length", () => { const result = truncate("Test", -5); expect(result).toBe("..."); });
it("should use custom ellipsis", () => { const result = truncate("This is a very long string", 10, "…"); expect(result).toBe("This is a …"); });
it("should use multi-character custom ellipsis", () => { const result = truncate("Hello world", 5, " [more]"); expect(result).toBe("Hello [more]"); });
it("should allow empty ellipsis", () => { const result = truncate("Hello world", 5, ""); expect(result).toBe("Hello"); });
it("should use custom ellipsis with zero max length", () => { const result = truncate("Test", 0, "---"); expect(result).toBe("---"); });
it("should use custom ellipsis with negative max length", () => { const result = truncate("Test", -5, "…"); expect(result).toBe("…"); });
it("should not append ellipsis when string fits", () => { const result = truncate("Short", 10, "!!"); expect(result).toBe("Short"); }); });
describe("isBlank", () => { it("should return true for empty strings", () => { expect(isBlank("")).toBe(true); expect(isBlank(" ")).toBe(true); expect(isBlank("\t\n\r")).toBe(true); });
it("should return true for null and undefined", () => { expect(isBlank(null)).toBe(true); expect(isBlank(undefined)).toBe(true); });
it("should return false for non-empty strings", () => { expect(isBlank("hello")).toBe(false); expect(isBlank("0")).toBe(false); expect(isBlank("false")).toBe(false); expect(isBlank(" hello ")).toBe(false); });
it("should handle numbers", () => { expect(isBlank(0)).toBe(false); expect(isBlank(1)).toBe(false); expect(isBlank(-1)).toBe(false); expect(isBlank(Number.NaN)).toBe(false); });
it("should handle mixed whitespace", () => { expect(isBlank(" \t \n ")).toBe(true); expect(isBlank(" hello ")).toBe(false); }); });
describe("isPresent", () => { it("should return true for non-empty strings", () => { expect(isPresent("hello")).toBe(true); expect(isPresent("0")).toBe(true); expect(isPresent("false")).toBe(true); expect(isPresent(" hello ")).toBe(true); });
it("should return false for empty strings", () => { expect(isPresent("")).toBe(false); expect(isPresent(" ")).toBe(false); expect(isPresent("\t\n\r")).toBe(false); });
it("should return false for null and undefined", () => { expect(isPresent(null)).toBe(false); expect(isPresent(undefined)).toBe(false); });
it("should handle mixed whitespace", () => { expect(isPresent(" \t \n ")).toBe(false); expect(isPresent(" hello ")).toBe(true); });
it("should return true for strings with only non-whitespace", () => { expect(isPresent("a")).toBe(true); expect(isPresent("1")).toBe(true); expect(isPresent("!")).toBe(true); }); });
describe("type guards", () => { it("should properly narrow types for isBlank", () => { const value: string | null | undefined = "";
if (isBlank(value)) { expect(value === "" || value === null || value === undefined).toBe( true, ); } });
it("should properly narrow types for isPresent", () => { const value: string | null | undefined = "hello";
if (isPresent(value)) { expect(value.length).toBeGreaterThan(0); } }); });});