-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.go
64 lines (55 loc) · 926 Bytes
/
test_utils.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
//go:build test
package typegen
import (
"fmt"
"os"
)
func init() {
fmt.Fprintln(os.Stderr, "Testing...")
}
func TestInitNodes(nodes Nodes) Nodes {
for i, n := range nodes {
nodes[i] = TestInitNode(n)
}
return nodes
}
func TestInitNode(n *Node) *Node {
if n == nil {
goto end
}
if n.nodes != nil {
goto end
}
n.nodes = make(Nodes, 0)
end:
return n
}
func TestAddNode(parent, child *Node) *Node {
TestInitNode(child)
resetDebugString(child)
parent.nodes = append(parent.nodes, child)
resetDebugString(parent)
return parent
}
func TestResetNode(n *Node) *Node {
resetDebugString(n)
return n
}
func TestGetNode(n *Node, i int) *Node {
return n.nodes[i]
}
func TestGetNodes(n *Node) Nodes {
return n.nodes
}
func TestFixupNodes(ns Nodes, f func(Nodes)) Nodes {
for i, n := range ns {
if n == nil {
continue
}
ns[i] = n.Reset()
}
if f != nil {
f(TestInitNodes(ns))
}
return ns
}