-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrender_test.go
86 lines (70 loc) · 1.41 KB
/
render_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
package textree
import (
"bytes"
"github.com/plouc/gosnap"
"testing"
)
func getSampleTree() *Node {
root := NewNode("ROOT")
node1 := NewNode("1")
root.Append(node1)
node11 := NewNode("1.1")
node1.Append(node11)
node11.Append(NewNode("1.1.1"))
node11.Append(NewNode("1.1.2"))
node12 := NewNode("1.2")
node1.Append(node12)
node12.Append(NewNode("1.2.1"))
node13 := NewNode("1.3")
node1.Append(node13)
node13.Append(NewNode("1.3.1"))
node132 := NewNode("1.3.2")
node13.Append(node132)
node132.Append(NewNode("1.3.2.1"))
node132.Append(NewNode("1.3.2.2"))
node13.Append(NewNode("1.3.3"))
node1.Append(NewNode("1.4"))
node1.Append(NewNode("1.5"))
return root
}
var testCases = []struct {
name string
tree *Node
getRenderOptions func() *RenderOptions
}{
{
"basic",
getSampleTree(),
func() *RenderOptions {
o := NewRenderOptions()
return o
},
},
{
"dotted",
getSampleTree(),
func() *RenderOptions {
o := NewRenderOptions()
o.Dotted()
return o
},
},
{
"rounded",
getSampleTree(),
func() *RenderOptions {
o := NewRenderOptions()
o.Rounded()
return o
},
},
}
func TestRender(t *testing.T) {
ctx := gosnap.NewContext(t, "snapshots")
for _, testCase := range testCases {
s := ctx.NewSnapshot(testCase.name)
buf := new(bytes.Buffer)
testCase.tree.Render(buf, testCase.getRenderOptions())
s.AssertString(buf.String())
}
}