[READ-ONLY] Mirror of https://github.com/bombshell-dev/tty. Platform independent 2D layout engine for terminal applications based on Clay
5

Configure Feed

Select the types of activity you want to include in your feed.

test: failing repro for string-width

Nate Moore (Jun 4, 2026, 12:33 AM -0500) 4c49974b d75fb4b6

+37
+37
test/string-width.test.ts
··· 1 + import { describe, expect, it } from "./suite.ts"; 2 + import * as mod from "../mod.ts"; 3 + 4 + // stringWidth/charWidth are not exported yet. Cast keeps this type-checking 5 + // (the cast makes them `any`) while the runtime values are `undefined` today, 6 + // so calling them throws -> the assertions below fail at runtime, not compile. 7 + let charWidth = (mod as Record<string, unknown>).charWidth as ( 8 + cp: number, 9 + ) => number; 10 + let stringWidth = (mod as Record<string, unknown>).stringWidth as ( 11 + s: string, 12 + ) => number; 13 + 14 + describe("display-width helpers", () => { 15 + it("charWidth returns terminal cell columns per codepoint", () => { 16 + expect(charWidth(0x41)).toBe(1); // 'A' ASCII occupies 1 cell 17 + expect(charWidth(0x4f60)).toBe(2); // CJK 你 is wide -> 2 cells 18 + expect(charWidth(0x301)).toBe(0); // combining acute (Mn) -> 0 cells 19 + expect(charWidth(0x07)).toBe(0); // BEL control clamped to 0, not -1 20 + }); 21 + 22 + it("stringWidth sums per-codepoint display width", () => { 23 + expect(stringWidth("hello")).toBe(5); // 5 ASCII cells 24 + expect(stringWidth("你好")).toBe(4); // two wide CJK -> 4 cells 25 + expect(stringWidth("🍔")).toBe(2); // astral emoji is wide -> 2 cells 26 + }); 27 + 28 + it("stringWidth ignores zero-width combining marks", () => { 29 + // decomposed: 'e' (U+0065) + combining acute (U+0301), not precomposed U+00E9 30 + expect(stringWidth("é")).toBe(1); // 1 (e) + 0 (mark) = 1 cell 31 + }); 32 + 33 + it("stringWidth treats a VS16 emoji cluster as 2 cells", () => { 34 + // U+2764 (1) + U+FE0F (0): VS16 promotes the cluster to emoji width 35 + expect(stringWidth("❤️")).toBe(2); 36 + }); 37 + });