fix: repair all failing tests across utility modules - #334
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide throws on zero divisor instead of returning Infinity/NaN - string-utils: wordCount collapses consecutive whitespace; implement truncate with word-boundary cutting and ellipsis counted toward maxLength - task-manager: implement remove/update/sortBy; fail loudly on unknown sort field - date-utils: fix off-by-one in formatRelative day rounding (36h -> 2 days ago) - validator: isEmail accepts long TLDs/subdomains; isUrl accepts ports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes all 16 failing tests (now 60/60 pass) across the utility library, implementing missing functionality and repairing edge-case bugs. No test files modified, no dependencies added.
tsc --noEmitis clean.Changes by module
calculator.ts—dividenow throws on a zero divisor (b === 0, also catches-0) instead of returningInfinity/NaN.string-utils.ts—wordCountusestrim().split(/\s+/)so consecutive whitespace no longer produces empty entries.truncateimplemented: cuts at a word boundary with"..."counting towardmaxLength, returns unchanged when within limit, never exceedsmaxLength.task-manager.ts— implementedremove(boolean),update(returns false for unknown id; only applies provided keys), andsortBy(priority high→medium→low, createdAt oldest first).sortBythrows on unknown field with aneverexhaustiveness guard.date-utils.ts— fixed off-by-one informatRelative:Math.round(abs(diffHours)/24)so 36h maps to "2 days ago"; future dates stay symmetric.validator.ts—isEmailaccepts arbitrary subdomain depth and long TLDs (e.g..museum);isUrlaccepts URLs with ports (e.g.http://localhost:3000) while still rejecting non-http(s) protocols.Verification
bun test→ 60 pass, 0 failbunx tsc --noEmit→ cleanReviewer notes / assumptions
divideis a semver-major behaviour change for consumers relying onInfinity/NaNpropagation. Required by the test suite; flagged for changelog.update's!== undefinedguard meansdescriptioncannot be cleared viaundefined— kept as the intentional convention.isEmail/isUrlare format checks, not trust-boundary controls. localhost/internal IPs accepted by design (unchanged from prior behaviour); add SSRF protection separately if a URL feeds a server-side fetch.🤖 Generated with QuantCode