mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-21 02:43:25 +01:00
Preserve an ordinary space after composer autocomplete selections and place the caret after it. Cover all seven completion types and queries with trailing spaces. Co-Authored-By: Paperclip <noreply@paperclip.ing>
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
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 ", "<div>\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>  ",
|
|
"  ",
|
|
"<div>\n ",
|
|
"[link](https://example.com/ )",
|
|
])("preserves literal entities and other Markdown: %s", (input) => {
|
|
expect(restoreTrailingMarkdownSpaces(input)).toBe(input);
|
|
});
|
|
});
|