fix: repair failing utility-library tests (16 → 0 failures) - #333
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide now throws on division by zero - string-utils: wordCount collapses consecutive spaces; implement truncate with word-boundary + ellipsis-in-limit and maxLength bounds guard - task-manager: implement remove/update (false for unknown id) and sortBy (priority high>medium>low, createdAt oldest-first) - date-utils: fix formatRelative off-by-one at 36h boundary - validator: fix isEmail long TLD + tighten local-part dot rules; fix isUrl port handling
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 TypeScript utility library. Final result: 60 pass / 0 fail,
tsc --noEmitclean. No test files modified, no dependencies added.Changes by file
src/calculator.ts—dividenow throws on division by zero.src/string-utils.ts—wordCountcollapses consecutive whitespace ("hello world"→ 2); implementedtruncate(word-boundary cut,"..."counts towardmaxLength, returns unchanged when within limit). Added aRangeErrorguard for non-finite/negativemaxLength.src/task-manager.ts— implementedremoveandupdate(returnfalsefor unknown id), andsortBy(priority high→medium→low;createdAtoldest-first).src/date-utils.ts— fixedformatRelativeoff-by-one at the 36-hour boundary.src/validator.ts—isEmailnow accepts long TLDs and rejects leading/trailing/consecutive dots in the local part;isUrlhandles URLs with a port.Assumptions & notes
isEmailwas tightened (dot as an explicit separator) beyond the minimal fix; quoted local parts and IP-literal domains remain unsupported by design.isUrlaccepts loopback/localhost (required by tests). SSRF caveats for callers documented in the source.TaskManager.update/removetake no actor parameter — authorization is intentionally left to the caller/API layer.Verification
```
bun test → 60 pass, 0 fail, 70 expect() calls
```