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

textDirection.test.ts

62 lines2.5 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { markdownProseDirection, textDirection } from "./textDirection";
4​
5describe("textDirection", () => {
6 it.each([
7 ["Arabic", "اكتب دالة تجمع الأرقام", "rtl"],
8 ["Hebrew", "תקן את הבאג", "rtl"],
9 ["English", "fix the failing test", "ltr"],
10 [
11 "Arabic that opens with an English term",
12 "StrictMode: يعيد الـ render مرتين في التطوير",
13 "rtl",
14 ],
15 ["English quoting one Arabic word", "translate the label مرحبا for the login screen", "ltr"],
16 ["a tie, by its first word", "React مكتبة", "ltr"],
17 ["a tie that opens in Arabic", "مكتبة React", "rtl"],
18 ["Arabic around numbers and punctuation", "عدّل السطر 42، ثم شغّل الاختبارات (3)", "rtl"],
19 ])("reads %s", (_, text, direction) => {
20 expect(textDirection(text)).toBe(direction);
21 });
22​
23 it("leaves text without letters to its surroundings", () => {
24 expect(textDirection("42 — 7 ✓")).toBeUndefined();
25 });
26});
27​
28describe("markdownProseDirection", () => {
29 it.each([
30 [
31 "Hebrew around a code block",
32 "תתקן את זה:\n```ts\nexport function useCheckout(props: CheckoutProps) {\n return props.items.length;\n}\n```\nותריץ שוב",
33 "rtl",
34 ],
35 ["Hebrew around inline code", "לערוך את `apps/web/src/chat.tsx` או להשאיר `useMemo`?", "rtl"],
36 ["Hebrew around double-backtick code", "תבדוק ``const a = `b c d e` + f`` עכשיו", "rtl"],
37 [
38 "Hebrew after a four-backtick fence",
39 "````md\none two three four five six\n````\nשלום עולם, זה עובד",
40 "rtl",
41 ],
42 [
43 "Hebrew after a tilde fence",
44 "~~~\nnpm run build --filter web --force\n~~~\nזה נכשל אצלי",
45 "rtl",
46 ],
47 [
48 "Hebrew before an unclosed fence",
49 "שלום, הנה השגיאה:\n```\nError: cannot find module react dom client",
50 "rtl",
51 ],
52 ["Hebrew around a URL", "ראה https://github.com/pingdotgg/t3code/pull/24050 לפני", "rtl"],
53 ["English around inline code", "Should I edit `useMemo` or keep it?", "ltr"],
54 ["English quoting one Hebrew word", "Please check the שלום label before the release", "ltr"],
55 ])("reads %s", (_, markdown, direction) => {
56 expect(markdownProseDirection(markdown)).toBe(direction);
57 });
58​
59 it("leaves markdown without prose letters to its surroundings", () => {
60 expect(markdownProseDirection("```\nconst a = 1;\n```")).toBeUndefined();
61 });
62});