Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738import { describe, expect, it } from "vitest";import { parseScript } from "../../runner/parser";
/** P8-11: where checks are built in (the extension), `call NAME` must name one that is, and a script that does not is refused when it is read, not when it runs. */
const wrap = (body: string) => `test "t"\n start http://127.0.0.1:1/\n step "s"\n ${body}\n`;const errors = (text: string, checks?: string[]) => { const r = parseScript(text, checks === undefined ? {} : { checks }); return r.ok ? [] : r.errors;};
describe("parseScript with a list of built-in checks", () => { it("accepts a call to a listed check, with its arguments", () => { expect(errors(wrap('call session-check alice'), ["session-check", "balance-at-least"])).toEqual([]); }); it("refuses a call to a name that is not listed (E011), says which are, and names the line", () => { const e = errors(wrap("call nope 1"), ["session-check", "balance-at-least"]); expect(e).toHaveLength(1); expect(e[0]).toMatchObject({ code: "E011", line: 4 }); expect(e[0]!.message).toContain('"nope"'); expect(e[0]!.message).toContain("session-check, balance-at-least"); }); it("with an empty list every call is refused, and says there are none", () => { const e = errors(wrap("call anything"), []); expect(e[0]).toMatchObject({ code: "E011" }); expect(e[0]!.message).toContain("no checks are built in"); }); it("without a list nothing changes: the runner finds checks in scripts/checks when it runs", () => { expect(errors(wrap("call anything"))).toEqual([]); }); it("reports every unknown call, not just the first, and still reports other errors", () => { const text = `test "t"\n start http://127.0.0.1:1/\n step "s"\n call a\n call b\n clik text:"x"\n`; const codes = errors(text, ["c"]).map((e) => e.code); expect(codes.filter((c) => c === "E011")).toHaveLength(2); expect(codes).toContain("E002"); });});