fix(utils): resolve failing tests and implement missing functionality - #297
Open
stooit wants to merge 1 commit into
Open
fix(utils): resolve failing tests and implement missing functionality#297stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- 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
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 across the utility library and implements the missing functions. All 60 tests now pass (was 44 pass / 16 fail);
tsc --noEmitis clean. No test files modified, no dependencies added.Changes
src/calculator.ts—dividenow throws on division by zero instead of silently returningInfinity.src/string-utils.tswordCountsplits on whitespace runs (/\s+/), fixing consecutive spaces (and tabs/newlines).truncateimplemented: returns input unchanged when withinmaxLength; otherwise truncates at a word boundary with"..."counting towardmaxLength. Whitespace-aware boundaries (tab/newline, for parity withwordCount), and the ellipsis contract is honoured down tomaxLength === 3.src/task-manager.ts— implementedremove(true/false on presence),update(partial title/description/priority), andsortBy(priorityhigh>medium>low,createdAtoldest-first,statusby lifecycle).sortBysorts a copy, preserving internal order.src/date-utils.ts—formatRelativeusesMath.round(notMath.floor), so 36h rounds to "2 days ago". Symmetric for future dates.src/validator.ts—isEmailaccepts long TLDs (e.g..museum) and matches subdomains explicitly (net stricter — now rejectsuser@example..com);isUrlaccepts URLs with a port (protocol allowlist retained as the actual control).Verification
bun test-> 60 pass, 0 failtsc --noEmit-> cleantruncate, ellipsis at smallmaxLength) were addressed.Assumptions
sortBy("status")has no test coverage; implemented as lifecycle order pending -> in_progress -> completed.isEmail/isUrlremain pragmatic format checks (regex / protocol allowlist), suitable as input-format hints rather than authoritative gates.