mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 20:05:46 -06:00
test(tui): lock dunder markdown rendering (#95211)
* test(tui): lock dunder markdown rendering Co-authored-by: 张贵萍0668001030 <zhang.guiping@xydigit.com> * test(tui): lock dunder markdown rendering --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user