forked from clbanning/mxj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keystolower_test.go
60 lines (50 loc) · 1.02 KB
/
keystolower_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
// keystolower_test.go
package mxj
import (
"fmt"
"testing"
)
var tolowerdata1 = []byte(`
<doc>
<element attr="attrValue">value</element>
</doc>
`)
var tolowerdata2 = []byte(`
<DOC>
<Element attR="attrValue">value</Element>
</DOC>
`)
func TestToLower(t *testing.T) {
fmt.Println("\n-------------- keystolower_test.go")
fmt.Println("\nTestToLower ...")
CoerceKeysToLower()
defer CoerceKeysToLower()
m1, err := NewMapXml(tolowerdata1)
if err != nil {
t.Fatal(err)
}
m2, err := NewMapXml(tolowerdata2)
if err != nil {
t.Fatal(err)
}
v1, err := m1.ValuesForPath("doc.element")
if err != nil {
t.Fatal(err)
}
v2, err := m2.ValuesForPath("doc.element")
if err != nil {
t.Fatal(err)
}
if len(v1) != len(v2) {
t.Fatal(err, len(v1), len(v2))
}
m := v1[0].(map[string]interface{})
mm := v2[0].(map[string]interface{})
for k, v := range m {
if vv, ok := mm[k]; !ok {
t.Fatal("key:", k, "not in mm")
} else if v.(string) != vv.(string) {
t.Fatal(v.(string), "not in v2:", vv.(string))
}
}
}