-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_struct_test.go
61 lines (45 loc) · 1.32 KB
/
value_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
package codegen
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStructNoProperties(t *testing.T) {
const want = `myStruct{}`
var sb strings.Builder
InitStruct("myStruct").writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestStructNoPropertiesAddress(t *testing.T) {
const want = `&myStruct{}`
var sb strings.Builder
InitStruct("myStruct").Address().
writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestStructOneProp(t *testing.T) {
const want = `myStruct{prop:val}`
var sb strings.Builder
InitStruct("myStruct").Props(
PropValue("prop", Identifier("val")),
).writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestStructMultipleProps(t *testing.T) {
const want = `myStruct{prop1:val1,prop2:val2}`
var sb strings.Builder
InitStruct("myStruct").Props(
PropValue("prop1", Identifier("val1")),
PropValue("prop2", Identifier("val2")),
).writeValue(&sb)
assert.Equal(t, want, sb.String())
}
func TestStructAddPropValue(t *testing.T) {
const want = `myStruct{prop1:val1.MyFunc(),prop2:myFunc(a)}`
var sb strings.Builder
fixture := InitStruct("myStruct")
fixture.AddPropValue("prop1", Identifier("val1").Call("MyFunc"))
fixture.AddPropValue("prop2", FuncCall("myFunc").Args(Identifier("a")))
fixture.writeValue(&sb)
assert.Equal(t, want, sb.String())
}