fix: repair all failing tests across the utility library - #338
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide throws on division by zero instead of returning Infinity - string-utils: implement truncate (word-boundary, ellipsis in budget, negative/leading-whitespace hardening); wordCount collapses whitespace runs - task-manager: implement remove, update (partial, no field-blanking), sortBy (typed rank maps) - date-utils: diffDays uses round(abs()) fixing off-by-one day bucketing - validator: isEmail accepts long TLDs; isUrl allows 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 across the 5 source modules so the full suite passes (60 pass / 0 fail,
tsc --noEmitclean). No test files modified, no dependencies added.Changes
src/calculator.ts—dividethrowsError("Division by zero")whenb === 0instead of silently returningInfinity.src/string-utils.tstruncate: unchanged when withinmaxLength; otherwise reserves 3 chars for"..."(ellipsis counts toward the limit), cuts at the last word boundary with a hard-cut fallback, trims trailing whitespace. Hardened against negativemaxLength(clamped to 0) and leading-whitespace inputs.wordCounttrims then splits on/\s+/, collapsing whitespace runs.src/task-manager.ts— Implementedremove(Map.delete),update(returnsfalsefor unknown ids; only assigns fields present inchanges), andsortBy(sorts a copy via typedRecord<Priority,number>/Record<Status,number>rank maps).src/date-utils.ts—diffDaysusesMath.round(Math.abs(diffHours) / 24), fixing the off-by-one that bucketed 24–47h as "1 day".src/validator.ts—isEmailTLD quantifier{2,4}→{2,}(accepts long TLDs);isUrldrops theport === ""condition sohttp://localhost:3000validates, retaining http/https allowlisting.Assumptions
updatetreats omitted keys as "leave untouched"; clearingdescriptionvia{ description: undefined }is intentionally a no-op.trimStart()deliberately avoided intruncateto keep within-limit/whitespace-only inputs unchanged.Testing
bun test→ 60 pass, 0 failbunx tsc --noEmit→ cleanReviewer notes (out of scope, non-blocking)
isEmailis a format check only, not a deliverability/authorisation control.isUrlallowlists the scheme but not the host — SSRF risk if a caller server-side-fetches a user-supplied URL.