forked from beme/abide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_test.go
40 lines (37 loc) · 858 Bytes
/
json_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
package abide
import (
"testing"
)
func TestUpdateKeyValuesInMap(t *testing.T) {
m := map[string]interface{}{
"A": map[string]interface{}{
"B": 1,
"C": map[string]interface{}{
"B": 2,
},
"D": []interface{}{
map[string]interface{}{
"B": 3,
},
},
},
"B": 3,
}
newM := updateKeyValuesInMap("B", 0, m)
b1 := newM["A"].(map[string]interface{})["B"].(int)
if b1 != 0 {
t.Fatalf("Expected 0, instead got %d.", b1)
}
b2 := newM["A"].(map[string]interface{})["C"].(map[string]interface{})["B"].(int)
if b1 != 0 {
t.Fatalf("Expected 0, instead got %d.", b2)
}
b3 := newM["A"].(map[string]interface{})["D"].([]interface{})[0].(map[string]interface{})["B"].(int)
if b3 != 0 {
t.Fatalf("Expected 0, instead got %d.", b3)
}
b4 := newM["B"].(int)
if b4 != 0 {
t.Fatalf("Expected 0, instead got %d.", b4)
}
}