-
Notifications
You must be signed in to change notification settings - Fork 3
/
diff_test.go
90 lines (71 loc) · 1.3 KB
/
diff_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"reflect"
"testing"
)
func TestEmpty(t *testing.T) {
if Diff(nil, nil) != nil {
t.Error("two nils should equal nil")
}
}
func TestCreate(t *testing.T) {
doc := map[string]interface{}{
"foo": 1,
}
if !reflect.DeepEqual(Diff(nil, doc).Additions, doc) {
t.Error("create should be an addition")
}
}
func TestDelete(t *testing.T) {
doc := map[string]interface{}{
"foo": 1,
}
if !reflect.DeepEqual(Diff(doc, nil).Removals, doc) {
t.Error("delete should be a removal")
}
}
func TestAdd(t *testing.T) {
b := map[string]interface{}{
"foo": 1,
}
a := map[string]interface{}{
"foo": 1,
"bar": 2,
}
d := map[string]interface{}{
"bar": 2,
}
if !reflect.DeepEqual(Diff(b, a).Additions, d) {
t.Error("failed to add")
}
}
func TestRemove(t *testing.T) {
b := map[string]interface{}{
"foo": 1,
"bar": 2,
}
a := map[string]interface{}{
"foo": 1,
}
d := map[string]interface{}{
"bar": 2,
}
if !reflect.DeepEqual(Diff(b, a).Removals, d) {
t.Error("failed to remove")
}
}
func TestChange(t *testing.T) {
b := map[string]interface{}{
"foo": 1,
}
a := map[string]interface{}{
"foo": 2,
}
d := map[string]Change{
"foo": Change{1, 2},
}
r := Diff(b, a)
if !reflect.DeepEqual(r.Changes, d) {
t.Errorf("failed to change: %v", r.Changes)
}
}