jesseduffield.lazygit/pkg/gui/mergeconflicts/state_test.go
Stefan Haller bc9fafff02 Make the conflict marker size a parameter of our marker matching
Git doesn't always write conflict markers of seven characters: the
conflict-marker-size gitattribute overrides that per file, and it is set
for good reasons — for file types whose regular content tends to contain
marker-looking lines, such as documentation about merging, or test
scripts. We hard-code seven characters everywhere we look for markers,
so none of that works.

Prepare for honoring the attribute by threading the marker size through
everything that recognizes a marker, carried on the file model. Nothing
fills it in yet, so we still use git's default size of seven everywhere,
and matching is unchanged: a marker consists of exactly that many marker
characters, and all but the "=======" one are followed by a space and a
label.
2026-08-08 12:43:42 +02:00

123 lines
1.6 KiB
Go

package mergeconflicts
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFindConflicts(t *testing.T) {
type scenario struct {
name string
content string
expected []*mergeConflict
}
scenarios := []scenario{
{
name: "empty",
content: "",
expected: []*mergeConflict{},
},
{
name: "various conflicts",
content: `++<<<<<<< HEAD
foo
++=======
bar
++>>>>>>> branch
<<<<<<< HEAD: foo/bar/baz.go
foo
bar
=======
baz
>>>>>>> branch
++<<<<<<< MERGE_HEAD
foo
++=======
bar
++>>>>>>> branch
++<<<<<<< Updated upstream
foo
++=======
bar
++>>>>>>> branch
++<<<<<<< ours
foo
++=======
bar
++>>>>>>> branch
<<<<<<< Updated upstream: foo/bar/baz.go
foo
bar
=======
baz
>>>>>>> branch
<<<<<<< HEAD
foo
||||||| fffffff
bar
=======
baz
>>>>>>> branch
`,
expected: []*mergeConflict{
{
start: 0,
ancestor: -1,
target: 2,
end: 4,
},
{
start: 6,
ancestor: -1,
target: 9,
end: 11,
},
{
start: 13,
ancestor: -1,
target: 15,
end: 17,
},
{
start: 19,
ancestor: -1,
target: 21,
end: 23,
},
{
start: 25,
ancestor: -1,
target: 27,
end: 29,
},
{
start: 31,
ancestor: -1,
target: 34,
end: 36,
},
{
start: 38,
ancestor: 40,
target: 42,
end: 44,
},
},
},
}
for _, s := range scenarios {
t.Run(s.name, func(t *testing.T) {
assert.EqualValues(t, s.expected, findConflicts(s.content, defaultConflictMarkerSize))
})
}
}