diff --git a/src/tui/components/hyperlink-markdown.test.ts b/src/tui/components/hyperlink-markdown.test.ts new file mode 100644 index 000000000000..ed155f2a6dc9 --- /dev/null +++ b/src/tui/components/hyperlink-markdown.test.ts @@ -0,0 +1,37 @@ +import { visibleWidth } from "@earendil-works/pi-tui"; +import { describe, expect, it } from "vitest"; +import { normalizeTestText } from "../../../test/helpers/normalize-text.js"; +import { markdownTheme } from "../theme/theme.js"; +import { HyperlinkMarkdown } from "./hyperlink-markdown.js"; + +describe("HyperlinkMarkdown", () => { + it("moves dunder identifiers intact across fenced code wrap boundaries", () => { + const markdown = new HyperlinkMarkdown( + ["```python", 'if __name__ == "__main__":', "```"].join("\n"), + 0, + 0, + markdownTheme, + ); + + const rendered = markdown.render(12); + const normalized = rendered.map((line) => normalizeTestText(line)); + + expect(rendered.every((line) => visibleWidth(line) <= 12)).toBe(true); + expect(normalized.some((line) => line.includes("__name__ =="))).toBe(true); + expect(normalized.some((line) => line.includes('"__main__":'))).toBe(true); + }); + + it("preserves underscores in fenced and inline code", () => { + const markdown = new HyperlinkMarkdown( + ["```python", "is_palindrome", "```", "", "Call `__init__`."].join("\n"), + 0, + 0, + markdownTheme, + ); + + const normalized = markdown.render(16).map((line) => normalizeTestText(line)); + + expect(normalized.some((line) => line.includes("is_palindrome"))).toBe(true); + expect(normalized.some((line) => line.includes("__init__"))).toBe(true); + }); +});