Conversation
Fix 16 failing tests across the utility library: - calculator: divide now throws on division by zero - string-utils: wordCount collapses consecutive whitespace; implement truncate at word boundary with ellipsis counting toward maxLength - task-manager: implement remove, update (partial), and sortBy (priority, createdAt) - date-utils: fix off-by-one in formatRelative (round vs floor) - 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 pass / 0 fail) by implementing missing functionality and correcting edge-case bugs across the utility library. No test files modified; no new dependencies added.
Changes
src/calculator.ts—dividethrows on division by zero (was returningInfinity).src/string-utils.ts—wordCountcollapses consecutive whitespace via/\s+/;truncateimplemented (word-boundary cut,"..."counting towardmaxLength, unchanged when within limit, handles strings shorter than the ellipsis).src/task-manager.ts— implementedremove(returns bool),update(partial updates, ignoresundefinedkeys), andsortBy(priority high>medium>low; createdAt oldest-first).src/date-utils.ts— fixed off-by-one informatRelative(Math.roundinstead ofMath.floor; 36h → "2 days ago").src/validator.ts—isEmailaccepts multi-level subdomains and long TLDs;isUrlaccepts URLs with ports (scheme still restricted to http/https).Verification
bun test→ 60 pass, 0 failnpx tsc --noEmit→ cleanisEmailregex confirmed linear time on adversarial input.Assumptions & notes (deliberately out of scope — no test coverage)
Kept changes minimal per the "fix only what the tests require" constraint. Review flagged these as potential follow-ups, left unchanged to avoid untested scope creep:
isEmaillocal-part uses an explicit allow-list; apostrophe/non-ASCII local parts (e.g.O'Brien, non-Anglicised names) are rejected. Worth widening for inclusivity if this gates a user-facing form.truncatecan return bare"..."when the only space in the budget is leading whitespace.updatecannot explicitly clear an optional field (uses!== undefinedrather than"key" in changes).sortBy("status")ordering (in_progress>pending>completed) is implemented but untested/invented so the declared type isn't lying.isUrlvalidates scheme+syntax only, not destination safety (not an SSRF guard).