fix: repair failing utility tests and implement missing functionality - #294
Open
stooit wants to merge 1 commit into
Open
fix: repair failing utility tests and implement missing functionality#294stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- calculator: divide throws on division by zero instead of returning Infinity - string-utils: fix wordCount for consecutive whitespace; implement truncate (word-boundary clip, ellipsis counts toward maxLength, short-string guard) - task-manager: implement remove/update return contracts and sortBy (priority high>medium>low, createdAt oldest-first, non-mutating copy) - date-utils: formatRelative uses Math.round on magnitude, fixing the day-bucket off-by-one for both past and future dates - validator: isEmail accepts long TLDs (.museum); isUrl accepts URLs with ports
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 in the utility library (60 pass / 0 fail, up from 44 pass / 16 fail) and implements the missing functionality the tests require. Only the 5
src/files were changed — no test files modified, no dependencies added.Changes
src/calculator.ts—dividenow throws on division by zero instead of returningInfinity(fail-closed on invalid input).src/string-utils.ts—wordCountsplits on/\s+/after trimming so runs of whitespace no longer produce phantom words;truncateimplemented: returns unchanged within limit, clips at a word boundary, counts the ellipsis towardmaxLength, and guards short strings.src/task-manager.ts—remove/updatehonour their boolean return contracts (false for unknown id, partial updates never clobber omitted fields);sortByorders priority high→medium→low andcreatedAtoldest-first, copying to an array so internal Map order isn't mutated (relies on stableArray.sort).src/date-utils.ts—formatRelativeday bucket usesMath.roundon the magnitude (Math.abs(diffHours)/24), fixing the off-by-one and keeping past/future symmetric.src/validator.ts—isEmailaccepts long TLDs (e.g..museum);isUrlaccepts URLs with ports (e.g.http://localhost:3000) while keeping thehttp/httpsprotocol allowlist.Verification
bun test: 60 pass, 0 fail (70 expect() calls, 5 files).tsc --noEmit: clean.formatRelative) was fixed in this branch.Assumptions / notes
Math.round), as the test comment specifies.formatRelativefuture-days path andsortBy("status")order are unit-tested only indirectly; general-correct behaviour was implemented and verified by direct execution. Follow-up tests (e.g.36h future → "in 2 days") would lock these in but could not be added under the "do not modify test files" constraint.🤖 Generated with QuantCode