-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_funcParam_test.go
199 lines (144 loc) · 4.03 KB
/
block_funcParam_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package codegen
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParamName(t *testing.T) {
const want = `name`
got := Param("name", "typeName").GetName()
assert.Equal(t, want, got)
}
func TestQualParamFullName(t *testing.T) {
const want = `name`
got := QualParam("name", "alias", "typeName").GetName()
assert.Equal(t, want, got)
}
func TestParamFullType(t *testing.T) {
const want = `typeName`
got := Param("name", "typeName").GetFullType()
assert.Equal(t, want, got)
}
func TestQualParamFullType(t *testing.T) {
const want = `alias.typeName`
got := QualParam("name", "alias", "typeName").GetFullType()
assert.Equal(t, want, got)
}
func TestParamFullTypePointer(t *testing.T) {
const want = `*typeName`
got := Param("name", "typeName").Pointer().GetFullType()
assert.Equal(t, want, got)
}
func TestQualParamTypePointer(t *testing.T) {
const want = `*alias.typeName`
got := QualParam("name", "alias", "typeName").Pointer().GetFullType()
assert.Equal(t, want, got)
}
func TestFuncParam(t *testing.T) {
const want = `name type`
var sb strings.Builder
Param("name", "type").wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestFuncParamPointer(t *testing.T) {
const want = `name *type`
var sb strings.Builder
Param("name", "type").Pointer().
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestFuncQualParam(t *testing.T) {
const want = `name alias.type`
var sb strings.Builder
QualParam("name", "alias", "type").wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestFuncQualParamPointer(t *testing.T) {
const want = `name *alias.type`
var sb strings.Builder
QualParam("name", "alias", "type").Pointer().
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestFuncParamsEmpty(t *testing.T) {
const want = `()`
var sb strings.Builder
params := make([]*ParamDecl, 0)
writeParams(&sb, params)
assert.Equal(t, want, sb.String())
}
func TestFuncParamsOne(t *testing.T) {
const want = `(name1 type)`
var sb strings.Builder
params := []*ParamDecl{
Param("name1", "type"),
}
writeParams(&sb, params)
assert.Equal(t, want, sb.String())
}
func TestFuncParams(t *testing.T) {
const want = `(name1 type,name2 alias.type,name3 *type,name4 *alias.type)`
var sb strings.Builder
params := []*ParamDecl{
Param("name1", "type"),
QualParam("name2", "alias", "type"),
Param("name3", "type").Pointer(),
QualParam("name4", "alias", "type").Pointer(),
}
writeParams(&sb, params)
assert.Equal(t, want, sb.String())
}
func TestFuncParamSetIsPointerTrue(t *testing.T) {
const want = `(name1 *type)`
var sb strings.Builder
params := []*ParamDecl{
Param("name1", "type").SetIsPointer(true),
}
writeParams(&sb, params)
assert.Equal(t, want, sb.String())
}
func TestFuncParamSetIsPointerFalse(t *testing.T) {
const want = `(name1 type)`
var sb strings.Builder
params := []*ParamDecl{
Param("name1", "type").SetIsPointer(false),
}
writeParams(&sb, params)
assert.Equal(t, want, sb.String())
}
func TestFuncParamArray(t *testing.T) {
const want = `param []string`
var sb strings.Builder
Param("param", "string").Array().
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestFuncQualParamArray(t *testing.T) {
const want = `param []alias.MyType`
var sb strings.Builder
QualParam("param", "alias", "MyType").Array().
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestFuncParamSetIsArrayTrue(t *testing.T) {
const want = `param []string`
var sb strings.Builder
Param("param", "string").SetIsArray(true).
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestFuncParamSetIsArrayFalse(t *testing.T) {
const want = `param string`
var sb strings.Builder
Param("param", "string").SetIsArray(false).
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestFuncGetters(t *testing.T) {
fixture := QualParam("param", "alias", "MyType").Pointer().Array()
assert.Equal(t, "param", fixture.GetName())
assert.Equal(t, "alias", fixture.GetTypeAlias())
assert.Equal(t, "MyType", fixture.GetTypeName())
assert.True(t, fixture.GetIsPointer())
assert.True(t, fixture.GetIsArray())
}