-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_lambda_test.go
111 lines (84 loc) · 1.95 KB
/
value_lambda_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
package codegen
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLambdaEmpty(t *testing.T) {
const want = `func (){
}`
var sb strings.Builder
Lambda().writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestLambdaNotPointer(t *testing.T) {
got := Lambda().isPointer()
assert.False(t, got)
}
func TestLambdaParamSingle(t *testing.T) {
const want = `func (param string){
}`
var sb strings.Builder
Lambda().Params(Param("param", "string")).
writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestLambdaParamMultiple(t *testing.T) {
const want = `func (param string,param2 alias.MyType){
}`
var sb strings.Builder
Lambda().Params(
Param("param", "string"),
QualParam("param2", "alias", "MyType"),
).writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestLambdaReturnTypeSingle(t *testing.T) {
const want = `func ()string{
return "str value"
}`
var sb strings.Builder
Lambda().ReturnTypes(
Type("string"),
).Block(
Return(String("str value")),
).writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestLambdaReturnTypeMultiple(t *testing.T) {
const want = `func ()(string,error){
return "str value",nil
}`
var sb strings.Builder
Lambda().ReturnTypes(
Type("string"),
ReturnTypeError(),
).Block(
Return(String("str value"), Nil()),
).writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestLambdaCallArgsEmpty(t *testing.T) {
const want = `func (){
}()`
var sb strings.Builder
Lambda().Call().
writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestLambdaCallArgsSingle(t *testing.T) {
const want = `func (){
}(a)`
var sb strings.Builder
Lambda().Call().Args(Identifier("a")).
writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestLambdaCallArgsMultiple(t *testing.T) {
const want = `func (){
}(a,b)`
var sb strings.Builder
Lambda().Call().Args(Identifier("a"), Identifier("b")).
writeValue(&sb)
assert.Equal(t, want, sb.String())
}