-
Notifications
You must be signed in to change notification settings - Fork 113
/
rename_test.go
42 lines (38 loc) · 867 Bytes
/
rename_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
package mxj
import (
"fmt"
"testing"
)
func TestRenameKey(t *testing.T) {
fmt.Println("------------ rename_test.go")
m := map[string]interface{}{
"Div": map[string]interface{}{
"Colour": "blue",
"Width": "100%",
},
}
mv := Map(m)
err := mv.RenameKey("Div.Colour", "Color")
if err != nil {
t.Fatal(err)
}
values, err := mv.ValuesForPath("Div.Color")
if len(values) != 1 {
t.Fatal("didn't add the new key")
}
if values[0] != "blue" {
t.Fatal("value is changed")
}
values, err = mv.ValuesForPath("Div.Colour")
if len(values) > 0 {
t.Fatal("didn't removed the old key")
}
err = mv.RenameKey("not.existing.path", "newname")
if err == nil {
t.Fatal("should raise an error on a non existing path")
}
err = mv.RenameKey("Div.Color", "Width")
if err == nil {
t.Fatal("should raise an error if the newName already exists")
}
}