diff options
author | Harrison Jones <harrison@hhj.me> | 2021-05-20 12:51:26 -0400 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-05-30 13:50:42 +1000 |
commit | e478c254d43495ecfa2dad55df1ca2d2726ff974 (patch) | |
tree | a5cadd2fa543dd5b4f94474bbbeff14e998139c5 /pkg/gui/mergeconflicts/state_test.go | |
parent | 44f7fc6f7c03a8eeb18e22f3605a384516b31baa (diff) |
Handle alternate merge conflict format; add tests
Diffstat (limited to 'pkg/gui/mergeconflicts/state_test.go')
-rw-r--r-- | pkg/gui/mergeconflicts/state_test.go | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/pkg/gui/mergeconflicts/state_test.go b/pkg/gui/mergeconflicts/state_test.go new file mode 100644 index 000000000..df2e077b4 --- /dev/null +++ b/pkg/gui/mergeconflicts/state_test.go @@ -0,0 +1,90 @@ +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 +`, + expected: []*mergeConflict{ + { + start: 0, + middle: 2, + end: 4, + }, + { + start: 6, + middle: 9, + end: 11, + }, + { + start: 13, + middle: 15, + end: 17, + }, + { + start: 19, + middle: 21, + end: 23, + }, + { + start: 25, + middle: 27, + end: 29, + }, + }, + }, + } + + for _, s := range scenarios { + t.Run(s.name, func(t *testing.T) { + assert.EqualValues(t, s.expected, findConflicts(s.content)) + }) + } +} |