forked from clbanning/mxj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleafnode_test.go
97 lines (88 loc) · 1.74 KB
/
leafnode_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package mxj
import (
"fmt"
"testing"
)
func TestLNHeader(t *testing.T) {
fmt.Println("\n---------------- leafnode_test.go ...")
}
func TestLeafNodes(t *testing.T) {
json1 := []byte(`{
"friends": [
{
"skills": [
44, 12
]
}
]
}`)
json2 := []byte(`{
"friends":
{
"skills": [
44, 12
]
}
}`)
m, _ := NewMapJson(json1)
ln := m.LeafNodes()
fmt.Println("\njson1-LeafNodes:")
for _, v := range ln {
fmt.Printf("%#v\n", v)
}
p := m.LeafPaths()
fmt.Println("\njson1-LeafPaths:")
for _, v := range p {
fmt.Printf("%#v\n", v)
}
m, _ = NewMapJson(json2)
ln = m.LeafNodes()
fmt.Println("\njson2-LeafNodes:")
for _, v := range ln {
fmt.Printf("%#v\n", v)
}
v := m.LeafValues()
fmt.Println("\njson1-LeafValues:")
for _, v := range v {
fmt.Printf("%#v\n", v)
}
json3 := []byte(`{ "a":"list", "of":["data", "of", 3, "types", true]}`)
m, _ = NewMapJson(json3)
ln = m.LeafNodes()
fmt.Println("\njson3-LeafNodes:")
for _, v := range ln {
fmt.Printf("%#v\n", v)
}
v = m.LeafValues()
fmt.Println("\njson3-LeafValues:")
for _, v := range v {
fmt.Printf("%#v\n", v)
}
p = m.LeafPaths()
fmt.Println("\njson3-LeafPaths:")
for _, v := range p {
fmt.Printf("%#v\n", v)
}
xmldata2 := []byte(`
<doc>
<item num="2" color="blue">Item 2 is blue</item>
<item num="3" color="green">
<arm side="left" length="3.5"/>
<arm side="right" length="3.6"/>
</item>
</doc>`)
m, err := NewMapXml(xmldata2)
if err != nil {
t.Fatal(err.Error())
}
fmt.Println("\nxml2data2-LeafValues:")
ln = m.LeafNodes()
for _, v := range ln {
fmt.Printf("%#v\n", v)
}
fmt.Println("\nxml2data2-LeafValues(NoAttributes):")
ln = m.LeafNodes(NoAttributes)
for _, v := range ln {
fmt.Printf("%#v\n", v)
}
}