Skip to content

Cover the paths nothing exercised (94% -> 99% statements, 77% -> 97% branches) - #11

Merged
MaximBelov merged 1 commit into
masterfrom
feat/cover-error-paths
Aug 13, 2026
Merged

MaximBelov merged 1 commit into
masterfrom
feat/cover-error-paths

Conversation

@MaximBelov

Copy link
Copy Markdown
Owner

#10 added the measurement. This closes what it found.

Statements Branches
before 93.98% 77.06%
after 99.14% 97.31%

301 specs, 0 failures.

What is now covered

Every refusal. The big switch throws a two digit code which a switch at the bottom turns into a message, and nothing exercised either side of it — 32 messages, none of them pinned. spec/RefusedIdentifiersSpec.js covers all of them.

Four were only reachable by a barcode that stops in the middle of an AI, where the digit the switch is about to read is not there at all — ]C132, ]C134, ]C136, ]C19. That is an ordinary half-read scan, and no spec had ever sent one.

The symbology identifiers. ]C1 was the only one any spec used. ]e0, ]e1, ]e2, ]d2 and ]Q3 are covered now, along with a barcode arriving without one at all.

Elements carrying an ISO code, which take a different path depending on whether they end at a separator or run to the end of the barcode. Only the second was exercised.

The sliding year window. Worked out from the current year rather than hard coded, so these specs will not start failing on their own a few years from now.

Three identifiers were missing from the table

spec/ApplicationIdentifiersSpec.js is meant to hold every supported identifier. It did not hold these:

  • 7030–7039 PROCESSOR #
  • 7230–7239 CERT #
  • 8026 ITIP CONTENT

All three build their AI by concatenation — parseVariableLength("723" + fourthNumber, …) — so the extraction that first produced that table never saw them. Added, following the table's existing convention of one representative per composed family.

One piece of dead code removed

case "38" is gone from the message switch. checkDeclaredAIs runs after the parse loop, outside the try that feeds that switch, so the arm could never be reached from anywhere. The message is thrown where the check is, and there is now a comment saying why it does not go through the switch.

What is left, and why it stays

Everything still uncovered is unreachable, not merely untested:

  • the catch arms around parseInt and parseFloat — neither throws — and the messages they map to;
  • the default arm of the element type switch, since every caller passes a known type;
  • the default arm of the message switch, since every code in use has an arm of its own;
  • the half of the sliding window that reads a year as the century ahead: it needs a two digit year at least fifty behind the current one, which cannot be written in two digits before 2050.

Deleting those would be a change to the parser rather than to its specs, so they are documented in the README instead.

Thresholds

Raised to 99% statements and lines, 97% branches, 100% functions.

Checked against #9 before setting them: merged with the person identifiers this comes to 99.4% and 98.41%, so that PR clears the new thresholds rather than being blocked by them.

Found along the way, not fixed here

Two things worth their own change:

  1. 26 truncated prefixes return a bogus element. A barcode ending on a three digit prefix — ]C1430, ]C1701, ]C1230 and 23 others — comes back as a successful parse whose single element is the empty string, because those inner switches have no default. Same shape as the fall-through fixed in Fix switch fall-through breaking 46 application identifiers, add full AI coverage and CI #6.
  2. ]C143 reports "invalid AI after '42'". Two different defaults throw the same internal code. There is a spec pinning the current message with a comment saying it is wrong, so correcting it fails loudly and gets updated on purpose.

Coverage went in measuring 93.98% of statements and 77.06% of branches. This
takes it to 99.14% and 97.31%, and what is left is unreachable rather than
untested.

- Every way the parser can refuse an application identifier, 32 messages in
  all. Several are reached only by a barcode which stops in the middle of an
  AI, where the digit the switch is about to read is not there at all: a real
  scan of a damaged code, and previously not exercised once.
- The five symbology identifiers besides ]C1, and the path for a barcode
  arriving without one.
- Elements carrying an ISO code, which behave differently depending on whether
  they end at a separator or run to the end of the barcode.
- The sliding year window, worked out from the current year rather than hard
  coded, so the specs do not start failing on their own some year from now.

Three identifier families the parser supports were missing from the table that
is supposed to hold all of them: 703x PROCESSOR, 723x CERT and 8026 ITIP
CONTENT. They build their AI by concatenation, so the extraction which first
produced that table never saw them.

The case for code "38" is removed from the message switch. checkDeclaredAIs
runs after the parse loop, outside the try which feeds that switch, so the arm
could not be reached from anywhere; the message is thrown where the check is.

Thresholds are raised to match. Merged with the person identifiers still in
review this comes to 99.4% and 98.41%, so that change clears them too.
@MaximBelov
MaximBelov merged commit 6afc539 into master Aug 13, 2026
1 check passed
This was referenced Aug 13, 2026
@MaximBelov
MaximBelov deleted the feat/cover-error-paths 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