Tags: 0xd219b/go-difflib
Tags
fix(difflib): improve unified diff context and display format Correct the behavior of unified diff to match git diff format: 1. Add "a/" and "b/" prefix to source and target file paths 2. Fix the context line in diff header to show the line before the change 3. Add byte-by-byte comparison helper for testing The @@ line context in unified diff headers now correctly shows the line preceding the first changed line, matching git diff behavior: - Before: Random or incorrect context line - After: Context from the line before the first change Examples: @@ -4,4 +4,5 @@ import "fmt" Shows that "import "fmt"" is the line before line 4 Added detailed testing utilities: - compareByteByByte function for exact diff comparison - Byte value display in decimal and ASCII - Context display around differences - Hex dump of the differing sections Signed-off-by: Chen Bojun <bojun.cbj@alibaba-inc.com>
feat(difflib): add context preview to unified diff headers Similar to git diff output, add context preview text after @@ headers in unified diff output to help identify the location of changes. The context is taken from the first line of the change block. Changes: - Add context preview extraction in WriteUnifiedDiff - Truncate long context lines (>40 chars) with ellipsis - Add comprehensive tests for context preview functionality Example output: - Before: @@ -1,5 +1,4 @@ - After: @@ -1,5 +1,4 @@ class Example: This makes unified diffs more readable by providing context about where the changes occur, matching the behavior of git diff and other modern diff tools. Test cases cover both basic context preview and long line truncation scenarios. Signed-off-by: Chen Bojun <bojun.cbj@alibaba-inc.com>