fix: resolve failing tests across utility library - #321
Open
stooit wants to merge 1 commit into
Open
Conversation
…on utils - calculator.divide: throw on division by zero instead of returning Infinity - string-utils.wordCount: split on whitespace runs so consecutive spaces don't inflate count - string-utils.truncate: implement word-boundary truncation with ellipsis counting toward maxLength - date-utils.diffDays: fix off-by-one by rounding hours/24 (and correct future-date branch) - task-manager: implement/complete remove, update, and sortBy - validator.isEmail: support multi-level subdomains and longer TLDs, reject empty labels - validator.isUrl: accept URLs with explicit ports (e.g. localhost:3000)
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 the utility library. The suite now reports 60 pass / 0 fail, with
npx tsc --noEmitclean. No test files were modified and no dependencies were added.Changes by file
dividethrowsError("Division by zero")when the divisor is0instead of silently returningInfinity.wordCount— trims then splits on/\s+/so runs of whitespace no longer inflate the count ("hello world"→ 2). Also handles tabs/newlines.truncate— implemented: returns the string unchanged whenstr.length <= maxLength; otherwise truncates at a word boundary, reserving 3 chars for"..."so the ellipsis counts towardmaxLength. Falls back to a hard slice whenmaxLength <= 3so the result never exceedsmaxLength.diffDaysusesMath.round(Math.abs(hours)/24)to fix the off-by-one (36h now → "2 days ago"), and corrects a latent bug on the future-date branch.remove(returns whether a task existed),update(applies only supplied keys, returnsfalsefor a missing id), andsortBy(priority, status, andcreatedAtordering).isEmail— supports multi-level subdomains and longer TLDs, and rejects empty/consecutive-dot labels.isUrl— accepts URLs with explicit ports (e.g.http://localhost:3000) while still allowlistinghttp/https.Testing
bun test→ 60 pass, 0 failnpx tsc --noEmit→ exit 0Assumptions
truncateguarantees its return value never exceedsmaxLength, hard-slicing when there is no room for a word plus ellipsis.updatetreats an omitted field as "leave unchanged" and only allows explicitly clearing the optionaldescription.Note
isEmailis a syntactic check only — if used to gate account creation, pair it with a confirmation-link verification step.