fix: repair 16 failing utility-library tests - #332
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: guard divide against zero (and -0) divisor - string-utils: fix wordCount for consecutive/whitespace runs; implement truncate at word boundary with ellipsis in budget - task-manager: implement remove/update/sortBy - date-utils: fix off-by-one in relative-day formatting (round + abs) - validator: broaden isEmail TLD/labels; allow ports in isUrl while keeping protocol allowlist
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 modules so the full suite passes (60 pass / 0 fail). No test files were modified and no dependencies were added — only the behaviour the tests require was changed.
Changes
src/calculator.ts—dividenow guards against a zero divisor (throws). Theb === 0check also catches-0, which previously produced-Infinity.src/string-utils.tswordCountnow trims and splits on/\s+/, correctly counting words separated by consecutive spaces (and tabs/newlines).truncateimplemented: returns the string unchanged whenstr.length <= maxLength; otherwise truncates at a word boundary with"..."counting towardmaxLength.src/task-manager.ts— implementedremove(delete by id),update(partial field update, returnsfalseif not found), andsortBy(returns a sorted copy, leaving internal insertion order intact).src/date-utils.ts— fixed off-by-one in relative-day formatting by rounding the (absolute) day difference instead of flooring, so 36h correctly reads "2 days ago" and future dates stay symmetric.src/validator.ts—isEmailbroadened to accept valid multi-label domains / longer TLDs while still rejecting malformed labels;isUrlnow accepts URLs with explicit ports (e.g.http://localhost:3000) while retaining the protocol allowlist.Verification
bun test→ 60 pass / 0 failbunx tsc --noEmit→ cleanmainbehaviour, left unchanged per the task scope ("fix only what the tests require").Assumptions
maxLength, clearing an optionaldescriptionviaupdate) were intentionally left as-is to avoid changing unverified behaviour.