fix: repair failing tests and implement missing utility functions - #320
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and implement missing utility functions#320stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- calculator: divide() throws on division by zero instead of returning Infinity - date-utils: formatRelative() rounds days to nearest and is symmetric for future dates - validator: isEmail() supports subdomains and long TLDs; isUrl() allows ports - string-utils: wordCount() collapses consecutive whitespace; implement truncate() with whitespace-aware word boundaries and non-positive maxLength guard - task-manager: implement remove(), update(), and sortBy() All 60 tests pass; no test files or dependencies changed.
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 previously-failing tests across the utility library and implements the missing functionality. All 60 tests now pass; no test files were modified and no dependencies were added.
Changes (source only)
src/calculator.ts—divide()now throws on division by zero instead of silently returningInfinity.src/date-utils.ts—formatRelative()rounds days to the nearest value (36h → "2 days ago") and is symmetric for future dates by takingMath.absbefore rounding.src/validator.ts—isEmail()accepts subdomains and long TLDs (e.g..museum);isUrl()accepts URLs with a port (e.g.http://localhost:3000). Protocol allow-listing (http/https) retained.src/string-utils.ts—wordCount()collapses consecutive whitespace; implementedtruncate()with word-boundary truncation, ellipsis counting towardmaxLength, whitespace-aware boundaries, and a non-positivemaxLengthguard.src/task-manager.ts— implementedremove(),update(), andsortBy()(priority high>medium>low, status workflow order, createdAt oldest-first).Verification
Review notes / assumptions
A review pass caught two extra defects in previously-untested branches, both now fixed:
formatRelativefuture-date asymmetry, andtruncatesplitting mid-word on tabs/newlines / over-length output for negativemaxLength.Assumptions:
sortBy("createdAt")relies onArray.prototype.sortstability (ES2019+) for same-millisecond ties.update({ description: undefined })does not clear the field (partial-update semantics).isUrlis a protocol/format check, not an SSRF control — unchanged from prior behaviour.