Skip to content

Commit 0489483

Browse files
committed
test(ac-parser): close two coverage gaps found in QA review of #946
- Export keywordMatcher (@internal, testing only) and add direct unit tests for it: metacharacter escaping ("a+b" keyword — proves the literal isn't misinterpreted as a regex quantifier) and allowPlural on/off behavior. - Add a regression-pinning test locking down which GATE_TEST_* keywords are plural-tolerant (fixture/section/flag/present) vs not (wired/exists/registered), so a future accidental list-swap fails a test instead of silently changing match behavior. Test-only diff — no production logic changed.
1 parent 60d3d72 commit 0489483

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

‎src/lib/ac-parser.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
inferVerificationMethod,
1515
resolveVerificationMethod,
1616
isGateTestEvidence,
17+
keywordMatcher,
1718
} from "./ac-parser.js";
1819

1920
// Real, unmodified GitHub issue bodies committed under __fixtures__ so the
@@ -925,4 +926,69 @@ Some notes here.
925926
).toBe(true);
926927
});
927928
});
929+
930+
// #946 gap-fix: keywordMatcher itself had no direct test, so its
931+
// metacharacter-escaping path was only ever exercised through keyword
932+
// lists that happen to contain no regex-special characters — a change
933+
// introducing a keyword with one (e.g. "c++") would have gone untested.
934+
describe("keywordMatcher", () => {
935+
it("escapes regex metacharacters in the keyword literal", () => {
936+
// "a+b" contains a literal `+` bounded by word characters on both
937+
// sides (required for \b to anchor meaningfully). Unescaped, `\ba+b\b`
938+
// would interpret `+` as "one or more of the preceding char" and
939+
// wrongly match plain "ab". Escaped, only the literal "a+b" matches.
940+
const re = keywordMatcher("a+b");
941+
expect(re.test("the a+b operator")).toBe(true);
942+
expect(re.test("the ab operator")).toBe(false);
943+
});
944+
945+
it("does not let an unescaped metacharacter match unrelated text", () => {
946+
// "a.b" — an unescaped `.` would match any character, so "aXb" would
947+
// wrongly match. Escaped, only the literal "a.b" matches.
948+
const re = keywordMatcher("a.b");
949+
expect(re.test("the a.b config key")).toBe(true);
950+
expect(re.test("the aXb config key")).toBe(false);
951+
});
952+
953+
it("with allowPlural=false matches only the exact word, not its plural", () => {
954+
const re = keywordMatcher("flag");
955+
expect(re.test("the flag is set")).toBe(true);
956+
expect(re.test("the flags are set")).toBe(false);
957+
});
958+
959+
it("with allowPlural=true matches both the exact word and its plural", () => {
960+
const re = keywordMatcher("flag", true);
961+
expect(re.test("the flag is set")).toBe(true);
962+
expect(re.test("the flags are set")).toBe(true);
963+
});
964+
});
965+
966+
// #946 gap-fix: pins down which GATE_TEST_* keywords are plural-tolerant.
967+
// A future edit that adds a keyword to the wrong list (e.g. moving
968+
// "registered" into the plural-tolerant set, or vice versa) fails this
969+
// test instead of silently changing match behavior unnoticed.
970+
describe("GATE_TEST keyword plural-tolerance boundaries (#946)", () => {
971+
it("plural-tolerant keywords (fixture, section, flag, present) match their plural form", () => {
972+
expect(isGateTestEvidence("the fixtures are in place")).toBe(true);
973+
expect(isGateTestEvidence("both sections match")).toBe(true);
974+
expect(isGateTestEvidence("the flags are set")).toBe(true);
975+
expect(isGateTestEvidence("the report presents two cases")).toBe(true);
976+
});
977+
978+
it("non-plural-tolerant keywords (wired, exists, registered) do NOT match an appended-s form", () => {
979+
// "wireds"/"existss"/"registereds" aren't real words, but if someone
980+
// mistakenly added plural tolerance to these keywords, these forms
981+
// would start matching — this test would catch that regression.
982+
expect(isGateTestEvidence("the cable wireds through the wall")).toBe(
983+
false,
984+
);
985+
expect(isGateTestEvidence("the file existss on disk")).toBe(false);
986+
// Uses "setting" rather than "flag" as filler — "flag" is itself a
987+
// plural-tolerant keyword and would match on its own, defeating the
988+
// point of isolating "registereds".
989+
expect(isGateTestEvidence("the setting registereds correctly")).toBe(
990+
false,
991+
);
992+
});
993+
});
928994
});

‎src/lib/ac-parser.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ function escapeRegExp(literal: string): string {
149149
* @param allowPlural - Also match a trailing "s" (e.g. `flag` -> `flags`).
150150
* Only meaningful for single nouns/verbs that commonly appear inflected
151151
* in prose; multi-word phrases never need it.
152+
*
153+
* @internal Exported for testing only — not part of the module's public API.
152154
*/
153-
function keywordMatcher(keyword: string, allowPlural = false): RegExp {
155+
export function keywordMatcher(keyword: string, allowPlural = false): RegExp {
154156
const escaped = escapeRegExp(keyword);
155157
const pattern = allowPlural ? `\\b${escaped}s?\\b` : `\\b${escaped}\\b`;
156158
return new RegExp(pattern, "i");

0 commit comments

Comments
 (0)