From fdff5a710c3c033663170794f34b23ff8b8a7ca7 Mon Sep 17 00:00:00 2001 From: Tom Fleet Date: Sun, 12 Apr 2026 13:56:29 +0100 Subject: [PATCH] Add some optimisations and enhancements inspired by similar (#3) --- README.md | 4 + chardiff_test.go | 84 ++++++++++ chars.go | 46 ++++- diff.go | 204 ++++++++++++++++++++--- diff_test.go | 199 ++++++++++++++++++++++ render/render.go | 15 +- testdata/dups.txtar | 5 +- testdata/fuzz/FuzzLines/8ccd8f74dba0b4a9 | 3 + 8 files changed, 525 insertions(+), 35 deletions(-) create mode 100644 testdata/fuzz/FuzzLines/8ccd8f74dba0b4a9 diff --git a/README.md b/README.md index a661c30..563c9c5 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,10 @@ The core diff algorithm (`diff.go`) is derived from the Go standard library's Copyright 2022 The Go Authors. All rights reserved. Used under a [BSD-style license](https://github.com/golang/go/blob/master/LICENSE). +Several optimisations — including common prefix/suffix trimming, the disjoint +fast-path, and the `CharDiff` similarity ratio gate — were inspired by the +[`similar`](https://github.com/mitsuhiko/similar) Rust crate by Armin Ronacher. + ### Credits This package was created with [copier] and the [FollowTheProcess/go-template] project template. diff --git a/chardiff_test.go b/chardiff_test.go index 9fbd03b..540e15a 100644 --- a/chardiff_test.go +++ b/chardiff_test.go @@ -222,6 +222,62 @@ func TestCharDiffNotSameForDifferent(t *testing.T) { } } +// TestCharDiffSimilarityGate verifies that WithSimilarityThreshold suppresses +// intraline highlighting when the ratio of equal runes is below the threshold. +func TestCharDiffSimilarityGate(t *testing.T) { + tests := []struct { + name string + removed []byte + added []byte + threshold float64 + wantAllChanged bool // true = expect single whole-line Changed segment (fallback) + wantHasUnchanged bool // true = expect at least one unchanged (intraline) segment + }{ + { + // "func Foo() {" vs "type Bar struct {" share almost nothing. + // Default threshold 0.5 should suppress highlighting. + name: "dissimilar lines suppressed at default threshold", + removed: []byte("func Foo() {\n"), + added: []byte("type Bar struct {\n"), + threshold: 0.5, + wantAllChanged: true, + }, + { + // Same pair, but threshold=0 means always highlight. + name: "dissimilar lines highlighted at threshold=0", + removed: []byte("func Foo() {\n"), + added: []byte("type Bar struct {\n"), + threshold: 0.0, + wantHasUnchanged: true, // " {" is common + }, + { + // Highly similar lines should always produce intraline highlights. + name: "similar lines produce intraline highlighting", + removed: []byte("return fmt.Errorf(\"could not open file: %w\", err)\n"), + added: []byte("return fmt.Errorf(\"failed to read config: %w\", err)\n"), + threshold: 0.5, + wantHasUnchanged: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := diff.CharDiff(tt.removed, tt.added, diff.WithSimilarityThreshold(tt.threshold)) + + assertJoinInvariant(t, result, tt.removed, tt.added) + + if tt.wantAllChanged { + assertAllChangedExceptNL(t, result.Removed, "removed") + assertAllChangedExceptNL(t, result.Added, "added") + } + + if tt.wantHasUnchanged { + assertHasUnchanged(t, result.Removed) + } + }) + } +} + // BenchmarkCharDiff benchmarks the CharDiff function. func BenchmarkCharDiff(b *testing.B) { removed := []byte("the quick brown fox jumps over the lazy dog\n") @@ -304,6 +360,34 @@ func anyChanged(segs []diff.Segment) bool { return false } +// assertAllChangedExceptNL asserts that all segments are Changed=true, except for a +// trailing standalone newline segment which is always Changed=false (to prevent ANSI +// background colours from bleeding onto the next terminal line). +func assertAllChangedExceptNL(t *testing.T, segs []diff.Segment, side string) { + t.Helper() + + for i, seg := range segs { + isTrailingNL := len(seg.Text) == 1 && seg.Text[0] == '\n' + if !seg.Changed && !isTrailingNL { + t.Errorf("%s segment[%d] Changed=false, want whole-line fallback", side, i) + } + } +} + +// assertHasUnchanged asserts that at least one segment in segs has Changed=false, +// meaning intraline highlighting found common content. +func assertHasUnchanged(t *testing.T, segs []diff.Segment) { + t.Helper() + + for _, seg := range segs { + if !seg.Changed { + return + } + } + + t.Error("expected at least one unchanged segment for similar lines") +} + func joinSegments(segs []diff.Segment) string { var sb strings.Builder for _, s := range segs { diff --git a/chars.go b/chars.go index 4227390..b373850 100644 --- a/chars.go +++ b/chars.go @@ -33,10 +33,15 @@ type InlineChange struct { // is returned as a fallback. // - If either side exceeds 500 runes, a single whole-line Changed segment is // returned to avoid O(mn) cost on minified or generated content. +// - If the similarity ratio (2*equalRunes / totalRunes) is below the threshold +// set by [WithSimilarityThreshold] (default 0.5), a whole-line Changed segment +// is returned — intraline highlighting of very different lines is noisy. // // The concatenation of segment Text fields on each side always equals the // original input byte-for-byte. -func CharDiff(removed, added []byte) InlineChange { +func CharDiff(removed, added []byte, opts ...Option) InlineChange { + cfg := applyOptions(opts) + // Identical inputs: short-circuit before any UTF-8 handling. This also // covers identical invalid UTF-8, where fallback would wrongly return // Changed:true segments. @@ -80,6 +85,40 @@ func CharDiff(removed, added []byte) InlineChange { segs := lcsSegments(oldRunes, newRunes, len(removedCore), len(addedCore)) + // Similarity ratio gate: if the ratio of equal runes to total runes is below + // the threshold, intraline highlighting would be more noise than signal. + // Build the whole-line fallback using the stripped core slices so that + // reattachNL can place the trailing newline outside the Changed segment — + // a highlighted \n bleeds ANSI background colour onto the next terminal line. + totalRunes := len(oldRunes) + len(newRunes) + if totalRunes > 0 { + equalRunes := 0 + + for _, seg := range segs.removed { + if !seg.Changed { + equalRunes += utf8.RuneCount(seg.Text) + } + } + + ratio := float64(similarityRatioScale*equalRunes) / float64(totalRunes) + if ratio < cfg.similarityThreshold { + var rSegs []Segment + if len(removedCore) > 0 { + rSegs = []Segment{{Text: bytes.Clone(removedCore), Changed: true}} + } + + var aSegs []Segment + if len(addedCore) > 0 { + aSegs = []Segment{{Text: bytes.Clone(addedCore), Changed: true}} + } + + return InlineChange{ + Removed: reattachNL(rSegs, removedNL), + Added: reattachNL(aSegs, addedNL), + } + } + } + removedSegs := reattachNL(segs.removed, removedNL) addedSegs := reattachNL(segs.added, addedNL) @@ -200,6 +239,11 @@ func lcsSegments(old, newText []rune, rCap, aCap int) sides { return mergeSegments(ops, rCap, aCap) } +// similarityRatioScale is the multiplier used in the similarity ratio formula: +// ratio = 2*equalRunes / totalRunes. The factor of 2 ensures that two identical +// lines score 1.0 (each equal rune is counted once on each side). +const similarityRatioScale = 2 + // segmentInitCap is the initial capacity for segment slices in mergeSegments. // Most diff lines produce far fewer than 8 segments; this avoids the first // few re-allocations on typical input. diff --git a/diff.go b/diff.go index e6e4ea1..a324f28 100644 --- a/diff.go +++ b/diff.go @@ -70,12 +70,12 @@ type pair struct{ x, y int } // // The structured form is useful for custom rendering; for plain unified-diff // text output use [Diff]. -func Lines(oldName string, old []byte, newName string, newText []byte) []Line { +func Lines(oldName string, old []byte, newName string, newText []byte, opts ...Option) []Line { if bytes.Equal(old, newText) { return nil } - return computeLines(oldName, old, newName, newText) + return computeLines(oldName, old, newName, newText, applyOptions(opts)) } // Diff returns an anchored unified diff of old and newText as raw bytes. @@ -107,12 +107,13 @@ func Diff( old []byte, newName string, newText []byte, + opts ...Option, ) []byte { if bytes.Equal(old, newText) { return nil } - structured := computeLines(oldName, old, newName, newText) + structured := computeLines(oldName, old, newName, newText, applyOptions(opts)) var out bytes.Buffer @@ -137,30 +138,24 @@ func Diff( return out.Bytes() } -// computeLines computes structured diff lines for old and newText (assumed non-equal). -func computeLines(oldName string, old []byte, newName string, newText []byte) []Line { - x := splitLines(old) - y := splitLines(newText) - - var result []Line - - result = append(result, - Line{Kind: KindHeader, Content: fmt.Appendf(nil, "diff %s %s\n", oldName, newName)}, - Line{Kind: KindHeader, Content: fmt.Appendf(nil, "--- %s\n", oldName)}, - Line{Kind: KindHeader, Content: fmt.Appendf(nil, "+++ %s\n", newName)}, - ) - +// groupIntoHunks groups the unique-line match pairs returned by [tgs] into +// context-annotated diff Lines. +// pairs is the output of [tgs] (including sentinels). x and y are the full line +// slices. contextLines controls how many unchanged lines are shown around changes. +func groupIntoHunks(pairs []pair, x, y [][]byte, contextLines int) []Line { var ( - done pair - chunk pair - count pair - ctext []Line + done pair + chunk pair + count pair + ctext []Line + result []Line ) - const contextLines = 3 - - for _, m := range tgs(x, y) { - if m.x < done.x { + for _, m := range pairs { + // Guard both coordinates independently: after pair offsetting a pair can + // advance one axis past done while the other lags, producing a negative + // slice range in the done.x:start.x or done.y:start.y expressions below. + if m.x < done.x || m.y < done.y { continue } @@ -225,6 +220,119 @@ func computeLines(oldName string, old []byte, newName string, newText []byte) [] return result } +// trimResult is the output of trimPrefixSuffix. +type trimResult struct { + oldTrimmed [][]byte + newTrimmed [][]byte + prefix int + suffix int +} + +// isDisjoint reports whether old and new share no lines in common. +// It only performs the check when both slices have at least 512 lines; +// below that threshold [tgs] is fast enough that the overhead is not worthwhile. +func isDisjoint(old, newSlice [][]byte) bool { + if len(old) < 512 || len(newSlice) < 512 { + return false + } + + // Build a set from the shorter side to minimise allocations. + shorter, longer := old, newSlice + if len(old) > len(newSlice) { + shorter, longer = newSlice, old + } + + seen := make(map[string]struct{}, len(shorter)) + for _, s := range shorter { + seen[unsafe.String(unsafe.SliceData(s), len(s))] = struct{}{} + } + + for _, s := range longer { + if _, ok := seen[unsafe.String(unsafe.SliceData(s), len(s))]; ok { + return false + } + } + + return true +} + +// trimPrefixSuffix finds the longest common prefix and suffix of x and y and +// returns the middle "interesting" portion together with the strip counts. +// The trimmed slices are subslices of the originals — no allocation. +func trimPrefixSuffix(x, y [][]byte) trimResult { + prefix := 0 + for prefix < len(x) && prefix < len(y) && bytes.Equal(x[prefix], y[prefix]) { + prefix++ + } + + suffix := 0 + for suffix < len(x)-prefix && suffix < len(y)-prefix && + bytes.Equal(x[len(x)-1-suffix], y[len(y)-1-suffix]) { + suffix++ + } + + return trimResult{ + prefix: prefix, + oldTrimmed: x[prefix : len(x)-suffix], + newTrimmed: y[prefix : len(y)-suffix], + suffix: suffix, + } +} + +// computeLines computes structured diff lines for old and newText (assumed non-equal). +func computeLines(oldName string, old []byte, newName string, newText []byte, cfg config) []Line { + x := splitLines(old) + y := splitLines(newText) + + // diffHeaders is the number of fixed header lines prepended to every diff result: + // "diff …", "--- …", and "+++ …". + const diffHeaders = 3 + + headers := []Line{ + {Kind: KindHeader, Content: fmt.Appendf(nil, "diff %s %s\n", oldName, newName)}, + {Kind: KindHeader, Content: fmt.Appendf(nil, "--- %s\n", oldName)}, + {Kind: KindHeader, Content: fmt.Appendf(nil, "+++ %s\n", newName)}, + } + + tr := trimPrefixSuffix(x, y) + + if isDisjoint(tr.oldTrimmed, tr.newTrimmed) { + // Fast-path: no common lines — emit one hunk with all removals then all additions. + result := make([]Line, 0, diffHeaders+1+len(tr.oldTrimmed)+len(tr.newTrimmed)) + result = append(result, headers...) + + result = append(result, chunkHeader( + pair{tr.prefix, tr.prefix}, + pair{len(tr.oldTrimmed), len(tr.newTrimmed)}, + )) + for _, s := range tr.oldTrimmed { + result = append(result, Line{Kind: KindRemoved, Content: s}) + } + + for _, s := range tr.newTrimmed { + result = append(result, Line{Kind: KindAdded, Content: s}) + } + + return result + } + + // Run TGS on the trimmed middle only, then offset the returned pairs back + // into full-array coordinates so groupIntoHunks draws context from the + // correct positions (including up to contextLines lines from the prefix). + pairs := tgs(tr.oldTrimmed, tr.newTrimmed) + for i := range pairs { + pairs[i].x += tr.prefix + pairs[i].y += tr.prefix + } + + hunks := groupIntoHunks(pairs, x, y, cfg.contextLines) + result := make([]Line, 0, diffHeaders+len(hunks)) + result = append(result, headers...) + result = append(result, hunks...) + + return result +} + // expandMatch expands a match region backward to start and forward to end // while adjacent lines in x and y also match. func expandMatch(m, done pair, x, y [][]byte) (start, end pair) { @@ -288,6 +396,54 @@ func splitLines(x []byte) [][]byte { return lines } +const ( + // defaultContextLines is the default number of unchanged context lines shown around each change. + defaultContextLines = 3 + + // defaultSimilarityThreshold is the default minimum similarity ratio for intraline highlighting. + defaultSimilarityThreshold = 0.5 +) + +// config holds resolved options for a diff operation. +type config struct { + contextLines int + similarityThreshold float64 +} + +// defaultConfig returns a config with package defaults. +func defaultConfig() config { + return config{ + contextLines: defaultContextLines, + similarityThreshold: defaultSimilarityThreshold, + } +} + +// Option is a functional option that configures a diff operation. +type Option func(*config) + +// WithContext sets the number of unchanged context lines shown around each change. +// The default is 3. Pass 0 to suppress context entirely. +func WithContext(n int) Option { + return func(c *config) { c.contextLines = n } +} + +// WithSimilarityThreshold sets the minimum similarity ratio for intraline highlighting. +// ratio = 2*equalRunes / (len(removedRunes) + len(addedRunes)). +// Default is 0.5. Use 0.0 to always highlight; 1.0 to never highlight. +func WithSimilarityThreshold(t float64) Option { + return func(c *config) { c.similarityThreshold = t } +} + +// applyOptions builds a config from defaults and the provided options. +func applyOptions(opts []Option) config { + cfg := defaultConfig() + for _, o := range opts { + o(&cfg) + } + + return cfg +} + // tgsYStep is the per-occurrence decrement applied to y-side entries in the // tgs occurrence map. It is 4× the x-side step (1) so that x and y counts // occupy separate bit ranges, allowing a unique line to be identified by the diff --git a/diff_test.go b/diff_test.go index 3f53df7..c2fa077 100644 --- a/diff_test.go +++ b/diff_test.go @@ -2,8 +2,10 @@ package diff_test import ( "bytes" + "fmt" "os" "path/filepath" + "strings" "testing" "go.followtheprocess.codes/diff" @@ -233,6 +235,203 @@ func BenchmarkDiff(b *testing.B) { } } +// TestWithContextOption verifies WithContext is accepted and the default (3) is unchanged. +func TestWithContextOption(t *testing.T) { + tests := []struct { + name string + old []byte + newText []byte + opts []diff.Option + wantLen int // expected number of Lines returned + }{ + { + // Default context=3: 3 headers + 1 @@ + 2 context (a, b) + 1 removed + 1 added = 8 + name: "default context unchanged", + old: []byte("a\nb\nc\n"), + newText: []byte("a\nb\nd\n"), + opts: nil, + wantLen: 8, + }, + { + // WithContext(0): 3 headers + 1 @@ + 1 removed + 1 added = 6 + name: "WithContext(0) suppresses context lines", + old: []byte("a\nb\nc\n"), + newText: []byte("a\nb\nd\n"), + opts: []diff.Option{diff.WithContext(0)}, + wantLen: 6, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := diff.Lines("old", tt.old, "new", tt.newText, tt.opts...) + if len(got) != tt.wantLen { + t.Fatalf("Lines() returned %d lines, want %d\n%#v", len(got), tt.wantLen, got) + } + }) + } +} + +// TestGroupIntoHunksViaWithContext verifies the extracted groupIntoHunks function +// respects the contextLines setting via the WithContext option. +func TestGroupIntoHunksViaWithContext(t *testing.T) { + tests := []struct { + opt diff.Option + name string + old []byte + new []byte + wantContext int + }{ + { + name: "default 3 context lines", + old: []byte("a\nb\nc\nd\ne\nf\ng\n"), + new: []byte("a\nb\nc\nX\ne\nf\ng\n"), + opt: diff.WithContext(3), + wantContext: 6, // 3 before + 3 after the change + }, + { + name: "zero context lines", + old: []byte("a\nb\nc\nd\ne\nf\ng\n"), + new: []byte("a\nb\nc\nX\ne\nf\ng\n"), + opt: diff.WithContext(0), + wantContext: 0, + }, + { + name: "one context line", + old: []byte("a\nb\nc\nd\ne\nf\ng\n"), + new: []byte("a\nb\nc\nX\ne\nf\ng\n"), + opt: diff.WithContext(1), + wantContext: 2, // 1 before + 1 after + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + lines := diff.Lines("old", tt.old, "new", tt.new, tt.opt) + + contextCount := 0 + + for _, l := range lines { + if l.Kind == diff.KindContext { + contextCount++ + } + } + + if contextCount != tt.wantContext { + t.Fatalf("got %d KindContext lines, want %d\n%#v", contextCount, tt.wantContext, lines) + } + }) + } +} + +// TestLargeCommonRegionsProduceCorrectLineNumbers verifies that inputs with large +// common regions produce correct line numbers and only show contextLines of context +// (not the whole prefix). +func TestLargeCommonRegionsProduceCorrectLineNumbers(t *testing.T) { + tests := []struct { + name string + old string + new string + wantHunk string + wantContext int + }{ + { + // 100-line common prefix, then 1 changed line. + // Hunk shows lines 98–101 (3 context + 1 change = 4 lines each side). + name: "large common prefix — correct line numbers", + old: strings.Repeat("line\n", 100) + "old content\n", + new: strings.Repeat("line\n", 100) + "new content\n", + wantContext: 3, + wantHunk: "@@ -98,4 +98,4 @@", + }, + { + // 1 changed line at the start, then 100-line common suffix. + name: "large common suffix — correct line numbers", + old: "old content\n" + strings.Repeat("line\n", 100), + new: "new content\n" + strings.Repeat("line\n", 100), + wantContext: 3, + wantHunk: "@@ -1,4 +1,4 @@", + }, + { + // 50 common prefix + 1 change + 50 common suffix. + name: "common prefix and suffix", + old: strings.Repeat("line\n", 50) + "old\n" + strings.Repeat("line\n", 50), + new: strings.Repeat("line\n", 50) + "new\n" + strings.Repeat("line\n", 50), + wantContext: 6, // 3 before + 3 after + wantHunk: "@@ -48,7 +48,7 @@", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + lines := diff.Lines("old", []byte(tt.old), "new", []byte(tt.new)) + + contextCount := 0 + + var hunkHeader string + + for _, l := range lines { + if l.Kind == diff.KindContext { + contextCount++ + } + + if l.Kind == diff.KindHeader && len(l.Content) > 2 && l.Content[0] == '@' { + hunkHeader = strings.TrimSuffix(string(l.Content), "\n") + } + } + + if contextCount != tt.wantContext { + t.Errorf("context line count = %d, want %d", contextCount, tt.wantContext) + } + + if hunkHeader != tt.wantHunk { + t.Errorf("hunk header = %q, want %q", hunkHeader, tt.wantHunk) + } + }) + } +} + +// TestDisjointFastPath verifies that large fully-disjoint inputs produce the +// correct all-removed / all-added diff output (same as the normal TGS path). +func TestDisjointFastPath(t *testing.T) { + // Build two 512-line files with no lines in common. + var oldLines, newLines strings.Builder + for i := range 512 { + fmt.Fprintf(&oldLines, "old line %d\n", i) + fmt.Fprintf(&newLines, "new line %d\n", i) + } + + old := []byte(oldLines.String()) + newText := []byte(newLines.String()) + + lines := diff.Lines("old", old, "new", newText) + if lines == nil { + t.Fatal("Lines() returned nil for non-equal inputs") + } + + removed := 0 + added := 0 + + for _, l := range lines { + switch l.Kind { + case diff.KindRemoved: + removed++ + case diff.KindAdded: + added++ + default: + // KindHeader and KindContext lines are not counted + } + } + + if removed != 512 { + t.Errorf("removed line count = %d, want 512", removed) + } + + if added != 512 { + t.Errorf("added line count = %d, want 512", added) + } +} + func clean(text []byte) []byte { text = bytes.ReplaceAll(text, []byte("$\n"), []byte("\n")) text = bytes.TrimSuffix(text, []byte("^D\n")) diff --git a/render/render.go b/render/render.go index d37c0fe..091fe14 100644 --- a/render/render.go +++ b/render/render.go @@ -26,7 +26,8 @@ var ( ) // Render formats a []diff.Line as a colourised byte slice suitable for terminal output. -// Returns nil if lines is nil or empty. +// Returns nil if lines is nil or empty. Options are forwarded to [diff.CharDiff] and +// control intraline highlighting behaviour (e.g. [diff.WithSimilarityThreshold]). // // Colour scheme: // - "diff …" and "@@ … @@" header lines are bold with no colour. @@ -36,7 +37,7 @@ var ( // of added lines, each pair is diffed at the character level via [diff.CharDiff] // and changed characters are highlighted with a coloured background. // - Otherwise whole-line colour is applied with no character-level highlighting. -func Render(lines []diff.Line) []byte { +func Render(lines []diff.Line, opts ...diff.Option) []byte { if len(lines) == 0 { return nil } @@ -57,7 +58,7 @@ func Render(lines []diff.Line) []byte { i++ case diff.KindRemoved: - buf, i = appendRemovedBlock(buf, lines, i) + buf, i = appendRemovedBlock(buf, lines, i, opts) case diff.KindAdded: buf, i = appendAddedBlock(buf, lines, i) @@ -93,7 +94,7 @@ func appendContext(buf []byte, line diff.Line) []byte { // appendRemovedBlock collects a consecutive run of removed lines and any immediately // following added lines starting at index i, renders them, and returns the updated buf and index. -func appendRemovedBlock(buf []byte, lines []diff.Line, i int) ([]byte, int) { +func appendRemovedBlock(buf []byte, lines []diff.Line, i int, opts []diff.Option) ([]byte, int) { start := i for i < len(lines) && lines[i].Kind == diff.KindRemoved { i++ @@ -108,7 +109,7 @@ func appendRemovedBlock(buf []byte, lines []diff.Line, i int) ([]byte, int) { added := lines[removedEnd:i] if len(removed) == len(added) { - return renderInlinePairs(buf, removed, added), i + return renderInlinePairs(buf, removed, added, opts), i } return renderWholeLine(buf, removed, added), i @@ -126,9 +127,9 @@ func appendAddedBlock(buf []byte, lines []diff.Line, i int) ([]byte, int) { } // renderInlinePairs renders 1:1 paired removed/added lines with character-level inline diff. -func renderInlinePairs(buf []byte, removed, added []diff.Line) []byte { +func renderInlinePairs(buf []byte, removed, added []diff.Line, opts []diff.Option) []byte { for k := range removed { - ic := diff.CharDiff(removed[k].Content, added[k].Content) + ic := diff.CharDiff(removed[k].Content, added[k].Content, opts...) buf = styleRemovedLine.AppendText(buf, prefixRemoved) diff --git a/testdata/dups.txtar b/testdata/dups.txtar index f69f6ac..5724f01 100644 --- a/testdata/dups.txtar +++ b/testdata/dups.txtar @@ -30,10 +30,9 @@ diff old new a $ - b -- -- c + B -+ + $ +- c + C $ d diff --git a/testdata/fuzz/FuzzLines/8ccd8f74dba0b4a9 b/testdata/fuzz/FuzzLines/8ccd8f74dba0b4a9 new file mode 100644 index 0000000..2ebf8e1 --- /dev/null +++ b/testdata/fuzz/FuzzLines/8ccd8f74dba0b4a9 @@ -0,0 +1,3 @@ +go test fuzz v1 +[]byte("0\n\n\n\n0") +[]byte("\n0\n\n0") -- knotmirror 0.0.1