import test from "node:test"; import assert from "node:assert/strict"; import { applyDialogueTextReplacements, applyTokenCasing, dialogueReplacementCatalog } from "../../shared/speech/dialogueText.js"; import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js"; import { normalizeDialogueTree } from "../../shared/quests/normalize.js"; test("applyTokenCasing follows placeholder case", () => { assert.equal(applyTokenCasing("mr", "ms"), "ms"); assert.equal(applyTokenCasing("Mr", "ms"), "Ms"); assert.equal(applyTokenCasing("MR", "ms"), "MS"); assert.equal(applyTokenCasing("He", "she"), "She"); }); test("dialogue text replacements cover names and gendered forms", () => { const male = applyDialogueTextReplacements( "Hello [Mr] [playername] [playersurname]. [He] brings [his] bag, [playerfullname].", { firstName: "Ada", lastName: "Worker", sex: "male" } ); assert.equal(male, "Hello Mr Ada Worker. He brings his bag, Ada Worker."); const female = applyDialogueTextReplacements( "Hello [Mr] [playername]. [He] / [him] / [his] / [man] / [himself].", { firstName: "Bea", lastName: "Smith", sex: "female" } ); assert.equal(female, "Hello Ms Bea. She / her / her / woman / herself."); }); test("dialogueReplacementCatalog lists player and gender tokens", () => { const tokens = dialogueReplacementCatalog().map((row) => row.token); assert.ok(tokens.includes("[playername]")); assert.ok(tokens.includes("[playerfullname]")); assert.ok(tokens.includes("[playersurname]")); assert.ok(tokens.includes("[he]")); assert.ok(tokens.includes("[mr]")); }); test("dialogue step lines are substituted for the player identity", () => { const harness = makeSimulation({ workerCount: 1 }); try { const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8, firstName: "Ada", lastName: "Worker", sex: "female" }); harness.simulation.spawnCharacter(1, character); harness.simulation.step(); const tree = normalizeDialogueTree({ dialogueId: "greet-name", steps: [{ stepId: "hi", lines: [{ speaker: "npc", text: "Welcome, [Mr] [playername]." }] }] }); const revisionId = harness.worldDb.getActiveRevisionId(); harness.worldDb.saveDialogueTree(revisionId, tree); harness.simulation.questContent.reload(); const opened = harness.simulation.quests.tryOpenDialogue( character.character_id, 9100, "greet-name" ); assert.equal(opened.ok, true); const step = (opened.events ?? []).find((e) => e.type === "dialogueStep"); assert.equal(step.lines[0].text, "Welcome, Ms Ada."); } finally { harness.close(); } });