import { expect, test } from "bun:test";
import { parse } from "../src/index.ts";
test("an ssr data block is rejected and names the replacement", () => {
expect(() =>
parse(`page P {
ssr { api x GET /api/x { return users } }
view { x }
}
`),
).toThrow(/apis/);
});
test("a client data block is rejected and names the replacement", () => {
expect(() =>
parse(`page P {
client { api x GET /api/x { return users } }
view { x }
}
`),
).toThrow(/apis/);
});
test("client state is unaffected", () => {
// Different construct sharing the keyword. It must keep working.
const ast = parse(`page P {
client state { count = 0 }
view { x }
}
`);
expect(ast.states.some((state) => state.name === "count")).toBe(true);
});