┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ import { describe, expect, it } from "vitest"; │
│ import { G, box, center, checkGrid, kv, len, pad, row2, row3, rule, ruleD, wrap, w │
│ rapHard } from "./ascii"; │
│ │
│ describe("len", () => { │
│ it("counts codepoints, not UTF-16 units", () => { │
│ expect(len("abc")).toBe(3); │
│ expect(len("?")).toBe(1); │
│ expect(len("")).toBe(0); │
│ expect(len(null)).toBe(0); │
│ expect(len(undefined)).toBe(0); │
│ }); │
│ }); │
│ │
│ describe("pad", () => { │
│ it("pads end by default", () => { │
│ expect(pad("ab", 5)).toBe("ab "); │
│ }); │
│ it("pads start", () => { │
│ expect(pad("ab", 5, "start")).toBe(" ab"); │
│ }); │
│ it("centers with the extra cell on the right", () => { │
│ expect(pad("ab", 5, "center")).toBe(" ab "); │
│ }); │
│ it("truncates overlong input at codepoint boundaries", () => { │
│ expect(pad("abcdef", 3)).toBe("abc"); │
│ expect(pad("???", 2)).toBe("??"); │
│ }); │
│ }); │
│ │
│ describe("rules", () => { │
│ it("rule and ruleD repeat to exact width", () => { │
│ expect(rule(4)).toBe("────"); │
│ expect(ruleD(3)).toBe("═══"); │
│ }); │
│ }); │
│ │
│ describe("box", () => { │
│ it("emits every line at exactly the box width", () => { │
│ const b = box({ width: 12, lines: ["hi", "a longer li"], title: "T" }); │
│ for (const line of b.split("\n")) expect(len(line)).toBe(12); │
│ }); │
│ it("draws corners and title separator", () => { │
│ const lines = box({ width: 8, lines: ["x"], title: "T" }).split("\n"); │
│ expect(lines[0]).toBe(G.TL + "──────" + G.TR); │
│ expect(lines[2]).toBe(G.LJ + "──────" + G.RJ); │
│ expect(lines.at(-1)).toBe(G.BL + "──────" + G.BR); │
│ }); │
│ it("centers content when asked", () => { │
│ const lines = box({ width: 8, lines: ["ab"], align: "center" }).split("\n"); │
│ expect(lines[1]).toBe("│ ab │"); │
│ }); │
│ }); │
│ │
│ describe("rows", () => { │
│ it("kv pads key and value to the total width", () => { │
│ expect(kv("K", "V", 4, 10)).toBe("K V "); │
│ }); │
│ it("row2 fills the gap to exact width", () => { │
│ const r = row2("LEFT", "RIGHT", 20); │
│ expect(len(r)).toBe(20); │
│ expect(r.startsWith("LEFT")).toBe(true); │
│ expect(r.endsWith("RIGHT")).toBe(true); │
│ }); │
│ it("row3 places left, center, right in exact width", () => { │
│ const r = row3("L", "CC", "R", 12); │
│ expect(len(r)).toBe(12); │
│ expect(r[0]).toBe("L"); │
│ expect(r[11]).toBe("R"); │
│ expect(r).toContain("CC"); │
│ }); │
│ it("center returns exact width", () => { │
│ expect(center("ab", 6)).toBe(" ab "); │
│ }); │
│ }); │
│ │
│ describe("wrap", () => { │
│ it("wraps greedily at word boundaries", () => { │
│ expect(wrap("aa bb cc", 5)).toBe("aa bb\ncc"); │
│ }); │
│ it("leaves a too-long word on its own line rather than splitting it", () => { │
│ expect(wrap("abcdefgh xy", 4)).toBe("abcdefgh\nxy"); │
│ }); │
│ it("returns single line when everything fits", () => { │
│ expect(wrap("aa bb", 10)).toBe("aa bb"); │
│ }); │
│ }); │
│ │
│ describe("wrapHard", () => { │
│ it("splits words wider than the width", () => { │
│ const out = wrapHard("feat(hosts:{ooksmedia,ooksdesk,ooknode}) done", 20); │
│ for (const line of out.split("\n")) expect(len(line)).toBeLessThanOrEqual(20); │
│ expect(out.replace(/\n/g, "")).toBe("feat(hosts:{ooksmedia,ooksdesk,ooknode})d │
│ one"); │
│ }); │
│ it("behaves like wrap for normal prose", () => { │
│ expect(wrapHard("aa bb cc", 5)).toBe(wrap("aa bb cc", 5)); │
│ }); │
│ }); │
│ │
│ describe("checkGrid", () => { │
│ it("accepts frame glyphs, arrows, and ASCII", () => { │
│ const ok = "│ ok [x] ... -- ↑↓ ╌ ═ ┼ ▁▄█ │"; │
│ expect(checkGrid(ok, 40, "t")).toBe(ok); │
│ }); │
│ it("rejects typographic glyphs - og ascii only", () => { │
│ expect(() => checkGrid("a - b", 10, "t")).toThrow(/U\+2014/); │
│ expect(() => checkGrid("a... ", 10, "t")).toThrow(/U\+2026/); │
│ expect(() => checkGrid("caf?", 10, "t")).toThrow(/off-grid/); │
│ }); │
│ it("throws on lines exceeding the width", () => { │
│ expect(() => checkGrid("abcdef", 5, "t")).toThrow(/6 cells, max 5/); │
│ }); │
│ it("throws on off-grid characters with the codepoint named", () => { │
│ expect(() => checkGrid("ok ?", 10, "t")).toThrow(/U\+1F44D/); │
│ expect(() => checkGrid("??", 10, "t")).toThrow(/off-grid/); │
│ }); │
│ it("rejects glyphs the font subset lacks, naming the context", () => { │
│ expect(() => checkGrid("a ? b", 10, "my-frame")).toThrow(/my-frame/); │
│ }); │
│ }); │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ import { describe, expect, it } from "vitest │
│ "; │
│ import { G, box, center, checkGrid, kv, len, │
│ pad, row2, row3, rule, ruleD, wrap, wrapHar │
│ d } from "./ascii"; │
│ │
│ describe("len", () => { │
│ it("counts codepoints, not UTF-16 units", │
│ () => { │
│ expect(len("abc")).toBe(3); │
│ expect(len("?")).toBe(1); │
│ expect(len("")).toBe(0); │
│ expect(len(null)).toBe(0); │
│ expect(len(undefined)).toBe(0); │
│ }); │
│ }); │
│ │
│ describe("pad", () => { │
│ it("pads end by default", () => { │
│ expect(pad("ab", 5)).toBe("ab "); │
│ }); │
│ it("pads start", () => { │
│ expect(pad("ab", 5, "start")).toBe(" a │
│ b"); │
│ }); │
│ it("centers with the extra cell on the rig │
│ ht", () => { │
│ expect(pad("ab", 5, "center")).toBe(" ab │
│ "); │
│ }); │
│ it("truncates overlong input at codepoint │
│ boundaries", () => { │
│ expect(pad("abcdef", 3)).toBe("abc"); │
│ expect(pad("???", 2)).toBe("??"); │
│ }); │
│ }); │
│ │
│ describe("rules", () => { │
│ it("rule and ruleD repeat to exact width", │
│ () => { │
│ expect(rule(4)).toBe("────"); │
│ expect(ruleD(3)).toBe("═══"); │
│ }); │
│ }); │
│ │
│ describe("box", () => { │
│ it("emits every line at exactly the box wi │
│ dth", () => { │
│ const b = box({ width: 12, lines: ["hi", │
│ "a longer li"], title: "T" }); │
│ for (const line of b.split("\n")) expect │
│ (len(line)).toBe(12); │
│ }); │
│ it("draws corners and title separator", () │
│ => { │
│ const lines = box({ width: 8, lines: ["x │
│ "], title: "T" }).split("\n"); │
│ expect(lines[0]).toBe(G.TL + "──────" + │
│ G.TR); │
│ expect(lines[2]).toBe(G.LJ + "──────" + │
│ G.RJ); │
│ expect(lines.at(-1)).toBe(G.BL + "────── │
│ " + G.BR); │
│ }); │
│ it("centers content when asked", () => { │
│ const lines = box({ width: 8, lines: ["a │
│ b"], align: "center" }).split("\n"); │
│ expect(lines[1]).toBe("│ ab │"); │
│ }); │
│ }); │
│ │
│ describe("rows", () => { │
│ it("kv pads key and value to the total wid │
│ th", () => { │
│ expect(kv("K", "V", 4, 10)).toBe("K V │
│ "); │
│ }); │
│ it("row2 fills the gap to exact width", () │
│ => { │
│ const r = row2("LEFT", "RIGHT", 20); │
│ expect(len(r)).toBe(20); │
│ expect(r.startsWith("LEFT")).toBe(true); │
│ expect(r.endsWith("RIGHT")).toBe(true); │
│ }); │
│ it("row3 places left, center, right in exa │
│ ct width", () => { │
│ const r = row3("L", "CC", "R", 12); │
│ expect(len(r)).toBe(12); │
│ expect(r[0]).toBe("L"); │
│ expect(r[11]).toBe("R"); │
│ expect(r).toContain("CC"); │
│ }); │
│ it("center returns exact width", () => { │
│ expect(center("ab", 6)).toBe(" ab "); │
│ }); │
│ }); │
│ │
│ describe("wrap", () => { │
│ it("wraps greedily at word boundaries", () │
│ => { │
│ expect(wrap("aa bb cc", 5)).toBe("aa bb\ │
│ ncc"); │
│ }); │
│ it("leaves a too-long word on its own line │
│ rather than splitting it", () => { │
│ expect(wrap("abcdefgh xy", 4)).toBe("abc │
│ defgh\nxy"); │
│ }); │
│ it("returns single line when everything fi │
│ ts", () => { │
│ expect(wrap("aa bb", 10)).toBe("aa bb"); │
│ }); │
│ }); │
│ │
│ describe("wrapHard", () => { │
│ it("splits words wider than the width", () │
│ => { │
│ const out = wrapHard("feat(hosts:{ooksme │
│ dia,ooksdesk,ooknode}) done", 20); │
│ for (const line of out.split("\n")) expe │
│ ct(len(line)).toBeLessThanOrEqual(20); │
│ expect(out.replace(/\n/g, "")).toBe("fea │
│ t(hosts:{ooksmedia,ooksdesk,ooknode})done"); │
│ }); │
│ it("behaves like wrap for normal prose", ( │
│ ) => { │
│ expect(wrapHard("aa bb cc", 5)).toBe(wra │
│ p("aa bb cc", 5)); │
│ }); │
│ }); │
│ │
│ describe("checkGrid", () => { │
│ it("accepts frame glyphs, arrows, and ASCI │
│ I", () => { │
│ const ok = "│ ok [x] ... -- ↑↓ ╌ ═ ┼ ▁▄█ │
│ │"; │
│ expect(checkGrid(ok, 40, "t")).toBe(ok); │
│ }); │
│ it("rejects typographic glyphs - og ascii │
│ only", () => { │
│ expect(() => checkGrid("a - b", 10, "t") │
│ ).toThrow(/U\+2014/); │
│ expect(() => checkGrid("a... ", 10, "t") │
│ ).toThrow(/U\+2026/); │
│ expect(() => checkGrid("caf?", 10, "t")) │
│ .toThrow(/off-grid/); │
│ }); │
│ it("throws on lines exceeding the width", │
│ () => { │
│ expect(() => checkGrid("abcdef", 5, "t") │
│ ).toThrow(/6 cells, max 5/); │
│ }); │
│ it("throws on off-grid characters with the │
│ codepoint named", () => { │
│ expect(() => checkGrid("ok ?", 10, "t")) │
│ .toThrow(/U\+1F44D/); │
│ expect(() => checkGrid("??", 10, "t")).t │
│ oThrow(/off-grid/); │
│ }); │
│ it("rejects glyphs the font subset lacks, │
│ naming the context", () => { │
│ expect(() => checkGrid("a ? b", 10, "my- │
│ frame")).toThrow(/my-frame/); │
│ }); │
│ }); │
└──────────────────────────────────────────────┘