-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeeply_test.go
More file actions
66 lines (63 loc) · 1.43 KB
/
deeply_test.go
File metadata and controls
66 lines (63 loc) · 1.43 KB
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 deeply
import (
"reflect"
"testing"
)
func TestMerge(t *testing.T) {
a := map[string]interface{}{
"z": map[string]interface{}{
"one": "az1",
"three": "az3",
},
"x": "ax",
}
b := map[string]interface{}{
"z": map[string]interface{}{
"one": "az1!",
"two": "az2",
},
"y": "ay",
}
c := Merge(a, b)
z1 := c["z"].(map[string]interface{})["one"]
if z1 != "az1!" {
t.Errorf("Expected value for 'z.one' was 'az1!', but found '%v'", z1)
}
z2 := c["z"].(map[string]interface{})["two"]
if z2 != "az2" {
t.Errorf("Expected value for 'z.two' was 'az2', but found '%v'", z2)
}
z3 := c["z"].(map[string]interface{})["three"]
if z3 != "az3" {
t.Errorf("Expected value for 'z.three' was 'az3', but found '%v'", z3)
}
y := c["y"]
if y != "ay" {
t.Errorf("Expected value for 'y' was 'ay', but found '%v'", y)
}
x := c["x"]
if x != "ax" {
t.Errorf("Expected value for 'x' was 'ax', but found '%v'", x)
}
}
func TestCopy(t *testing.T) {
a := map[string]interface{}{
"z": map[string]interface{}{
"one": "az1",
"two": "az2",
},
"y": "ay",
}
b := Copy(a)
if !reflect.DeepEqual(a, b) {
t.Errorf("Copy not equal than original: '%v' '%v'", a, b)
}
b["y"] = "!!"
if a["y"] == "!!" {
t.Errorf("Modification on copy changed the original")
}
b["z"].(map[string]interface{})["one"] = "!!"
if a["z"].(map[string]interface{})["one"] == "!!" {
t.Errorf("Modification on copy changed the original")
}
}