import { describe, expect, it } from "vitest";
import { preserveTrailingMarkdownSpaces, restoreTrailingMarkdownSpaces } from "./trailing-markdown-spaces";
describe("preserveTrailingMarkdownSpaces", () => {
it.each([
["[/deploy](skill://deploy) ", "[/deploy](skill://deploy) "],
["/goal ", "/goal "],
["Send this ", "Send this "],
["Use `code` ", "Use `code` "],
])("preserves a final prose space through import: %s", (input, expected) => {
expect(preserveTrailingMarkdownSpaces(input)).toBe(expected);
expect(restoreTrailingMarkdownSpaces(expected)).toBe(input);
});
it.each(["", "No suffix", "Keep \nthis", "```text\ncode ", " code ", "
\ntext ", String.raw`literal\ `])(
"leaves other content unchanged: %s", (input) => {
expect(preserveTrailingMarkdownSpaces(input)).toBe(input);
},
);
});
describe("restoreTrailingMarkdownSpaces", () => {
it.each([
["Send this ", "Send this "],
["Send this \n", "Send this \n"],
["Send this \n\n", "Send this \n\n"],
["> - Send this ", "> - Send this "],
["Keep this ", "Keep this "],
["First line \nsecond \n", "First line \nsecond \n"],
["**bold ** \n", "**bold ** \n"],
["Use ` ` ", "Use ` ` "],
[String.raw`Use \\ `, String.raw`Use \\` + " "],
])("restores trailing prose spaces: %s", (input, expected) => {
expect(restoreTrailingMarkdownSpaces(input)).toBe(expected);
});
it.each([
"",
"Keep two spaces \nfor a hard break",
"Keep this",
"First line \nsecond",
"First line \nsecond",
"**bold **\n",
"*italic *\n",
String.raw`Keep \ `,
String.raw`Keep \\\ `,
"Use ` `",
"```text\n ",
"> ```text\n> ",
" ",
"
\n ",
"[link](https://example.com/ )",
])("preserves literal entities and other Markdown: %s", (input) => {
expect(restoreTrailingMarkdownSpaces(input)).toBe(input);
});
});