Skip to content

fix(utils): resolve failing tests and implement missing functionality - #297

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2219-1787242334
Open

fix(utils): resolve failing tests and implement missing functionality#297
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2219-1787242334

Conversation

@stooit

@stooit stooit commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across the utility library and implements the missing functions. All 60 tests now pass (was 44 pass / 16 fail); tsc --noEmit is clean. No test files modified, no dependencies added.

Changes

  • src/calculator.tsdivide now throws on division by zero instead of silently returning Infinity.
  • src/string-utils.ts
    • wordCount splits on whitespace runs (/\s+/), fixing consecutive spaces (and tabs/newlines).
    • truncate implemented: returns input unchanged when within maxLength; otherwise truncates at a word boundary with "..." counting toward maxLength. Whitespace-aware boundaries (tab/newline, for parity with wordCount), and the ellipsis contract is honoured down to maxLength === 3.
  • src/task-manager.ts — implemented remove (true/false on presence), update (partial title/description/priority), and sortBy (priority high>medium>low, createdAt oldest-first, status by lifecycle). sortBy sorts a copy, preserving internal order.
  • src/date-utils.tsformatRelative uses Math.round (not Math.floor), so 36h rounds to "2 days ago". Symmetric for future dates.
  • src/validator.tsisEmail accepts long TLDs (e.g. .museum) and matches subdomains explicitly (net stricter — now rejects user@example..com); isUrl accepts URLs with a port (protocol allowlist retained as the actual control).

Verification

  • bun test -> 60 pass, 0 fail
  • tsc --noEmit -> clean
  • Reviewed: no blocking issues; the two consistency warnings raised in review (whitespace boundaries in truncate, ellipsis at small maxLength) were addressed.

Assumptions

  • sortBy("status") has no test coverage; implemented as lifecycle order pending -> in_progress -> completed.
  • isEmail/isUrl remain pragmatic format checks (regex / protocol allowlist), suitable as input-format hints rather than authoritative gates.

- calculator: divide now throws on division by zero instead of returning Infinity
- string-utils: wordCount splits on whitespace runs; implement truncate with
  whitespace-aware word-boundary and ellipsis counting toward maxLength
- task-manager: implement remove, update, and sortBy (priority/createdAt/status)
- date-utils: formatRelative uses Math.round so 36h rounds to 2 days
- validator: isEmail accepts long TLDs; isUrl accepts URLs with a port
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