/
parse_test.go
63 lines (54 loc) · 1.37 KB
/
parse_test.go
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
package conflict
import (
"os/exec"
"reflect"
"testing"
)
func TestParseGitInfo(t *testing.T) {
for _, test := range tests {
output := []int{}
for _, line := range test.diffCheck {
_, lineNum, ok := parseGitMarkerInfo(line)
if ok != nil {
continue
}
output = append(output, lineNum)
}
if !(reflect.DeepEqual(output, test.markers)) && test.parsable {
t.Errorf("parseGitInfo failed: got %v, want %v", output, test.markers)
}
}
}
func TestParseConflictsIn(t *testing.T) {
for _, test := range tests {
f := File{AbsolutePath: test.path}
if err := f.Read(); err != nil && test.highlightable {
t.Error("ParseConflicts/Read failed")
}
_, err := parseConflictsIn(f, test.markers)
if err != nil && test.parsable {
t.Errorf("parseConflicts failed: %s", err.Error())
}
}
}
func TestFind(t *testing.T) {
execCommand = mockExecCommand
defer func() { execCommand = exec.Command }()
files, err := Find(".")
if err != nil {
t.Errorf("Find failed: %s", err.Error())
}
if len(files) != 3 {
t.Errorf("Find failed: got %d files, want 3", len(files))
}
for _, f := range files {
for _, test := range tests {
if f.AbsolutePath == test.path && test.parsable {
if len(f.Conflicts) != test.numConflicts {
t.Errorf("Find failed: got %d conflicts in %s, want %d",
len(f.Conflicts), test.path, test.numConflicts)
}
}
}
}
}