with 50 words or more, else , else ", () => { const e = ok(extractPage(doc(`Short teaser.${prose(200)}${prose(40, 5)} outside`), url)); expect(e.lead).not.toContain("teaser"); expect(e.lead).not.toContain("outside"); const b = ok(extractPage(doc(`${prose(200)}Share thisSign upMore`), url)); expect(b.lead).not.toMatch(/Share this|Sign up|More/); // A junk-looking name on a wrapper that holds most of the text is not junk. const w = ok(extractPage(doc(`${prose(200)}`), url)); expect(w.words).toBeGreaterThan(150); // A page wrapped whole in a is the page; a small form is dropped. const f = ok(extractPage(doc(`${prose(200)} Search the site`), url)); expect(f.words).toBeGreaterThan(150); expect(f.lead).not.toContain("Search the site"); }); it(" makes paragraphs; a single stays inside one", () => { const e = ok(extractPage(doc(`${prose(80)}${prose(80, 3)}still the second\n${prose(40, 7)}`), url)); expect(e.plan.units.map((u) => u.kind)).toEqual(["p", "p", "p"]); expect(e.lead).toContain("still the second"); }); it("headings outline needs three non-junk sections of 40 words covering half the text", () => { const sec = (h: string, n: number, from: number) => `${h}${prose(n, from)}`; expect(ok(extractPage(doc(sec("A", 60, 1) + sec("B", 60, 2) + sec("C", 60, 3)), url)).outline).toBe("headings"); // Only two long enough. expect(ok(extractPage(doc(`${prose(30)}` + sec("A", 60, 1) + sec("B", 60, 2) + sec("C", 20, 3)), url)).outline).toBe("none"); // Three, but the lead holds most of the text. expect(ok(extractPage(doc(`${prose(400)}` + sec("A", 45, 1) + sec("B", 45, 2) + sec("C", 45, 3)), url)).outline).toBe("none"); // Junk does not count; a heading that only starts like junk is not junk. expect(ok(extractPage(doc(sec("A", 60, 1) + sec("B", 60, 2) + sec("See also", 60, 3)), url)).outline).toBe("none"); expect(ok(extractPage(doc(sec("A", 60, 1) + sec("B", 60, 2) + sec("12 Comments", 60, 3)), url)).outline).toBe("none"); expect(ok(extractPage(doc(sec("A", 60, 1) + sec("B", 60, 2) + sec("Notes on the design", 60, 3)), url)).outline).toBe("headings"); }); it("a short intro gives way to the page's description, which is put before it", () => { const e = ok(extractPage(doc(`By someone.A${prose(60, 1)}B${prose(60, 2)}C${prose(60, 3)}`, ``), url)); expect(e.leadFrom).toBe("page-description"); expect(e.lead).toBe("What it is about.\nBy someone."); checkInvariant(e); }); it("the first sentence of a lead", () => { expect(firstSentence("One thing. Another thing.")).toBe("One thing."); expect(firstSentence("Version 2.5 is out. Next.")).toBe("Version 2.5 is out."); expect(firstSentence("No full stop")).toBe("No full stop"); }); it("keeps the unit invariant on any document built from the usual blocks", () => { const block = fc.oneof( fc.tuple(fc.integer({ min: 3, max: 120 }), fc.nat(29)).map(([n, f]) => `${prose(n, f)}`), fc.tuple(fc.integer({ min: 2, max: 6 }), fc.nat(29)).map(([l, f]) => `${prose(4, f).split(" ").slice(0, 4).join(" ")}`), fc.nat(29).map((f) => `${prose(5, f).split(" ").slice(0, 5).join(" ")}`), fc.constantFrom("I.", "II.", "3."), fc.tuple(fc.integer({ min: 5, max: 90 }), fc.nat(29)).map(([n, f]) => `${prose(n, f)}${prose(n, f + 1)}${prose(5, f + 2)}`), fc.nat(29).map((f) => `${prose(10, f)}${prose(8, f + 1)}`), fc.nat(29).map((f) => `${prose(6, f)}`), fc.nat(29).map((f) => `${prose(20, f)} ${prose(10, f + 1)}`), fc.nat(29).map((f) => `${prose(25, f)}`), fc.nat(29).map((f) => `let x = ${f};`), fc.nat(29).map((f) => `${prose(30, f)}`), ); fc.assert( fc.property(fc.array(block, { minLength: 1, maxLength: 40 }), fc.boolean(), (blocks, described) => { const e = extractPage(doc(`Title${blocks.join("\n")}`, described ? `` : ""), url); if (!e.ok) return; checkInvariant(e); }), { numRuns: 150 }, ); }); });