@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, 04:45 UTC

main
ts 39 lines 1.39 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2
3 import { rehypeTextDirection } from "./markdownTextDirection";
4
5 const text = (value: string) => ({ type: "text", value });
6 const element = (tagName: string, children: object[]) => ({
7 type: "element",
8 tagName,
9 properties: {} as Record<string, unknown>,
10 children,
11 });
12
13 function directed(...blocks: ReturnType<typeof element>[]) {
14 rehypeTextDirection()({ type: "root", children: blocks });
15 return blocks;
16 }
17
18 describe("rehypeTextDirection", () => {
19 it("keeps raw HTML list items apart when counting words", () => {
20 const [list] = directed(
21 element("ul", [element("li", [text("مرحبا")]), element("li", [text("hello world")])]),
22 );
23 expect(list!.properties.dir).toBe("ltr");
24 });
25
26 it("leaves inline code out of the count and isolates it", () => {
27 const code = element("code", [text("useEffect useLayoutEffect React")]);
28 const [paragraph] = directed(element("p", [text("استخدم "), code, text(" هنا")]));
29 expect(paragraph!.properties.dir).toBe("rtl");
30 expect(code.properties.dir).toBe("ltr");
31 });
32
33 it("leaves code blocks to their own left-to-right frame", () => {
34 const code = element("code", [text("// احسب المجموع هنا")]);
35 const [pre] = directed(element("pre", [code]));
36 expect(pre!.properties.dir).toBeUndefined();
37 expect(code.properties.dir).toBeUndefined();
38 });
39 });