forked from clbanning/mxj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_test.go
43 lines (39 loc) · 801 Bytes
/
set_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
package mxj
import (
"testing"
)
func TestSetValueForPath(t *testing.T) {
m := map[string]interface{}{
"Div": map[string]interface{}{
"Colour": "blue",
"Font": map[string]interface{}{
"Family": "sans",
},
},
}
mv := Map(m)
// testing setting a new key
err := mv.SetValueForPath("big", "Div.Font.Size")
if err != nil {
t.Fatal(err)
}
val, err := mv.ValueForPathString("Div.Font.Size")
if err != nil {
t.Fatal(err)
}
if val != "big" {
t.Fatal("key's value hasn't changed")
}
// testing setting a new value to en existing key
err = mv.SetValueForPath("red", "Div.Colour")
if err != nil {
t.Fatal(err)
}
val, err = mv.ValueForPathString("Div.Colour")
if err != nil {
t.Fatal(err)
}
if val != "red" {
t.Fatal("existig key's value hasn't changed")
}
}