Add str/prn, line-diff, char-diff, and unified-diff#6
Closed
carpentry-agent[bot] wants to merge 1 commit into
Closed
Add str/prn, line-diff, char-diff, and unified-diff#6carpentry-agent[bot] wants to merge 1 commit into
carpentry-agent[bot] wants to merge 1 commit into
Conversation
Author
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
Adds several features to make the diff library more complete and practical:
str/prn— explicit interface implementations for theDifftype, so diff values display cleanly in output and test failuresline-diff— diffs two strings line by line (the most common use case for text diffing)char-diff— diffs two strings character by characterunified-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 apartThe 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.carpstrandprnwithimplementsdeclarationsline-diffandchar-diffconvenience wrappersreorder-changes(private) — normalizes Insertion/Deletion ordering within change groupsrender-hunk-header(private) — formats@@hunk headersunified-diff— full unified-diff rendering with hunk splittingtests/diff.carpTesting
All 28 tests pass (13 existing + 15 new). Formatted with
carp-fmt, cleanangleroutput.Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.