-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_test.go
50 lines (37 loc) · 1010 Bytes
/
tree_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
package partial
import (
"testing"
)
func TestTree(t *testing.T) {
p := New("template1", "template2").ID("root")
child := New("template1", "template2").ID("id")
oobChild := New("template1", "template2").ID("id1")
child.With(oobChild)
p.With(child)
p.WithOOB(oobChild)
tr := Tree(p)
if tr.ID != "root" {
t.Errorf("expected root id to be root, got %s", tr.ID)
}
if tr.Nodes == nil {
t.Errorf("expected nodes to be non-nil")
}
if len(tr.Nodes) != 2 {
t.Errorf("expected 2 node, got %d", len(tr.Nodes))
}
if tr.Nodes[0].ID != "id" {
t.Errorf("expected id to be id∂, got %s", tr.Nodes[0].ID)
}
if tr.Nodes[1].ID != "id1" {
t.Errorf("expected id to be id1, got %s", tr.Nodes[1].ID)
}
if tr.Nodes[0].Nodes == nil {
t.Errorf("expected nodes to be non-nil")
}
if len(tr.Nodes[0].Nodes) != 1 {
t.Errorf("expected 1 node, got %d", len(tr.Nodes[0].Nodes))
}
if tr.Nodes[0].Nodes[0].ID != "id1" {
t.Errorf("expected id to be id1, got %s", tr.Nodes[0].Nodes[0].ID)
}
}