fix(utils): repair failing tests and implement missing utilities - #302
Open
stooit wants to merge 1 commit into
Open
fix(utils): repair failing tests and implement missing utilities#302stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
…ports Implement missing functionality and fix edge-case bugs surfaced by the test suite: - calculator: divide now throws on a zero divisor instead of returning Infinity - string-utils: wordCount collapses consecutive whitespace; truncate implemented with word-boundary cutting and ellipsis counting toward maxLength - task-manager: implement remove, update, and sortBy (priority/status/createdAt) - date-utils: round rather than floor day diffs so 36h reports '2 days ago' - validator: isEmail accepts long TLDs and rejects empty labels; isUrl accepts URLs with a port 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 failing tests across the utility library (60/60 now pass). Only
src/files were changed — no test files and no dependencies were touched.Changes
dividenow throws on a zero divisor instead of returningInfinity.wordCountcollapses runs of consecutive whitespace (trim().split(/\s+/));truncateimplemented: returns input unchanged when withinmaxLength, otherwise cuts at the last word boundary within budget and appends...(ellipsis counts towardmaxLength), with fallbacks for very small limits and no-space budgets.remove(returnstrue/false),update(guards unknown ids, only applies keys explicitly present), andsortBy(priority high→medium→low, status, and ascendingcreatedAt).Math.roundrather thanMath.floor, so 36h correctly reports "2 days ago" (off-by-one fix).isEmailaccepts long TLDs (e.g..museum) and rejects empty labels;isUrlaccepts URLs with a port (e.g.http://localhost:3000) while still restricting the protocol to http/https.Verification
bun test→ 60 pass, 0 fail.tsc --noEmitclean.Assumptions / notes
dividethrows a genericError— the test only asserts.toThrow().sortBy("createdAt")gained an explicitidtiebreaker becauseadd()stampscreatedAtto the millisecond; back-to-back adds could otherwise collide and rely on sort stability.