fix(utils): make all failing tests pass - #292
Open
stooit wants to merge 1 commit into
Open
Conversation
…dators - calculator: divide(x, 0) now throws instead of returning Infinity - string-utils: implement truncate (word-boundary + ellipsis budget); wordCount collapses consecutive whitespace - task-manager: implement remove/update/sortBy with correct return contracts and non-mutating sort - date-utils: fix day-bucket off-by-one via symmetric Math.round(abs) - validator: isEmail accepts subdomains/long TLDs; isUrl accepts 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 in the utility library. Test suite now: 60 pass / 0 fail (
bun test). No test files modified, no dependencies added — scope kept to exactly what the tests require.Changes
src/calculator.tsdivide(x, 0)now throws instead of returningInfinity(also catches-0).src/string-utils.tstruncate(word-boundary cut, ellipsis counts towardmaxLength, handles strings shorter than the ellipsis);wordCountnow collapses consecutive whitespace viasplit(/\s+/).src/task-manager.tsremove(returnstrue/false),update(explicit field allowlist,falseon unknown id), andsortBy(priorityhigh<medium<low,createdAtoldest-first; sorts a copy so the internal Map order is preserved).src/date-utils.tsMath.round(Math.abs(diffHours)/24)so 36h → "2 days ago", symmetric for past/future.src/validator.tsisEmailaccepts subdomains and long TLDs (e.g..museum) while still rejecting empty labels;isUrlaccepts URLs with ports (http://localhost:3000).Verification
bun test→ 60 pass / 0 failbunx tsc --noEmit→ cleanAssumptions & notes
truncatewith a negativemaxLength(no test covers it).TaskManager.update/sortBydo no runtime value validation of caller-suppliedpriority— fine for the typed API, but a follow-up if reached from untrusted input.isEmail/isUrlare syntax predicates, not security gates (no SSRF/length hardening added).sortBy("status")ordering (in_progress < pending < completed) is untested; chosen as a sensible "active work first" default.