summaryrefslogtreecommitdiffstats
path: root/pkg/gui/mergeconflicts/state_test.go
blob: 442265fb6cd308f4f1e5f6571dd9cd63a480979b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
`,
			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,
				},
				{
					start:  31,
					middle: 34,
					end:    36,
				},
			},
		},
	}

	for _, s := range scenarios {
		t.Run(s.name, func(t *testing.T) {
			assert.EqualValues(t, s.expected, findConflicts(s.content))
		})
	}
}