Skip to content

fix: implement missing utilities and fix edge-case bugs - #331

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2172-1788944354
Open

fix: implement missing utilities and fix edge-case bugs#331
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2172-1788944354

Conversation

@stooit

@stooit stooit commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests (now 60 pass / 0 fail) by implementing missing functionality and correcting edge-case bugs across the utility library. No test files were modified and no dependencies were added.

Fixes

  • src/calculator.tsdivide returned Infinity for a zero divisor; now throws Error("Division by zero") (fail-closed on invalid input).
  • src/string-utils.ts
    • truncate — implemented: returns unchanged when str.length <= maxLength, otherwise reserves 3 chars for "...", backtracks to the last word boundary, trims trailing whitespace, and appends the ellipsis. Guards maxLength <= 3 so the result never exceeds maxLength.
    • wordCount — was split(" ") (counted empty strings from consecutive spaces). Now trims and splits on /\s+/, also handling tabs/newlines.
  • src/date-utils.tsformatRelative used Math.floor(diffHours / 24), so 12h–47h all rendered "1 day ago". Switched to Math.round; 36h now yields "2 days ago".
  • src/validator.ts
    • isEmail — regex rejected long TLDs (e.g. .museum); replaced with a pattern allowing dot-separated labels and a 2+ letter TLD.
    • isUrl — removed the port === "" clause that rejected URLs carrying an explicit port; scheme allowlist (http/https) remains the control.
  • src/task-manager.ts — implemented remove (delegates to Map.delete), update (returns false for unknown id; applies only present keys), and sortBy (priority/status rank maps + numeric createdAt comparator).

Testing

bun test60 pass / 0 fail.

Assumptions / notes

  • Behaviour for each fix follows the TODO comments and test expectations in the source.
  • sortBy/list hand out references to the live Task objects (no defensive copy). Tests don't exercise mutation of stored state, so this was left as-is, but worth noting if consumed across trust boundaries.

- calculator: divide now throws on zero divisor instead of returning Infinity
- string-utils: implement truncate (word-boundary + ellipsis); fix wordCount for consecutive whitespace
- date-utils: fix off-by-one in formatRelative day rounding
- validator: fix isEmail long-TLD rejection and isUrl explicit-port rejection
- task-manager: implement remove, update, and sortBy

All 60 tests pass.
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