import { heredocBodies } from "./shell-regions.js"; // The one heredoc scan the policy classifier and the daemon's command readers share, pinned by exact offset. const bodiesOf = (command: string): string[] => heredocBodies(command).map(({ start, end }) => command.slice(start, end)); test("a body starts on the line after its opener, not at the newline, and ends where its terminator's line starts", () => { expect(heredocBodies("cat < { const command = "cat < { const command = "cat <<-EOF\n\tx\n\tEOF\nls"; expect(heredocBodies(command)).toEqual([{ start: 11, end: 14 }]); expect(bodiesOf(command)).toEqual(["\tx\n"]); }); test("the terminator is the whole word on its line, quoted delimiters included", () => { expect(bodiesOf("cat < { expect(heredocBodies("cat <<'EOF'\nrm -rf /")).toEqual([{ start: 12, end: 20 }]); expect(heredocBodies("cat < { expect(bodiesOf("cat <a\n1\nA\ncat <<-B >b\n\t2\n\tB\nls")).toEqual(["1\n", "\t2\n"]); });