Skip to content

Commit 7c87610

Browse files
authored
test(nxz): restore 100% coverage on memlimit.ts after parser refactor (#121)
The PR #120 extract-method refactor introduced three defensive paths in parseSuffixed that vitest's v8 instrumentation flagged as unreachable: the '?? ""' fallbacks on regex capture groups (unreachable when exec returns non-null) and the 'mult === undefined' guard (unreachable because the regex constrains the suffix to keys present in the multiplier map). - Replace 'match[1] ?? ""' and 'match[2] ?? ""' with 'as string' type assertions: compile-time only, no runtime branch for v8 to instrument, and not flagged by biome's noNonNullAssertion rule (unlike non-null '!' which would re-introduce the lint warning we resolved in PR #117 fix-round 1). - Wrap the noUncheckedIndexedAccess-required mult-undefined guard with /* v8 ignore start ... stop */: TypeScript strict mode demands the check but the regex+map alignment makes it structurally unreachable. Project convention is start/stop pairs (never 'next'). Coverage: lines 95.2 -> 100, branches 83.3 -> 100 on memlimit.ts. 707 tests still pass byte-identical.
1 parent de60b8f commit 7c87610

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/nxz/src/memlimit.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ function parseSuffixed(
4040
): bigint | null {
4141
const match = regex.exec(s);
4242
if (!match) return null;
43-
const num = match[1] ?? '';
44-
const suffix = (match[2] ?? '').toUpperCase();
43+
const num = match[1] as string;
44+
const suffix = (match[2] as string).toUpperCase();
4545
const mult = multipliers[suffix];
46+
/* v8 ignore start: defensive fail-closed; regex + map keys are pre-aligned, branch unreachable */
4647
if (mult === undefined) return null;
48+
/* v8 ignore stop */
4749
return BigInt(num) * mult;
4850
}
4951

0 commit comments

Comments
 (0)