Skip to content

Take coverage to 100%, fixing a real gap on the way - #13

Merged
MaximBelov merged 1 commit into
masterfrom
test/full-coverage
Aug 13, 2026
Merged

MaximBelov merged 1 commit into
masterfrom
test/full-coverage

Conversation

@MaximBelov

Copy link
Copy Markdown
Owner

Yes — 100% of statements, branches, functions and lines. Getting there turned up a real bug rather than just moving a number.

The bug

Dates and measures are read with parseInt and parseFloat, each wrapped in a try. Neither function throws on rubbish; they return NaN. So the catch blocks could never fire, and a barcode carrying letters where it should carry digits came back as a successful parse:

]C117ABCDEF    ->  { ai: "17", data: Invalid Date }
]C13103ABCDEF  ->  { ai: "3103", data: null }

Invalid Date is still instanceof Date, so a caller checking the type sees nothing wrong and only finds out downstream.

The parse now looks at the number rather than merely reading it — which is what those catch blocks were written to do — and refuses with invalid year in date, invalid month in date, invalid day in date or invalid number. That also makes error codes 33 to 36 reachable for the first time, which is most of what was missing from the coverage figure.

Valid input is untouched, including the day-of-00 reading that turns a date into the last day of its month.

The sliding window

The half of the year window that reads a year as belonging to the century ahead needs a two digit year at least fifty behind the current one. That cannot be written in two digits before 2050, so no fixed date would ever have exercised it. It is reached by moving the clock with jasmine.clock().mockDate() instead.

The same specs now pin both edges deterministically rather than depending on what year it happens to be, while the "as the clock stands today" block still checks the window really does move.

The two that stay uncovered

Two guards cannot be reached by construction:

  • the default arm of the element type switch — every construction in the file passes S, N or D;
  • the default arm of the message switch — every code the parser throws has an arm of its own.

Both are worth keeping. They are held out of the figure with /* c8 ignore */ and a comment saying why, rather than deleted to flatter the number.

Thresholds

Set at 100. Verified they bite rather than decorate: removing the new spec file drops the run to 99.36% statements and 98.04% branches, and the build fails.

313 specs, 0 failures.

Dates and measures were read with parseInt and parseFloat inside a try which
could never fire, because neither throws on rubbish - they return NaN. So a
barcode carrying letters where it should carry digits came back as a successful
parse holding an Invalid Date or a null weight, and every caller had to notice
that for itself. The parse now looks at the number rather than merely reading
it, which is what those catch blocks were meant to do all along, and what makes
error codes 33 to 36 reachable at last.

The far half of the sliding year window is reached by moving the clock. It
needs a two digit year fifty behind the current one, which cannot be written in
two digits before 2050, so no fixed date would ever have exercised it.

That leaves two guards which cannot be reached by construction: the default arm
of the element type switch, and the default arm of the message switch. Both are
worth keeping, so they are held out of the figure with c8 ignore and a comment
saying why, rather than deleted to flatter it.

Thresholds are set at 100. Verified they bite: removing the new spec file drops
the run to 99.36% and fails.
@MaximBelov MaximBelov mentioned this pull request Aug 13, 2026
@MaximBelov
MaximBelov merged commit 3b4aaea into master Aug 13, 2026
1 check passed
@MaximBelov
MaximBelov deleted the test/full-coverage branch August 13, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant