fix: repair 16 failing tests across utility library - #305
Open
stooit wants to merge 1 commit into
Open
Conversation
Fix 16 failing tests without modifying test files or adding dependencies: - calculator: divide now throws on division by zero instead of returning Infinity - string-utils: fix wordCount for consecutive whitespace; implement truncate with word-boundary cutting and ellipsis counting toward maxLength - task-manager: implement remove, update (partial), and sortBy (priority/createdAt) - date-utils: round day magnitude for symmetric past/future relative times - validator: allow long TLDs in isEmail; allow ports in isUrl
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 in the utility library. Test suite now reports 60 pass, 0 fail, and
tsc --noEmitis clean. No test files were modified and no dependencies were added.Changes
src/calculator.tsdividenow throwsError("Division by zero")when the divisor is0(previously returnedInfinity). Covers-0too.src/string-utils.tswordCountsplits on/\s+/against the trimmed string so consecutive/leading/trailing whitespace no longer counts as words.truncateimplemented: returns input unchanged when withinmaxLength, otherwise cuts at the last word boundary with the ellipsis counted towardmaxLength.src/task-manager.tsremove(returnsfalsefor unknown id),update(partial update,falsefor unknown id), andsortByforpriority(high→medium→low) andcreatedAt(oldest first). Sorts a copy so internal order is preserved.src/date-utils.tsformatRelativeday rounding fixed: rounds the magnitude (Math.round(Math.abs(diffHours) / 24)) so past and future intervals are symmetric — 36h resolves to "2 days ago" / "in 2 days".src/validator.tsisEmailallows TLDs longer than 4 chars (e.g..museum) and subdomains.isUrlaccepts a port (e.g.http://localhost:3000) while still restricting the protocol to http/https.Verification
bun test→ 60 pass / 0 failtsc --noEmit→ cleanMath.round-on-signed-value regression indate-utils(future dates were asymmetric with past dates); this was fixed before commit.Assumptions & notes
sortBy("createdAt")relies on ES2019 stable-sort for tasks created within the same millisecond (falls back to insertion order) — safe on Bun/Node.isEmail/isUrlare format validators, not safety checks.isUrlacceptslocalhost/private hosts by design (required by the tests); if its output ever gates an outbound fetch it needs separate SSRF/open-redirect controls.