fix: repair failing tests across utility modules - #298
Open
stooit wants to merge 1 commit into
Open
Conversation
Fix 16 failing tests without touching test files or adding deps:
- calculator: divide now throws on division by zero instead of Infinity
- string-utils: implement truncate (ellipsis counts toward maxLength,
word-boundary aware); wordCount handles consecutive/other whitespace
- task-manager: implement remove/update/sortBy (priority + createdAt)
- date-utils: formatRelative rounds day diff (36h => "2 days ago");
also corrects a previously-untested future-date skew ("in N days")
- validator: isEmail accepts long TLDs (.museum); isUrl accepts a port
All 60 tests pass; tsc --noEmit clean.
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. Only source files under
src/were changed — no test files modified, no dependencies added.Result: 60 pass / 0 fail;
tsc --noEmitclean.Changes
dividethrows on division by zero (was returningInfinity).b === 0also covers-0.truncate(returns unchanged when within limit; ellipsis counts towardmaxLength; word-boundary aware; handlesmaxLength <= 3).wordCounttrims and splits on/\s+/, so consecutive spaces/tabs/newlines don't inflate the count.remove(false for unknown id),update(applies only provided fields; false for unknown id), andsortBy(priority high>medium>low; createdAt oldest-first).sortBysorts a copy and does not mutate internal state.formatRelativeoff-by-one fixed viaMath.round(Math.abs(diffHours)/24); 36h now reports "2 days ago".isEmailaccepts long TLDs (e.g..museum) via a{2,63}quantifier plus a 254-char length guard;isUrlaccepts URLs with a port (protocol allowlist retained, softp:/javascript:/data:/file:still rejected).Assumptions / notes
updateuses!== undefinedchecks, so it cannot clear an optional field — matches the common convention and no test requires clearing.package.json, ortsconfig.jsonchanged.Out of scope (flagged, not fixed)
isUrlaccepts any http/https host including loopback/private addresses — if ever used to guard a server-side fetch, that's an SSRF vector needing separate host allowlisting.isEmaillooseness (user@example..com) is unchanged.