fix: resolve 16 failing tests across utility modules - #293
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide now throws on zero divisor instead of returning Infinity - string-utils: implement truncate; fix wordCount to collapse whitespace - task-manager: implement remove/update/sortBy with correct semantics - date-utils: fix off-by-one in formatRelative day bucketing (round vs floor) - validator: accept long TLDs in isEmail; accept host:port URLs in isUrl
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 in the utility library. Test suite now reports 60 pass / 0 fail (was 44 pass / 16 fail). Only the five
src/files were modified — no test files touched, no dependencies added.Changes
src/calculator.ts—dividenow throws on a zero divisor instead of returningInfinity(fail-closed on invalid input).src/string-utils.ts— implementedtruncate(word-boundary aware, never exceedsmaxLength); fixedwordCountto split on/\s+/after trimming so runs of whitespace and whitespace-only input count correctly.src/task-manager.ts— implementedremove(returnstrue/false),update(partial update, returnsfalsefor unknown id, omitted keys never clobber existing values), andsortBy(priority/status rank maps, chronologicalcreatedAt; sorts a copy, non-mutating).src/date-utils.ts— fixed off-by-one informatRelative: day bucket now usesMath.round(abs(diffHours)/24)instead of a pre-sign floor, so 36 hours correctly reads "2 days ago".src/validator.ts—isEmailaccepts long TLDs (example.museum) via{2,};isUrlaccepts host:port URLs (http://localhost:3000) by dropping the erroneous empty-port rejection, while still restricting the scheme allowlist to http/https.Verification
bun test→ 60 pass / 0 fail (70 expect() calls)tsc --noEmitcleanAssumptions / notes
isEmailis a pragmatic format-validation regex, not RFC 5322-complete — it should not be treated as proof an address is deliverable. If these validators gate anything security-relevant, delivery confirmation is the real control.