a62513cab1b5fe7ee649f49c7ac065a0d4b5336b diff --git a/scripts/p620/snapshot-tests.ts b/scripts/p620/snapshot-tests.ts index 588f22994aa53b2ace497861d0ad52164d8f5327..e4968cb4fd48484967af83d45843f1827ccf6f73 100644 --- a/scripts/p620/snapshot-tests.ts +++ b/scripts/p620/snapshot-tests.ts @@ -17,6 +17,7 @@ import { spawnSync } from "node:child_process"; import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { resolve } from "node:path"; +import { stripStringsAndComments } from "../../src/c32_sama_verify.ts"; const REPO_ROOT = resolve(import.meta.dir, "..", ".."); const OWNER = "syntaxai"; @@ -100,9 +101,17 @@ interface PlaceholderTest { // the catch is the common failure shape, not every theoretical one. const findPlaceholderTests = (testFile: string, content: string): PlaceholderTest[] => { const out: PlaceholderTest[] = []; + // Strip strings & comments to a same-length whitespace mask. Used + // below to skip any test()/it() match whose keyword sits inside a + // string literal (the c32_sama_verify.test.ts fixtures hold real + // test source as backtick strings — those aren't real tests). + const mask = stripStringsAndComments(content); const re = /\b(test|it)\s*\(\s*(["'`])((?:\\.|(?!\2).)*)\2\s*,\s*(?:async\s+)?(?:\([^)]*\)|[^=()]*?)\s*=>\s*\{/g; let m: RegExpExecArray | null; while ((m = re.exec(content)) !== null) { + // If the match position is whitespace in the mask, the original + // was inside a string or comment — skip. + if (mask[m.index] === " " || mask[m.index] === "\n") continue; const name = m[3] ?? ""; const startBrace = re.lastIndex - 1; let depth = 1; diff --git a/src/c32_sama_verify.ts b/src/c32_sama_verify.ts index 70f78c10eea1d058d485be31ad1544a74417d3ae..0564493da312bde26ba6a477c4409a9306ca2de9 100644 --- a/src/c32_sama_verify.ts +++ b/src/c32_sama_verify.ts @@ -49,7 +49,7 @@ const SAMA_PREFIX = /^c(\d{2})_/; // is the cheapest reliable fix for the test-fixture false-positive: // import strings and `test(...)` patterns inside literals/comments // would otherwise trigger Sorted/Atomic violations. -const stripStringsAndComments = (src: string): string => { +export const stripStringsAndComments = (src: string): string => { let out = ""; let i = 0; while (i < src.length) {