1import { describe, expect, it } from "vite-plus/test";
2import { markdownWithTableBreaks } from "./markdownDocument";
3
4const table = "| Company | Fit |\n|---|---|\n| Acme | A |";
5
6describe("tables right under a line of text", () => {
7 it("separates a table from the paragraph it interrupts", () => {
8 expect(markdownWithTableBreaks(`Companies on file\n${table}`)).toBe(
9 `Companies on file\n\n${table}`,
10 );
11 });
12
13 it("handles CRLF and CR line endings", () => {
14 const crlf = table.replaceAll("\n", "\r\n");
15 expect(markdownWithTableBreaks(`Companies on file\r\n${crlf}`)).toBe(
16 `Companies on file\r\n\r\n${crlf}`,
17 );
18 const cr = table.replaceAll("\n", "\r");
19 expect(markdownWithTableBreaks(`Companies on file\r${cr}`)).toBe(`Companies on file\r\r${cr}`);
20 });
21
22 it("keeps the blank line inside a blockquote", () => {
23 const quoted = table.replace(/^/gm, "> ");
24 expect(markdownWithTableBreaks(`> Companies on file\n${quoted}`)).toBe(
25 `> Companies on file\n>\n${quoted}`,
26 );
27 });
28
29 it("keeps a table with a lazy header row inside its container", () => {
30 expect(markdownWithTableBreaks("> Intro\n| a | b |\n> | - | - |\n> | c | d |")).toBe(
31 "> Intro\n>\n> | a | b |\n> | - | - |\n> | c | d |",
32 );
33 expect(markdownWithTableBreaks("- Intro\n| a | b |\n | - | - |\n | c | d |")).toBe(
34 "- Intro\n\n | a | b |\n | - | - |\n | c | d |",
35 );
36 });
37
38 it("leaves Markdown that already renders alone", () => {
39 for (const markdown of [
40 `Companies on file\n\n${table}`,
41 `# Companies\n${table}`,
42 `\`\`\`md\nCompanies on file\n${table}\n\`\`\``,
43 "Not a table\n| a | b |\n|---|",
44 "a | b\nplain text",
45 ]) {
46 expect(markdownWithTableBreaks(markdown)).toBe(markdown);
47 }
48 });
49});