fix(utils): make all failing tests pass - #280
Open
stooit wants to merge 1 commit into
Open
Conversation
…e cases - calculator.divide: throw on division by zero (incl. -0) instead of returning Infinity/NaN - string-utils.truncate: implement word-boundary truncation with ellipsis counting toward maxLength - string-utils.wordCount: split on /\s+/ so runs of whitespace no longer inflate the count - task-manager: implement remove/update (partial-update safe) and sortBy (priority, status, createdAt) - date-utils.formatRelative: round instead of floor so 36h reads as "2 days ago"; fix future-dated sign - validator.isEmail: allow long TLDs and multi-level subdomains; isUrl: allow ports 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 5 source files in the utility library. Test suite now reports 60 pass, 0 fail. No test files were modified and no dependencies were added.
Changes
src/calculator.ts—dividethrows on division by zero (including-0) instead of silently returningInfinity/NaN.src/string-utils.ts— implementedtruncate(word-boundary truncation with"..."counting towardmaxLength; returns unchanged when within limit); fixedwordCountto split on/\s+/so runs of whitespace no longer inflate the count.src/task-manager.ts— implementedremove(returnstrue/false),update(returnsfalsefor unknown id; partial-update safe via!== undefinedchecks), andsortBy(priority high>medium>low, status ordering, andcreatedAtoldest-first).src/date-utils.ts—formatRelativeoff-by-one fixed:roundinstead offloorso 36 hours reads as "2 days ago"; also corrects the future-dated sign case.src/validator.ts—isEmailnow accepts long TLDs (e.g..museum) and multi-level subdomains while still rejecting empty labels;isUrlnow accepts URLs with a port (e.g.http://localhost:3000).Verification
bun test→ 60 pass, 0 failbunx tsc --noEmit→ cleanReview notes / assumptions
A review flagged two out-of-scope edge cases in
truncatethat no test covers and that don't affect the documented contract for sane inputs, left as-is per the "fix only what the tests require" constraint:maxLengthreturns""(undefined behaviour).isEmailremains a regex approximation (not RFC 5322) — suitable for form-level validation, not as a sole trust gate for delivery/identity.