fix: repair 16 failing tests across utility library - #316
Open
stooit wants to merge 1 commit into
Open
Conversation
… and validators Fix 16 failing tests across 5 source files: - calculator.divide: throw on division by zero instead of returning Infinity - string-utils.wordCount: collapse consecutive/mixed whitespace via /\s+/ - string-utils.truncate: implement word-boundary truncation with ellipsis budget - task-manager: implement remove, update (partial), and sortBy (priority/status/createdAt) - date-utils.formatRelative: use Math.round to fix day off-by-one (36h -> 2 days ago) - validator.isEmail: allow subdomains and long TLDs (e.g. .museum) - validator.isUrl: allow 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 across 5 source files in the utility library.
bun testnow reports 60 pass / 0 fail. No test files were modified and no dependencies were added.Changes
src/calculator.ts—dividethrowsError("Division by zero")on a zero divisor instead of returningInfinity.src/string-utils.tswordCountsplits on/\s+/against the trimmed string so consecutive/mixed whitespace collapses correctly.truncateimplemented: returns input unchanged when withinmaxLength; otherwise cuts to the last word boundary and appends"...", keeping the result withinmaxLength. Hard-slices whenmaxLength <= 3.src/task-manager.ts— implementedremove(returns hit/miss),update(partial update, guards each field,falseon unknown id), andsortBy(priority high>medium>low, status pending>in_progress>completed,createdAtoldest first; sorts a copy to avoid mutating internal order).src/date-utils.ts—formatRelativeusesMath.roundon the hour delta instead ofMath.floor, fixing the day off-by-one (36h now reads "2 days ago").src/validator.tsisEmailallows subdomains and TLDs of 2+ letters (e.g..museum) while still rejecting non-emails.isUrlallows URLs with a port (e.g.http://localhost:3000); protocol still restricted tohttp:/https:.Assumptions (tests underspecify)
truncateprefers the word-boundary rule over maximising length (matches the asserted"hello..."result).sortByties rely on V8's stable sort (insertion order preserved for equal keys); no explicit tie-break added.Verification
bun test→ 60 pass, 0 failtsc --noEmit→ cleanFollow-up note
The
isEmail/isUrlregexes touch input validation. A security review of the email pattern for ReDoS characteristics would be reasonable before use on untrusted input at scale.