@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 134 lines 4.73 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2
3 import { inlineMarkdownUnitMarks, parseInlineMarkdown } from "./composer-rich-text";
4
5 describe("composer rich text markdown", () => {
6 it("preserves unmatched markers, escaped markers, and identifiers", () => {
7 for (const text of [
8 "plain text",
9 "snake_case",
10 "ملفٌ_اول و ملفٌ_ثاني",
11 "файл_один и файл_два",
12 "𐐀_𐐁_𐐂 and 𠀀_𠀁_𠀂",
13 "unmatched **",
14 "** spaced **",
15 "\\*literal\\*",
16 ]) {
17 expect(parseInlineMarkdown(text)).toEqual([{ text, marks: [] }]);
18 }
19 });
20
21 it("renders triple markers and nested styles", () => {
22 expect(parseInlineMarkdown("***both***")).toEqual([
23 { text: "both", marks: ["bold", "italic"] },
24 ]);
25 expect(parseInlineMarkdown("*a **b** c*")).toEqual([
26 { text: "a ", marks: ["italic"] },
27 { text: "b", marks: ["italic", "bold"] },
28 { text: " c", marks: ["italic"] },
29 ]);
30 expect(parseInlineMarkdown("**a `code` c**")).toEqual([
31 { text: "a ", marks: ["bold"] },
32 { text: "code", marks: ["bold", "code"] },
33 { text: " c", marks: ["bold"] },
34 ]);
35 });
36
37 it("preserves crossing italic and bold spans", () => {
38 expect(parseInlineMarkdown("*a**b*****c**")).toEqual([
39 { text: "a", marks: ["italic"] },
40 { text: "b", marks: ["italic", "bold"] },
41 { text: "c", marks: ["bold"] },
42 ]);
43 });
44
45 it("keeps repeated and alternate delimiters literal inside an active mark", () => {
46 const repeated = "*".repeat(10_000);
47 expect(parseInlineMarkdown(repeated + "text" + repeated)).toEqual([
48 { text: repeated.slice(2) + "text", marks: ["bold"] },
49 { text: repeated.slice(2), marks: [] },
50 ]);
51 const alternate = "__".repeat(5_000);
52 expect(parseInlineMarkdown("**~~" + alternate + "text" + alternate + "~~**")).toEqual([
53 { text: alternate + "text" + alternate, marks: ["bold", "strike"] },
54 ]);
55 });
56
57 // regression: #25180 underscores in URLs and paths were read as emphasis
58 it("keeps underscores inside URLs, paths, and filenames literal", () => {
59 for (const text of [
60 "Read https://example.com/_handle_/status/1 and open src/__test__.tsx",
61 "https://example.com/~_user_/a",
62 "_build_/file.ts",
63 "edit __init__.py, then",
64 "see __init__.py:42",
65 "open src/_a.ts_ and example.com/_handle_.",
66 "/" + "_".repeat(50_000) + "a",
67 ]) {
68 expect(parseInlineMarkdown(text)).toEqual([{ text, marks: [] }]);
69 }
70 for (const [text, styled, mark, rest] of [
71 ["_see src/a_b.ts_ now", "see src/a_b.ts", "italic", " now"],
72 ["_read/write access_ now", "read/write access", "italic", " now"],
73 ["__read/write access__ now", "read/write access", "bold", " now"],
74 ["_see src/_a.ts_(optional)", "see src/_a.ts", "italic", "(optional)"],
75 ["__see src/__a.ts__(optional)", "see src/__a.ts", "bold", "(optional)"],
76 ["_see src/_a.ts_.", "see src/_a.ts", "italic", "."],
77 ["_notes.md_ here", "notes.md", "italic", " here"],
78 ["_файл_один.py_ now", "файл_один.py", "italic", " now"],
79 ["_my_file.py is broken_ now", "my_file.py is broken", "italic", " now"],
80 ["_e.g._ this", "e.g.", "italic", " this"],
81 ["_and_/or", "and", "italic", "/or"],
82 ] as const) {
83 expect(parseInlineMarkdown(text)).toEqual([
84 { text: styled, marks: [mark] },
85 { text: rest, marks: [] },
86 ]);
87 }
88 for (const [text, first, second, mark] of [
89 ["_yes_/_no_", "yes", "no", "italic"],
90 ["__yes__/__no__.", "yes", "no", "bold"],
91 ["_a_b_/_no_", "a_b", "no", "italic"],
92 ] as const) {
93 expect(parseInlineMarkdown(text).slice(0, 3)).toEqual([
94 { text: first, marks: [mark] },
95 { text: "/", marks: [] },
96 { text: second, marks: [mark] },
97 ]);
98 }
99 expect(parseInlineMarkdown("and/_or_")).toEqual([
100 { text: "and/", marks: [] },
101 { text: "or", marks: ["italic"] },
102 ]);
103 expect(parseInlineMarkdown("_build_/file.ts and _x_, __init__.py and __y__")).toEqual([
104 { text: "_build_/file.ts and ", marks: [] },
105 { text: "x", marks: ["italic"] },
106 { text: ", __init__.py and ", marks: [] },
107 { text: "y", marks: ["bold"] },
108 ]);
109 });
110
111 it("keeps code span contents literal", () => {
112 expect(parseInlineMarkdown("`**not bold**`")).toEqual([
113 { text: "**not bold**", marks: ["code"] },
114 ]);
115 });
116
117 it("maps each source character to its marks, or null for a dropped delimiter", () => {
118 const bold = ["bold"];
119 expect(inlineMarkdownUnitMarks("**`*` w** \\*")).toEqual([
120 null,
121 null,
122 null,
123 ["bold", "code"],
124 null,
125 bold,
126 bold,
127 null,
128 null,
129 [],
130 [],
131 [],
132 ]);
133 });
134 });