-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_struct_test.go
98 lines (80 loc) · 1.64 KB
/
block_struct_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
package codegen
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStructEmpty(t *testing.T) {
const want = `type myStruct struct {
}
`
var sb strings.Builder
newStruct("myStruct").write(&sb)
assert.Equal(t, want, sb.String())
}
func TestStructOne(t *testing.T) {
const want = `type myStruct struct {
prop string
}
`
var sb strings.Builder
newStruct("myStruct").Props(
Property("prop", "string"),
).write(&sb)
assert.Equal(t, want, sb.String())
}
func TestStructMultiple(t *testing.T) {
const want = `type myStruct struct {
prop string
prop alias.MyType
}
`
var sb strings.Builder
newStruct("myStruct").Props(
Property("prop", "string"),
QualProperty("prop", "alias", "MyType"),
).write(&sb)
assert.Equal(t, want, sb.String())
}
func TestStructAddProp(t *testing.T) {
const want = `type myStruct struct {
prop1 *string
prop2 string
prop3 *string
prop4 string
prop5 *string
}
`
decl := newStruct("myStruct")
for i := 0; i < 5; i++ {
prop := decl.AddProp(fmt.Sprintf("prop%d", i+1), "string")
if i%2 == 0 {
prop.Pointer()
}
}
var sb strings.Builder
decl.write(&sb)
assert.Equal(t, want, sb.String())
}
func TestStructQualAddProp(t *testing.T) {
const want = `type myStruct struct {
prop1 *alias.MyType1
prop2 alias.MyType2
prop3 *alias.MyType3
prop4 alias.MyType4
prop5 *alias.MyType5
}
`
decl := newStruct("myStruct")
for i := 0; i < 5; i++ {
name, typ := fmt.Sprintf("prop%d", i+1), fmt.Sprintf("MyType%d", i+1)
prop := decl.AddQualProp(name, "alias", typ)
if i%2 == 0 {
prop.Pointer()
}
}
var sb strings.Builder
decl.write(&sb)
assert.Equal(t, want, formatSb(sb))
}