Skip to content

Add str/prn, line-diff, char-diff, and unified-diff#6

Closed
carpentry-agent[bot] wants to merge 1 commit into
masterfrom
claude/line-diff-unified
Closed

Add str/prn, line-diff, char-diff, and unified-diff#6
carpentry-agent[bot] wants to merge 1 commit into
masterfrom
claude/line-diff-unified

Conversation

@carpentry-agent
Copy link
Copy Markdown

Summary

Adds several features to make the diff library more complete and practical:

  • str / prn — explicit interface implementations for the Diff type, so diff values display cleanly in output and test failures
  • line-diff — diffs two strings line by line (the most common use case for text diffing)
  • char-diff — diffs two strings character by character
  • unified-diff — renders a line diff in standard unified-diff format with proper @@ -a,b +a,b @@ hunk headers, 3 lines of context, and automatic hunk splitting when changes are far apart

The unified-diff output follows the standard convention: deletions (-) before insertions (+), context lines prefixed with space. The diff algorithm naturally produces insertions before deletions, so a reordering step normalizes this for output.

What changed

diff.carp

  • str and prn with implements declarations
  • line-diff and char-diff convenience wrappers
  • reorder-changes (private) — normalizes Insertion/Deletion ordering within change groups
  • render-hunk-header (private) — formats @@ hunk headers
  • unified-diff — full unified-diff rendering with hunk splitting

tests/diff.carp

  • 15 new tests covering str, prn, line-diff, char-diff, and unified-diff (including edge cases: identical strings, change at start/end, pure insertions/deletions, completely different content, multi-hunk output)

Testing

All 28 tests pass (13 existing + 15 new). Formatted with carp-fmt, clean angler output.


Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.

@carpentry-agent
Copy link
Copy Markdown
Author

Closing: duplicate of #5. Both PRs were opened in the same heartbeat cycle due to a race condition where two background sessions read the same topic file. PR #5 covers the same work (line-diff, char-diff, unified rendering).

@carpentry-agent carpentry-agent Bot closed this Jun 2, 2026
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.

0 participants