5347d89e76
- Corrected variable initialization order in formatPromptContent to prevent stale trimmedStart value when ASCII symbol replacement occurs. - Updated bash.md documentation to use ellipsis (...) instead of three dots (...) for consistency with ASCII symbol replacement behavior. - Added test case verifying table row compaction and content deduplication during pre-render with ASCII symbol replacement.
58 lines
2.3 KiB
TypeScript
58 lines
2.3 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { formatPromptContent } from "@oh-my-pi/pi-coding-agent/utils/prompt-format";
|
|
|
|
describe("formatPromptContent renderPhase", () => {
|
|
test("pre-render preserves indentation on Handlebars block lines", () => {
|
|
const input = "<root>\n {{#if ok}}\n value\n {{/if}}\n</root>";
|
|
|
|
const output = formatPromptContent(input, { renderPhase: "pre-render" });
|
|
|
|
expect(output).toBe("<root>\n {{#if ok}}\n value\n {{/if}}\n</root>");
|
|
});
|
|
|
|
test("pre-render preserves leading tabs", () => {
|
|
const input = "\t<root>\n\t {{#if ok}}\n\t value\n\t {{/if}}\n</root>";
|
|
|
|
const output = formatPromptContent(input, { renderPhase: "pre-render" });
|
|
|
|
expect(output).toBe(input);
|
|
});
|
|
|
|
test("pre-render trims trailing whitespace", () => {
|
|
const input = "\t<root> \n\t {{#if ok}}\t\n\t value \n\t {{/if}} \n</root>";
|
|
|
|
const output = formatPromptContent(input, { renderPhase: "pre-render" });
|
|
|
|
expect(output).toBe("\t<root>\n\t {{#if ok}}\n\t value\n\t {{/if}}\n</root>");
|
|
});
|
|
|
|
test("post-render mode preserves indentation on Handlebars-like lines", () => {
|
|
const input = "<root>\n {{#if ok}}\n value\n {{/if}}\n</root>";
|
|
|
|
const output = formatPromptContent(input, { renderPhase: "post-render" });
|
|
|
|
expect(output).toBe("<root>\n {{#if ok}}\n value\n {{/if}}\n</root>");
|
|
});
|
|
|
|
test("pre-render removes blank line before closing Handlebars block while post-render keeps it", () => {
|
|
const input = "<root>\n{{#if ok}}\nvalue\n\n{{/if}}\n</root>";
|
|
|
|
const preRender = formatPromptContent(input, { renderPhase: "pre-render" });
|
|
const postRender = formatPromptContent(input, { renderPhase: "post-render" });
|
|
|
|
expect(preRender).toBe("<root>\n{{#if ok}}\nvalue\n{{/if}}\n</root>");
|
|
expect(postRender).toBe("<root>\n{{#if ok}}\nvalue\n\n{{/if}}\n</root>");
|
|
});
|
|
test("pre-render compacts table rows and does not duplicate content when replacing ascii", () => {
|
|
const input =
|
|
'|`cat <<\'EOF\' > file`|`write(path="file", content="...")`|\n|`sed -i \'s/old/new/\' file`|`edit(path="file", edits=[...])`|';
|
|
const output = formatPromptContent(input, {
|
|
renderPhase: "pre-render",
|
|
replaceAsciiSymbols: true,
|
|
});
|
|
expect(output).toBe(
|
|
'|`cat <<\'EOF\' > file`|`write(path="file", content="…")`|\n|`sed -i \'s/old/new/\' file`|`edit(path="file", edits=[…])`|',
|
|
);
|
|
});
|
|
});
|