forked from basgys/goxml2json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstruct_test.go
45 lines (32 loc) · 834 Bytes
/
struct_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
package xml2json
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAddChild(t *testing.T) {
assert := assert.New(t)
n := Node{}
assert.Len(n.Children, 0)
n.AddChild("a", &Node{})
assert.Len(n.Children, 1)
n.AddChild("b", &Node{})
assert.Len(n.Children, 2)
}
func TestGetChild(t *testing.T) {
assert := assert.New(t)
n := Node{}
child := Node{}
child.AddChild("b", &Node{Data: "foobar"})
n.AddChild("a", &child)
bNode := n.GetChild("a.b")
assert.Equal("foobar", bNode.Data)
}
func TestIsComplex(t *testing.T) {
assert := assert.New(t)
n := Node{}
assert.False(n.IsComplex(), "nodes with no children are not complex")
n.AddChild("b", &Node{})
assert.True(n.IsComplex(), "nodes with children are complex")
n.Data = "foo"
assert.True(n.IsComplex(), "data does not impact IsComplex")
}