// Run: node --test tests/ (or see AGENTS.md for the container one-liner) import test from "node:test"; import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { parsePlay, speakers, joinLines, tidySpacing } from "../public/parse.js"; const play = parsePlay(readFileSync(new URL("../public/plays/hra.txt", import.meta.url), "utf8")); test("pages are in order and missing ones are marked", () => { const nums = play.map((p) => p.num); assert.deepEqual(nums.slice(0, 4), ["1-4", "5", "6", "7"]); assert.deepEqual(play.filter((p) => p.missing).map((p) => p.num), ["1-4", "7"]); assert.equal(nums.at(-1), "27"); }); test("text at the top of a page continues the previous speaker", () => { const p15 = play.find((p) => p.num === "15"); assert.equal(p15.blocks[0].speaker, "Lysák"); assert.equal(p15.blocks[0].cont, true); }); test("cast is found and counted", () => { const names = speakers(play).map((s) => s.name); for (const n of ["Mise", "Lída", "Lysák", "Továrník", "Švec", "Paní bába", "Lysáková"]) assert.ok(names.includes(n), n); assert.ok(!names.includes("")); }); test("verse stays separate from the stage direction before it", () => { const p19 = play.find((p) => p.num === "19"); const julius = p19.blocks.find((b) => b.speaker === "Julius" && b.parts.some((x) => x.kind === "verse")); assert.deepEqual(julius.parts.map((x) => x.kind), ["stage", "verse"]); }); test("hyphenated line breaks are rejoined, dashes are kept", () => { assert.equal(joinLines(["Mám vždycky velmi nepří-", "jemné poslání."]), "Mám vždycky velmi nepříjemné poslání."); assert.equal(joinLines(["takovém houfci ne -", "spokojenců"]), "takovém houfci nespokojenců"); assert.equal(joinLines(["Jsem jen tak –", "nalehko."]), "Jsem jen tak – nalehko."); }); test("spacing is tidied without touching numbers", () => { assert.equal(tidySpacing("Ano, roky.Nyní je rok 1931.Jaké ?"), "Ano, roky. Nyní je rok 1931. Jaké?"); assert.equal(tidySpacing("nadějí .Jsem směšný"), "nadějí. Jsem směšný"); });