Skip to content

fix: implement missing utility functions and fix edge-case bugs - #296

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2102-1787155850
Open

fix: implement missing utility functions and fix edge-case bugs#296
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2102-1787155850

Conversation

@stooit

@stooit stooit commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 previously-failing tests across the utility library. All 60 tests now pass (0 fail); tsc --noEmit is clean. No test files were modified and no dependencies were added.

Changes

  • src/calculator.tsdivide now throws on division by zero instead of returning Infinity.
  • src/string-utils.ts
    • wordCount — trims and splits on \s+, collapsing consecutive/leading/trailing whitespace ("hello world" → 2).
    • truncate — implemented: returns unchanged when str.length <= maxLength; otherwise reserves 3 chars for "...", backs up to the last word boundary, and appends the ellipsis (ellipsis counts toward maxLength).
  • src/task-manager.ts — implemented remove (Map delete → true/false), update (partial title/description/priority, false if not found), and sortBy (priority high>medium>low, status, createdAt oldest-first). Sort copies the values before sorting, so internal order is untouched.
  • src/date-utils.tsformatRelative day diff uses Math.round instead of Math.floor, so 36 hours renders as "2 days ago".
  • src/validator.tsisEmail accepts long TLDs (e.g. .museum) and subdomains; isUrl accepts URLs with ports (e.g. http://localhost:3000) by validating on protocol only.

Verification

  • bun test60 pass, 0 fail, 70 expect() calls.
  • tsc --noEmit exits 0.
  • A review pass empirically confirmed the truncate length invariant across edge cases and ruled out ReDoS in the new email regex.

Notes / assumptions

  • update(id, { description: undefined }) intentionally no-ops rather than clearing the field — no test covers clearing, and scope was to fix only what tests require.
  • Left untouched: a pre-existing hours/minutes boundary artefact in formatRelative that predates this change and is outside the failing-test scope.

- calculator: divide now throws on division by zero instead of returning Infinity
- string-utils: wordCount collapses consecutive/leading/trailing whitespace; implement truncate at word boundary with ellipsis counting toward maxLength
- task-manager: implement remove, update, and sortBy (priority/createdAt/status)
- date-utils: formatRelative uses Math.round for day diff (36h -> 2 days ago)
- validator: isEmail accepts long TLDs; isUrl accepts URLs with ports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant