fix: repair failing tests across utility library - #339
Open
stooit wants to merge 1 commit into
Open
Conversation
…ation edge cases - calculator: divide throws on division by zero instead of returning Infinity - string-utils: wordCount handles consecutive spaces; implement truncate at word boundary - task-manager: implement remove, update, and sortBy methods - date-utils: diffDays uses Math.round to fix off-by-one in relative dates - validator: isEmail accepts subdomains/long TLDs; isUrl permits 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 previously-failing tests across 5 modules. Test suite now: 60 pass, 0 fail. Typecheck clean (
tsc --noEmit).Changes
src/calculator.tsdividethrowsError("Division by zero")when divisor is0instead of returningInfinity.src/string-utils.tswordCounttrims and splits on/\s+/(fixes consecutive-space over-count); implementedtruncateto cut at the last word boundary withinmaxLength - 3and append"...".src/task-manager.tsremove,update(applies only defined fields, returnsfalseif not found), andsortBy(priority, status, andcreatedAt).src/date-utils.tsdiffDaysusesMath.roundinstead ofMath.floor, fixing the off-by-one in relative-date rendering.src/validator.tsisEmailaccepts subdomains and longer TLDs;isUrlno longer rejects URLs that specify a port.Constraints honoured
Assumptions & notes for reviewers
isUrlis a format check, not an SSRF control. It now accepts any host/port includinglocalhost, RFC1918 addresses and169.254.169.254. Correct for the tests, but if this is ever used to validate a URL the server will fetch (webhooks/callbacks), it needs a separate resolved-host allowlist (OWASP SSRF; ISM-1685).sortBy("createdAt")relies onArray.prototype.sortstability for same-millisecond ties (guaranteed since ES2019). No explicit tiebreaker added, as tests don't require it.