import { describe, it, expect } from "vitest";
import { sectioniseDocument } from "../document-sectioniser.js";
describe("sectioniseDocument", () => {
    it("splits on markdown headings, titling each section by its heading", () => {
        const { summary, sections } = sectioniseDocument("# A\nalpha\n## B\nbeta");
        expect(sections.map((s) => s.title)).toEqual(["A", "B"]);
        expect(sections[0].body).toContain("alpha");
        expect(sections[1].body).toContain("beta");
        expect(summary.length).toBeGreaterThan(0);
    });
    it("falls back to size windows titled Part N when there are no headings", () => {
        const { sections } = sectioniseDocument("z".repeat(9000));
        expect(sections.length).toBeGreaterThanOrEqual(2);
        expect(sections[0].title).toBe("Part 1");
        expect(sections[1].title).toBe("Part 2");
    });
    it("returns a single section for short headingless text", () => {
        const { sections } = sectioniseDocument("just a line");
        expect(sections.length).toBe(1);
        expect(sections[0].body).toContain("just a line");
    });
    it("empty body yields empty summary and no sections", () => {
        expect(sectioniseDocument("")).toEqual({ summary: "", sections: [] });
        expect(sectioniseDocument("   ")).toEqual({ summary: "", sections: [] });
    });
    it("captures non-empty text before the first heading as a leading section (lossless split)", () => {
        const { sections } = sectioniseDocument("intro words here\n# A\nalpha");
        expect(sections.map((s) => s.title)).toEqual(["Introduction", "A"]);
        expect(sections[0].body).toContain("intro words here");
    });
    it("does not emit an empty leading section when text starts at the first heading", () => {
        const { sections } = sectioniseDocument("# A\nalpha");
        expect(sections.map((s) => s.title)).toEqual(["A"]);
    });
    it("caps a section body and the summary at their limits", () => {
        const { summary, sections } = sectioniseDocument("# H\n" + "y".repeat(20_000));
        expect(summary.length).toBeLessThanOrEqual(500);
        expect(sections[0].body.length).toBeLessThanOrEqual(4000);
    });
});
//# sourceMappingURL=document-sectioniser.test.js.map