-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge_test.go
66 lines (54 loc) · 1.37 KB
/
merge_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
64
65
66
package go_three_way_merge
import (
"testing"
)
func expectSuccessfulMerge(t *testing.T, err error, ok bool) {
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
if !ok {
t.Fatal("Expected no merge conflict")
}
}
func TestNoMergeRequired(t *testing.T) {
text := "Hello World!"
result, ok, err := Merge(text, text, text)
expectSuccessfulMerge(t, err, ok)
if result != text {
t.Errorf("Expected %s, got %s.", text, result)
}
}
func TestSimpleInsertDeleteMerge(t *testing.T) {
base := "Hello World!"
versionA := "Coucou World!"
versionB := "Hello World and Space!"
result, ok, err := Merge(base, versionA, versionB)
expectSuccessfulMerge(t, err, ok)
expected := "Coucou World and Space!"
if result != expected {
t.Errorf("Expected %s, got %s.", expected, result)
}
}
func TestMergeWithSameDiff(t *testing.T) {
base := "Hello World!"
versionA := "Coucou World!"
versionB := "Coucou World!"
result, ok, err := Merge(base, versionA, versionB)
expectSuccessfulMerge(t, err, ok)
expected := "Coucou World!"
if result != expected {
t.Errorf("Expected %s, got %s.", expected, result)
}
}
func TestMergeConflict(t *testing.T) {
base := "Hello World!"
versionA := "Coucou World!"
versionB := "Hola World!"
_, ok, err := Merge(base, versionA, versionB)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
if ok {
t.Error("Should merge-conflict")
}
}