test: add escaped dollar sign output cases

This commit is contained in:
Chris Wanstrath 2026-03-12 15:27:08 -07:00
parent e829c67e88
commit 341a2fee42
2 changed files with 24 additions and 0 deletions

View File

@ -112,6 +112,21 @@ describe("parse", () => {
expect(result.commands[0]!.expected).toEqual(["$ hello"])
})
test("multiple escaped dollar signs", () => {
const content = "$ printf '$ a\\n$ b\\n'\n\\$ a\n\\$ b\n"
const result = parse("test.shout", content)
expect(result.commands).toHaveLength(1)
expect(result.commands[0]!.expected).toEqual(["$ a", "$ b"])
})
test("escaped dollar before first command is ignored", () => {
const content = "\\$ not a command\n$ echo hi\nhi\n"
const result = parse("test.shout", content)
// \$ before any command — no current command to attach to, so skipped
expect(result.commands).toHaveLength(1)
expect(result.commands[0]!.expected).toEqual(["hi"])
})
test("no directives returns empty array", () => {
const result = parse("test.shout", "$ echo hi\nhi\n")
expect(result.directives).toEqual([])

View File

@ -0,0 +1,9 @@
$ echo '$ hello world'
\$ hello world
$ printf '$ line one\n$ line two\n'
\$ line one
\$ line two
$ echo 'no dollar here'
no dollar here