diff --git a/scripts/frontend-product-name.test.mjs b/scripts/frontend-product-name.test.mjs index ce317194e..110697413 100644 --- a/scripts/frontend-product-name.test.mjs +++ b/scripts/frontend-product-name.test.mjs @@ -26,26 +26,63 @@ const SOURCES = [ "src/tally-error-copy.ts", ]; -test("the front end's displayed text names the product in full", async () => { - for (const file of SOURCES) { - const lines = (await readFile(new URL(`../${file}`, import.meta.url), "utf8")).split("\n"); - let inBlockComment = false; - lines.forEach((line, index) => { - const trimmed = line.trimStart(); +/** + * The bare "Bridge" words outside comments in `text`, as `{ line, text }`. A line starting with + * `//` is a comment; a block comment is skipped from `/*` to its `*\/`, on one line or across + * several, and whatever follows its close on the same line is checked (#1190's review). + */ +export function bareBridges(text) { + const found = []; + let inBlockComment = false; + text.split("\n").forEach((line, index) => { + let visible = ""; + let rest = line; + while (rest.length > 0) { if (inBlockComment) { - if (line.includes("*/")) inBlockComment = false; - return; + const close = rest.indexOf("*/"); + if (close < 0) break; + rest = rest.slice(close + 2); + inBlockComment = false; + continue; } - if (["//", "*", "/*", "{/*"].some((comment) => trimmed.startsWith(comment))) { - inBlockComment = trimmed.includes("/*") && !trimmed.includes("*/"); - return; + const trimmed = rest.trimStart(); + if (visible.trim() === "" && (trimmed.startsWith("//") || trimmed.startsWith("* "))) break; + const open = rest.indexOf("/*"); + if (open < 0) { + visible += rest; + break; } - for (const match of line.matchAll(/(? { + for (const file of SOURCES) { + const text = await readFile(new URL(`../${file}`, import.meta.url), "utf8"); + assert.deepEqual( + bareBridges(text).map(({ line, text: shown }) => `${file}:${line}: ${shown}`), + [], + "a bare Bridge outside a comment", + ); } }); + +test("text after a comment closes is checked, and text inside one is not", () => { + assert.deepEqual(bareBridges("{/* Bridge's report\n still Bridge */}Bridge"), [ + { line: 2, text: "still Bridge */}Bridge" }, + ]); + assert.deepEqual(bareBridges("{/* x */}Bridge"), [ + { line: 1, text: "{/* x */}Bridge" }, + ]); + assert.deepEqual(bareBridges("// Bridge\n * Bridge\nComplyEaze Bridge"), []); + assert.deepEqual(bareBridges("
Bridge
"), [{ line: 1, text: "Bridge
" }]); +});