fix: repair all failing tests across utility modules - #295
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide now throws on zero divisor instead of returning Infinity - string-utils: implement truncate (word-boundary, ellipsis budget, edge guards); wordCount splits on whitespace runs - task-manager: implement remove/update partial semantics and sortBy with stable tiebreak - date-utils: formatRelative rounds day magnitude symmetrically (fixes 36h boundary) - validator: isEmail accepts multi-level subdomains and 2+ char TLDs; isUrl no longer rejects URLs with a port
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 5 utility modules. Test suite goes from 44 pass / 16 fail to 60 pass / 0 fail.
tsc --noEmitis clean. No test files were modified and no dependencies were added — only the 5src/files changed.Changes by module
calculator.ts—dividenow throws on a zero divisor (incl.-0) instead of returningInfinity.string-utils.ts—wordCountsplits on whitespace runs (/\s+/on the trimmed string) so consecutive spaces/tabs/newlines no longer inflate the count.truncateimplemented: returns input unchanged within limit, otherwise cuts at a word boundary within the ellipsis budget, with a hard-cut fallback for over-long single words. Guards non-finite /<= 0maxLengthto"".task-manager.ts—removereturnstrue/falseon hit/miss;updatereturnsfalsefor unknown ids and applies only keys present inchanges(partial-update semantics);sortByreturns a sorted copy with rank maps for priority/status,createdAtascending, and a numeric-id tiebreak for deterministic ordering.date-utils.ts—formatRelativerounds the day magnitude, fixing the 36h boundary (now "2 days ago") and keeping past/future phrasing symmetric.validator.ts—isEmailaccepts multi-level subdomains and 2+ char TLDs (e.g..museum);isUrlno longer rejects valid URLs that carry a port (e.g.http://localhost:3000).Verification
bun test→ 60 pass, 0 fail, 70 expect() callstsc --noEmit→ cleanAssumptions
isUrl's existing protocol allowlist (rejectsftp:/javascript:/data:).sortByreturns a sorted copy rather than mutating internal state.truncatetreats non-finite / non-positivemaxLengthas"".