fix: implement missing utilities and fix edge-case bugs to pass all tests - #323
Open
stooit wants to merge 1 commit into
Open
fix: implement missing utilities and fix edge-case bugs to pass all tests#323stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
…ests - calculator.divide: throw on division by zero instead of returning Infinity - string-utils.wordCount: split on /\s+/ so consecutive spaces count once - string-utils.truncate: implement word-boundary truncation with ellipsis counting toward maxLength - task-manager: implement remove, update, and sortBy methods - date-utils.formatRelative: fix off-by-one day bucketing (round abs hours) - validator: allow long TLDs in isEmail and 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 previously-failing tests across the utility library. All 60 tests now pass (
bun test) andtsc --noEmitis clean. Only the 5 source files were touched — no test files modified, no dependencies added.Changes
src/calculator.ts—dividethrowsError("Division by zero")whenb === 0instead of silently returningInfinity.src/string-utils.tswordCountsplits on/\s+/against the trimmed string, so consecutive spaces no longer count an empty word ("hello world"→ 2).truncateimplemented per the TODO: unchanged ifstr.length <= maxLength; otherwise reserves 3 chars for"...", cuts at the last word boundary, and never exceedsmaxLength.src/task-manager.ts— implementedremove(returnsMap.delete's boolean),update(returnsfalsefor unknown id, applies only present fields), andsortBy(priorityhigh>medium>low, status ranking,createdAtoldest-first).src/date-utils.ts—formatRelativeday bucket usesMath.round(Math.abs(diffHours) / 24), fixing the off-by-one so 36h reads "2 days ago" (and future dates round correctly).src/validator.ts—isEmailaccepts long TLDs and subdomains ({2,}instead of{2,4}, hyphen-safe labels);isUrlno longer rejects URLs with an explicit port.Verification
bun test→ 60 pass / 0 failtsc --noEmit→ cleanReview notes / assumptions
An independent review confirmed the fixes are correct and cleared the validator regex of ReDoS risk (linear on adversarial inputs). It also flagged edge cases not covered by the test suite and left out of scope per the "fix only what the tests require" constraint:
formatRelativecan display "24 hours ago" / "60 minutes ago" at the rounded top of a bucket.truncatetreats only a literal space as a word boundary; negativemaxLengthslices from the end.sortBy's typed union makes an unknown-field call unreachable via the public API, but a raw JS caller would getundefined.These are candidates for a follow-up hardening pass; none affect the passing suite.