fix: repair failing utility-library tests across 5 modules - #340
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide throws on division by zero instead of returning Infinity/NaN - date-utils: fix off-by-one in relative-day formatting (round at format time) - string-utils: implement truncate (word-boundary, ellipsis in budget); fix wordCount whitespace handling - task-manager: implement remove/update/sortBy - validator: allow long TLDs/subdomains in isEmail; allow ports in isUrl 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 in the utility library. 60/60 tests now pass,
tsc --noEmitis clean, and no previously-passing tests were broken. No test files were modified and no dependencies were added.Changes by module
src/calculator.ts—dividenow throwsError("Division by zero")onb === 0instead of silently returningInfinity/NaN.src/date-utils.ts— fixed off-by-one in relative-day formatting: the day bucket usedMath.floor(diffHours / 24)(36h → "1 day"); now rounds at format time so 36h correctly reads "2 days ago".src/string-utils.ts— implementedtruncate(breaks on word boundary, ellipsis counts towardmaxLength, returns unchanged when within limit). Also fixedwordCountto split on/\s+/after trimming so runs of whitespace (incl. tabs/newlines) count as one separator.src/task-manager.ts— implementedremove(true/false on delete),update(applies only present keys, false if id absent), andsortBy(priority high→medium→low, status, ascendingcreatedAt; sorts a copy so the internal Map order is untouched).src/validator.ts—isEmailnow accepts long TLDs and subdomains (old{2,4}cap rejected.museum) while still tightening malformed domains likea..com;isUrlnow accepts explicit ports (e.g.http://localhost:3000) while keeping thehttp/httpsscheme allowlist.Assumptions
test/where the source lacked a spec (notablytruncateword-boundary behaviour andsortByordering).sortBy("status")ordering is not asserted by any test; chose a reasonable fixed ranking.Reviewer notes (out-of-scope edge cases, non-blocking)
A review pass flagged edge cases the tests don't cover — left as-is to respect the "fix only what tests require" constraint:
truncatewith a negative/NaNmaxLengthbehaves oddly (slice offset semantics); no test exercises this.isUrl/isEmailvalidate syntax only — not SSRF/injection guards. Callers using them to gate server-side requests or output should add their own allowlist/sanitisation.divideonly guards0, notNaNdivisors.updatetreats an explicit{field: undefined}as a no-op rather than clearing the field.Testing