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

markdownTextDirection.test.ts

77 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 expect(markdownWithTextDirection("\uFEFFAPI א ב")).toBe(
35 `\uFEFF${RLM}API א ב`,
36 );
37 });
38​
39 it("skips code and keeps task list checkboxes intact", () => {
40 const markdown = "```\nconst a = 'مرحبا';\n```\n\n- [ ] npm تشغيل الأوامر من المجلد الرئيسي";
41 expect(markdownWithTextDirection(markdown)).toBe(
42 `\`\`\`\nconst a = 'مرحبا';\n\`\`\`\n\n- [ ] ${RLM}npm تشغيل الأوامر من المجلد الرئيسي`,
43 );
44 });
45​
46 it("keeps words apart across table cells", () => {
47 const markdown = "| Name | الاسم | الوصف |\n| --- | --- | --- |\n| Price | السعر | القيمة |";
48 expect(markdownWithTextDirection(markdown)).toBe(
49 `| ${RLM}Name | الاسم | الوصف |\n| --- | --- | --- |\n| ${RLM}Price | السعر | القيمة |`,
50 );
51 });
52​
53 it("puts the mark before a link so references and autolinks still parse", () => {
54 const markdown = [
55 "[Plantur] هذا شرح عربي طويل للمنتج",
56 "",
57 "<https://example.com> هذا شرح عربي طويل للرابط",
58 "",
59 "[Plantur]: /product",
60 ].join("\n");
61 expect(markdownWithTextDirection(markdown)).toBe(
62 [
63 `${RLM}[Plantur] هذا شرح عربي طويل للمنتج`,
64 "",
65 `${RLM}<https://example.com> هذا شرح عربي طويل للرابط`,
66 "",
67 "[Plantur]: /product",
68 ].join("\n"),
69 );
70 });
71​
72 it("marks Arabic paragraphs that open with inline code", () => {
73 expect(markdownWithTextDirection("`npm` تشغيل الأوامر من المجلد الرئيسي")).toBe(
74 `${RLM}\`npm\` تشغيل الأوامر من المجلد الرئيسي`,
75 );
76 });
77});