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

proposedPlanText.test.ts

44 lines1.7 KB

1import { expect, it } from "vite-plus/test";
2import { proposedPlanTitle, stripDisplayedPlanMarkdown } from "./proposedPlanText.ts";
3​
4it("takes the plan title from headings outside code", () => {
5 for (const [open, inner, close] of [
6 ["```bash", "~~~", "```"],
7 ["~~~bash", "```", "~~~"],
8 ["````bash", "```", "````"],
9 ]) {
10 const code = `${open}\n# Back up database\n${inner}\n# Still code\n${close}\n`;
11 expect(proposedPlanTitle(`${code}\n## Real Plan Title\n`)).toBe("Real Plan Title");
12 }
13 expect(proposedPlanTitle("```bash\n# Back up database\n")).toBeNull();
14 expect(proposedPlanTitle("\t# Back up database\n\n## Real Plan Title")).toBe("Real Plan Title");
15});
16​
17it("skips empty plan headings without reading into the next line", () => {
18 for (const [heading, title] of [
19 ["# \r\n###\t\r\n## ###\r\n## Real Title", "Real Title"],
20 ["## # #", "#"],
21 ["## ###\t###", "###"],
22 ]) {
23 const markdown = `${heading}\r\n\r\n## Summary\r\n\r\nBody text`;
24 expect(proposedPlanTitle(markdown)).toBe(title);
25 expect(stripDisplayedPlanMarkdown(markdown)).toBe("Body text");
26 }
27});
28​
29it("strips the displayed plan title and summary after leading blank lines", () => {
30 const markdown = "\r\n# My Plan\r\n\r\n## Summary\r\n\r\nBody text";
31 expect(proposedPlanTitle(markdown)).toBe("My Plan");
32 expect(stripDisplayedPlanMarkdown(markdown)).toBe("Body text");
33});
34​
35it("reads the plan title past a leading byte-order mark", () => {
36 for (const markdown of [
37 "\uFEFF# Rollout\n\nDeploy",
38 "\uFEFF # Rollout\r\n\r\n## Summary\r\n\r\nDeploy",
39 ]) {
40 expect(proposedPlanTitle(markdown)).toBe("Rollout");
41 expect(stripDisplayedPlanMarkdown(markdown)).toBe("Deploy");
42 }
43 expect(proposedPlanTitle("\uFEFF # Indented code")).toBeNull();
44});