Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 54 additions & 17 deletions scripts/frontend-product-name.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(?<![\w])Bridge(?![\w])/g)) {
assert.ok(
line.slice(0, match.index).endsWith("ComplyEaze "),
`${file}:${index + 1}: a bare Bridge: ${trimmed}`,
);
visible += rest.slice(0, open);
rest = rest.slice(open + 2);
inBlockComment = true;
}
for (const match of visible.matchAll(/(?<![\w])Bridge(?![\w])/g)) {
if (!visible.slice(0, match.index).endsWith("ComplyEaze ")) {
found.push({ line: index + 1, text: line.trim() });
}
});
}
});
return found;
}

test("the front end's displayed text names the product in full", async () => {
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 */}<span>Bridge</span>"), [
{ line: 2, text: "still Bridge */}<span>Bridge</span>" },
]);
assert.deepEqual(bareBridges("{/* x */}<span>Bridge</span>"), [
{ line: 1, text: "{/* x */}<span>Bridge</span>" },
]);
assert.deepEqual(bareBridges("// Bridge\n * Bridge\n<span>ComplyEaze Bridge</span>"), []);
assert.deepEqual(bareBridges("<p>Bridge</p>"), [{ line: 1, text: "<p>Bridge</p>" }]);
});
Loading