fix: implement missing utils functions and fix edge-case bugs - #325
Open
stooit wants to merge 1 commit into
Open
fix: implement missing utils functions and fix edge-case bugs#325stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
Fix all 16 failing tests (60/60 now pass) without modifying tests or adding dependencies: - calculator: divide now throws on division by zero instead of silently returning Infinity/NaN - string-utils: wordCount splits on /\s+/ (handles consecutive spaces, tabs, newlines); implement truncate at word boundary with ellipsis counted toward maxLength - task-manager: implement remove/update (partial, returns false on unknown id) and sortBy (priority high>medium>low, createdAt oldest first, status workflow order) - date-utils: formatRelative uses Math.round(abs(hours)/24) to fix the off-by-one at exactly 36 hours - validator: isEmail allows TLDs of length >=2; isUrl accepts URLs with an explicit port while still rejecting non-http(s) protocols - docs: remove stale BUG comments now that the defects are fixed
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 in the utility library — 60/60 now pass (was 44/60). No test files modified, no dependencies added; scope limited to what the tests require.
Fixes by file
src/calculator.ts—dividenow throwsError("Division by zero")when the divisor is0(also covers-0), instead of silently returningInfinity/NaN.src/string-utils.tswordCountsplits on/\s+/against the trimmed string, correctly handling consecutive spaces, tabs, and newlines.truncateimplemented: returns unchanged whenstr.length <= maxLength; otherwise truncates at a word boundary with"..."counted towardmaxLength.src/task-manager.ts— implementedremove(returnsfalsefor unknown id),update(partial update via!== undefinedchecks; returnsfalsefor unknown id), andsortBy(priorityhigh>medium>low,createdAtoldest first,statusin workflow order).src/date-utils.ts—formatRelativeday bucket usesMath.round(Math.abs(diffHours) / 24), fixing the off-by-one at exactly 36 hours (now "2 days ago") while keeping past/future symmetric.src/validator.ts—isEmailallows TLDs of length >= 2 ({2,});isUrlaccepts URLs with an explicit port while still rejecting non-http(s) protocols.BUG:comments indate-utils.tsandvalidator.tsthat described the now-fixed defects.Testing
bun test-> 60 pass, 0 fail.tsc --noEmitclean.Assumptions / notes
truncatewith negative/NaNmaxLength;truncatewhen the budget window is all whitespace;updateclearing an optional field via explicitundefined. These are unguarded edge cases in newly-written code with no prior contract; flagging for a future hardening pass rather than expanding scope here.sortBy("createdAt")relies on stable sort + insertion order for same-millisecond ties (correct, but the test doesn't genuinely exercise timestamp comparison).🤖 Generated with QuantCode Agent