-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_interfaceFunc_test.go
97 lines (68 loc) · 2.21 KB
/
block_interfaceFunc_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
package codegen
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestInterfaceFuncEmpty(t *testing.T) {
const want = `myFunc()`
var sb strings.Builder
FuncDecl("myFunc").wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestInterfaceFuncParamOne(t *testing.T) {
const want = `myFunc(param myType)`
var sb strings.Builder
FuncDecl("myFunc").Params(Param("param", "myType")).
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestInterfaceFuncQualParamOne(t *testing.T) {
const want = `myFunc(param alias.MyType)`
var sb strings.Builder
FuncDecl("myFunc").Params(QualParam("param", "alias", "MyType")).
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestInterfaceFuncParamMultiple(t *testing.T) {
const want = `myFunc(param myType,anotherParam myType2)`
var sb strings.Builder
FuncDecl("myFunc").Params(Param("param", "myType"), Param("anotherParam", "myType2")).
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestInterfaceFuncQualParamMultiple(t *testing.T) {
const want = `myFunc(param alias.MyType,anotherParam alias.MyType2)`
var sb strings.Builder
FuncDecl("myFunc").Params(QualParam("param", "alias", "MyType"), QualParam("anotherParam", "alias", "MyType2")).
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestInterfaceFuncReturnTypeOne(t *testing.T) {
const want = `myFunc()myType`
var sb strings.Builder
FuncDecl("myFunc").ReturnTypes(Type("myType")).
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestInterfaceFuncQualReturnTypeOne(t *testing.T) {
const want = `myFunc()alias.MyType`
var sb strings.Builder
FuncDecl("myFunc").ReturnTypes(QualType("alias", "MyType")).
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestInterfaceFuncReturnTypeMultiple(t *testing.T) {
const want = `myFunc()(myType,anotherType)`
var sb strings.Builder
FuncDecl("myFunc").ReturnTypes(Type("myType"), Type("anotherType")).
wr(&sb)
assert.Equal(t, want, sb.String())
}
func TestInterfaceFuncQualReturnTypeMultiple(t *testing.T) {
const want = `myFunc()(alias.MyType,alias.AnotherType)`
var sb strings.Builder
FuncDecl("myFunc").ReturnTypes(QualType("alias", "MyType"), QualType("alias", "AnotherType")).
wr(&sb)
assert.Equal(t, want, sb.String())
}