Skip to content

Commit fffdf70

Browse files
authored
Add more test for struct copier (#20)
1 parent 2f8681b commit fffdf70

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

struct_copier_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ func Test_Copy_struct(t *testing.T) {
169169
assert.Nil(t, err)
170170
assert.Equal(t, DD{I: 100, F: 2}, d)
171171
})
172+
173+
t.Run("#10: structs have fields of type function", func(t *testing.T) {
174+
type SS struct {
175+
I int
176+
Fn func(int) string `copy:"fn"`
177+
}
178+
type DD struct {
179+
I int
180+
Fn func(int) string `copy:"fn"`
181+
}
182+
183+
fn := func(int) string { return "abc" }
184+
185+
var s SS = SS{I: 1, Fn: fn}
186+
var d DD = DD{I: 100}
187+
err := Copy(&d, s)
188+
assert.Nil(t, err)
189+
assert.NotNil(t, d.Fn)
190+
assert.Equal(t, "abc", d.Fn(1))
191+
})
172192
}
173193

174194
func Test_Copy_struct_error(t *testing.T) {

0 commit comments

Comments
 (0)