-
Notifications
You must be signed in to change notification settings - Fork 112
/
keyvalues2_test.go
47 lines (41 loc) · 1.02 KB
/
keyvalues2_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
package mxj
import (
"fmt"
"testing"
)
func TestSetSubkeyFieldSeparator(t *testing.T) {
PrependAttrWithHyphen(true)
fmt.Println("----------- TestSetSubkeyFieldSeparator")
data := `
<doc>
<elem attr="1">value 1</elem>
<elem attr="2">value 2</elem>
<elem attr="3">value 3</elem>
</doc>`
m, err := NewMapXml([]byte(data))
if err != nil {
t.Fatal(err)
}
vals, err := m.ValuesForKey("elem", "-attr:2:text")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 {
t.Fatal(":len(vals);", len(vals), vals)
}
if vals[0].(map[string]interface{})[textK].(string) != "value 2" {
t.Fatal(":expecting: value 2; got:", vals[0].(map[string]interface{})[textK])
}
SetFieldSeparator("|")
defer SetFieldSeparator()
vals, err = m.ValuesForKey("elem", "-attr|2|text")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 {
t.Fatal("|len(vals);", len(vals), vals)
}
if vals[0].(map[string]interface{})[textK].(string) != "value 2" {
t.Fatal("|expecting: value 2; got:", vals[0].(map[string]interface{})[textK])
}
}