tree - nodes_test.go
1 package tree
2
3 import (
4 "reflect"
5 "testing"
6 )
7
8 func TestRoots(t *testing.T) {
9 var branches [7]Branch
10
11 branches[0].Add("Leaf1", Leaf("ABC"))
12 branches[0].Add("Leaf2", Leaf("DEF"))
13 branches[1].Add("Leaf1", Leaf("GHI"))
14 branches[2].Add("BranchA", branches[0])
15 branches[2].Add("BranchB", branches[1])
16 branches[3].Add("Parent", branches[2])
17
18 branches[4].Add("Leaf3", Leaf("JKL"))
19 branches[5].Add("BranchA", branches[4])
20 branches[6].Add("Parent", branches[5])
21
22 tree, err := Merge(branches[3], branches[6])
23 if err != nil {
24 t.Fatalf("unexpected error: %s", err)
25 }
26
27 expected := node{
28 children: []node{
29 {
30 name: "Parent",
31 children: []node{
32 {
33 name: "BranchA",
34 children: []node{
35 {
36 name: "Leaf1",
37 data: []byte("ABC"),
38 },
39 {
40 name: "Leaf2",
41 data: []byte("DEF"),
42 },
43 {
44 name: "Leaf3",
45 data: []byte("JKL"),
46 },
47 },
48 },
49 {
50 name: "BranchB",
51 children: []node{
52 {
53 name: "Leaf1",
54 data: []byte("GHI"),
55 },
56 },
57 },
58 },
59 },
60 },
61 }
62
63 if read := readTree(tree); !reflect.DeepEqual(read, expected) {
64 t.Errorf("no match")
65 }
66 }
67