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

markdownChipPunctuation.test.ts

39 lines1.2 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { rehypeChipPunctuation } from "./markdownChipPunctuation";
4​
5const text = (value: string) => ({ type: "text", value });
6const element = (tagName: string, children: object[]) => ({
7 type: "element",
8 tagName,
9 properties: {} as Record<string, unknown>,
10 children,
11});
12​
13function paired(block: ReturnType<typeof element>) {
14 rehypeChipPunctuation()({ type: "root", children: [block] });
15 return block.children;
17​
18describe("rehypeChipPunctuation", () => {
19 it.each([
20 ["See ", "... next", "...", " next"],
21 ["请查看 ", "。然后", "。", "然后"],
22 ["请查看(", "),继续", "),", "继续"],
23 ])(
24 "pairs a link with the punctuation that follows it (%s%s)",
25 (before, after, punctuation, rest) => {
26 const link = element("a", [text("a.ts")]);
27 expect(paired(element("p", [text(before), link, text(after)]))).toEqual([
28 text(before),
29 expect.objectContaining({ tagName: "span", children: [link, text(punctuation)] }),
30 text(rest),
31 ]);
32 },
33 );
34​
35 it("leaves code blocks alone", () => {
36 const children = [element("code", [text("a.ts")]), text(".")];
37 expect(paired(element("pre", [...children]))).toEqual(children);
38 });
39});