import { expect, it } from "bun:test";
import * as limits from "../limits";
import { ulid } from "../ulid";
import { BLUE, CANARY, ID, OPEN, QUESTION, through } from "./questionnaire.test-fixtures";
// Whole archive 446a9779a937fa5be7cd3eb52fd7f3023d691ed2 callbacks.
it("round-trips chosen option identifiers", () => {
let source = OPEN.replace(
"",
`\n`,
);
let out = through(source);
expect(through(out)).toBe(out);
expect(out).toContain(` {
let source = OPEN.replace('multiple="false"', 'multiple="true"').replace(
"",
`\n`,
);
let out = through(source);
expect(through(out)).toBe(out);
expect(out).toContain(`choices="${CANARY} ${BLUE}"`);
});
it("keeps older and custom answers without chosen identifiers", () => {
let source = OPEN.replace(
"",
`\n`,
);
let out = through(source);
expect(through(out)).toBe(out);
expect(out).toContain(' {
let answer = (choices: string) =>
OPEN.replace("", `\n`);
expect(() => through(answer(ID))).toThrow(/Answer choices must name options/);
expect(() => through(answer(`${CANARY} ${CANARY}`))).toThrow(/cannot repeat/);
expect(() => through(answer(`${CANARY} ${BLUE}`))).toThrow(/accepts one choice/);
});
it("rejects more chosen identifiers than the legacy option ceiling", () => {
let ids = Array.from({ length: limits.MAX_OPTIONS + 1 }, () => ulid());
let source = (selected: string[]) =>
`\n`
+ `\n`
+ ids.map(id => `\n`).join("")
+ `\n`
+ `\n\n`;
expect(through(source(ids.slice(0, limits.MAX_OPTIONS)))).toContain("