fix: implement missing utils and correct 5 logic bugs - #290
Open
stooit wants to merge 1 commit into
Open
Conversation
Implements truncate and TaskManager.remove/update/sortBy, and fixes wordCount whitespace handling, formatRelative day rounding, isEmail TLD length, isUrl port acceptance, and divide-by-zero handling. Makes all 60 tests pass (was 44 pass / 16 fail). Only source files changed; no test files or dependencies modified.
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 5 source files.
bun testnow reports 60 pass / 0 fail (was 44 pass / 16 fail), andtsc --noEmitis clean. No test files or dependencies were modified.Changes
src/calculator.ts—dividenow throws on division by zero (also covers-0) instead of returningInfinity.src/date-utils.ts—formatRelativeday calc usesMath.round(Math.abs(diffHours) / 24), fixing the off-by-one so 36h reports "2 days ago" (past and future symmetric).src/validator.ts—isEmailTLD quantifier widened{2,4}→{2,}(accepts long TLDs like.museum);isUrldrops the empty-port requirement sohttp://localhost:3000validates, while keeping the protocol allow-list.src/string-utils.ts—wordCountusestrim().split(/\s+/)for consecutive spaces;truncateimplemented with ellipsis counted towardmaxLengthand word-boundary cutting.src/task-manager.ts— implementedremove(returns boolean),update(guarded key-wise assignment, returns boolean), andsortBy(priority and createdAt ordering on a sorted copy, preserving insertion order via stable sort).Verification
bun test→ 60 pass / 0 failtsc --noEmit→ exit 0Assumptions / notes
maxLength, clearing an optionaldescription,sortBywith an unrecognised field) — left out of scope as no test exercises them and the task said to fix only what tests require.isUrlis a format validator, not an SSRF guard — documented in its docstring.