Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

markdownTextDirection.test.ts

76 lines3.2 KB

1import { describe, expect, it } from "vite-plus/test";
2import { markdownWithTextDirection } from "./markdownDocument";
3​
4const LRM = "‎";
5const RLM = "‏";
6​
7describe("markdownWithTextDirection", () => {
8 it("marks Arabic list items that open with an English name", () => {
9 const markdown = [
10 "## للنمو والتقوية",
11 "",
12 "- **Plantur**، Haarserum 100 مل، 14,95 €. سيروم مخصص للشعر الطويل بالكافيين، أغلى واحد في القائمة.",
13 "- **Bali Curls**، زيت إكليل الجبل للفروة والشعر، موجه للشعر اللي بيخف.",
14 ].join("\n");
15​
16 expect(markdownWithTextDirection(markdown)).toBe(
17 [
18 "## للنمو والتقوية",
19 "",
20 `- **${RLM}Plantur**، Haarserum 100 مل، 14,95 €. سيروم مخصص للشعر الطويل بالكافيين، أغلى واحد في القائمة.`,
21 `- **${RLM}Bali Curls**، زيت إكليل الجبل للفروة والشعر، موجه للشعر اللي بيخف.`,
22 ].join("\n"),
23 );
24 });
25​
26 it("keeps an English list on one side when one item opens in Arabic", () => {
27 const markdown = "- Install the package first.\n- مرحبا then run the build and tests.";
28 expect(markdownWithTextDirection(markdown)).toBe(
29 `- Install the package first.\n- ${LRM}مرحبا then run the build and tests.`,
30 );
31 });
32​
33 it("marks a byte order mark paragraph whose Hebrew is written as character references", () => {
34 const markdown = "\uFEFFAPI א ב";
35 expect(markdownWithTextDirection(markdown)).toBe(`${RLM}${markdown}`);
36 });
37​
38 it("skips code and keeps task list checkboxes intact", () => {
39 const markdown = "```\nconst a = 'مرحبا';\n```\n\n- [ ] npm تشغيل الأوامر من المجلد الرئيسي";
40 expect(markdownWithTextDirection(markdown)).toBe(
41 `\`\`\`\nconst a = 'مرحبا';\n\`\`\`\n\n- [ ] ${RLM}npm تشغيل الأوامر من المجلد الرئيسي`,
42 );
43 });
44​
45 it("keeps words apart across table cells", () => {
46 const markdown = "| Name | الاسم | الوصف |\n| --- | --- | --- |\n| Price | السعر | القيمة |";
47 expect(markdownWithTextDirection(markdown)).toBe(
48 `| ${RLM}Name | الاسم | الوصف |\n| --- | --- | --- |\n| ${RLM}Price | السعر | القيمة |`,
49 );
50 });
51​
52 it("puts the mark before a link so references and autolinks still parse", () => {
53 const markdown = [
54 "[Plantur] هذا شرح عربي طويل للمنتج",
55 "",
56 "<https://example.com> هذا شرح عربي طويل للرابط",
57 "",
58 "[Plantur]: /product",
59 ].join("\n");
60 expect(markdownWithTextDirection(markdown)).toBe(
61 [
62 `${RLM}[Plantur] هذا شرح عربي طويل للمنتج`,
63 "",
64 `${RLM}<https://example.com> هذا شرح عربي طويل للرابط`,
65 "",
66 "[Plantur]: /product",
67 ].join("\n"),
68 );
69 });
70​
71 it("marks Arabic paragraphs that open with inline code", () => {
72 expect(markdownWithTextDirection("`npm` تشغيل الأوامر من المجلد الرئيسي")).toBe(
73 `${RLM}\`npm\` تشغيل الأوامر من المجلد الرئيسي`,
74 );
75 });
76});