// Unit tests for the pure candidate extraction (run with `node --test`). Zero-dep. // CJS so it can require() extract.js, which is a UMD script (also a content script). const { test } = require("node:test"); const assert = require("node:assert/strict"); const { matchesIn, cueMatchesIn, allMatchesIn } = require("./extract.js"); test("matchesIn finds Title-Case / ALL-CAPS runs, skips stopwords", () => { // Note: "and" is a connector, so "X and Y" greedily joins into one run (by design, // for names like "Iron and Wine") — keep the two names in separate clauses here. const names = matchesIn("Cattle Decapitation is great; DEVOURMENT rules. I agree").map((m) => m.name); assert.ok(names.includes("Cattle Decapitation")); assert.ok(names.includes("DEVOURMENT")); assert.ok(!names.includes("I")); }); test("matchesIn reports positions that map back to the text", () => { const text = "Check out Devourment now"; const m = matchesIn(text).find((x) => x.name === "Devourment"); assert.equal(text.substr(m.index, m.length), "Devourment"); }); test("cueMatchesIn catches lowercase names after a cue phrase", () => { const names = cueMatchesIn("you should check out devourment honestly").map((m) => m.name); assert.ok(names.includes("devourment")); }); test("cueMatchesIn positions map back to the text", () => { const text = "i'm a big fan of cattle decapitation"; // "fan of" cue for (const m of cueMatchesIn(text)) assert.equal(text.substr(m.index, m.length), m.name); }); test("cueMatchesIn skips lowercase stopwords right after the cue", () => { const names = cueMatchesIn("check out the new album").map((m) => m.name); assert.ok(!names.includes("the")); }); test("allMatchesIn merges cue + Title-Case and sorts ascending by index", () => { const text = "Check out devourment and Cattle Decapitation"; const ms = allMatchesIn(text); for (let i = 1; i < ms.length; i++) assert.ok(ms[i].index >= ms[i - 1].index); const names = ms.map((m) => m.name); assert.ok(names.includes("devourment")); // cue (lowercase) assert.ok(names.includes("Cattle Decapitation")); // title-case });