-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwraps_test.go
114 lines (89 loc) · 2.73 KB
/
wraps_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package astrav
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSelectorExpr_PackageName(t *testing.T) {
n := getTree(t, 1)
selExpr := n.FindFirstByNodeType(NodeTypeSelectorExpr).(*SelectorExpr)
pkgIdent := selExpr.PackageName()
assert.Equal(t, "strings", pkgIdent.Name)
assert.Equal(t, selExpr, pkgIdent.Parent())
}
func TestFuncType_Params(t *testing.T) {
n := getTree(t, 1)
f := n.FindFirstByName("Score").ChildByNodeType(NodeTypeFuncType)
params := f.(*FuncType).Params()
assert.NotNil(t, params)
assert.Equal(t, 1, len(params.List))
}
func TestFuncType_Results(t *testing.T) {
n := getTree(t, 1)
f := n.FindFirstByName("Score").ChildByNodeType(NodeTypeFuncType)
params := f.(*FuncType).Results()
assert.NotNil(t, params)
assert.Equal(t, 1, len(params.List))
}
func TestFuncDecl_Params(t *testing.T) {
n := getTree(t, 1)
f := n.FindFirstByName("Score")
params := f.(*FuncDecl).Params()
assert.NotNil(t, params)
assert.Equal(t, 1, len(params.List))
}
func TestFuncDecl_Results(t *testing.T) {
n := getTree(t, 1)
f := n.FindFirstByName("Score")
params := f.(*FuncDecl).Results()
assert.NotNil(t, params)
assert.Equal(t, 1, len(params.List))
}
func TestForStmt_Init(t *testing.T) {
n := getPackage(t, 2)
loop := n.FindFirstByNodeType(NodeTypeForStmt)
init := loop.(*ForStmt).Init()
assert.NotNil(t, init)
assert.NotNil(t, init.FindByName("i"))
assert.Equal(t, NodeTypeAssignStmt, init.NodeType())
}
func TestForStmt_Cond(t *testing.T) {
n := getPackage(t, 2)
loop := n.FindFirstByNodeType(NodeTypeForStmt)
cond := loop.(*ForStmt).Cond()
assert.NotNil(t, cond)
assert.NotNil(t, cond.FindByName("i"))
assert.NotNil(t, cond.FindByName("num"))
assert.Equal(t, NodeTypeBinaryExpr, cond.NodeType())
}
func TestForStmt_Post(t *testing.T) {
n := getPackage(t, 2)
loop := n.FindFirstByNodeType(NodeTypeForStmt)
post := loop.(*ForStmt).Post()
assert.NotNil(t, post)
assert.NotNil(t, post.FindByName("i"))
assert.Equal(t, NodeTypeIncDecStmt, post.NodeType())
}
func TestRangeStmt_Key(t *testing.T) {
n := getPackage(t, 1)
loop := n.FindFirstByNodeType(NodeTypeRangeStmt)
k := loop.(*RangeStmt).Key()
assert.NotNil(t, k)
assert.Equal(t, "_", k.(*Ident).Name)
assert.Equal(t, NodeTypeIdent, k.NodeType())
}
func TestRangeStmt_Value(t *testing.T) {
n := getPackage(t, 1)
loop := n.FindFirstByNodeType(NodeTypeRangeStmt)
v := loop.(*RangeStmt).Value()
assert.NotNil(t, v)
assert.Equal(t, "c", v.(*Ident).Name)
assert.Equal(t, NodeTypeIdent, v.NodeType())
}
func TestRangeStmt_X(t *testing.T) {
n := getPackage(t, 1)
loop := n.FindFirstByNodeType(NodeTypeRangeStmt)
x := loop.(*RangeStmt).X()
assert.NotNil(t, x)
assert.NotNil(t, x.FindByName("word"))
assert.Equal(t, NodeTypeCallExpr, x.NodeType())
}