-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathfiller_test.go
101 lines (83 loc) · 1.95 KB
/
filler_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
package defaults
import (
"fmt"
"reflect"
. "gopkg.in/check.v1"
)
type FillerSuite struct{}
var _ = Suite(&FillerSuite{})
type FixtureTypeInt int
func (s *FillerSuite) TestFuncByNameIsEmpty(c *C) {
calledA := false
calledB := false
f := &Filler{
FuncByName: map[string]FillerFunc{
"Foo": func(field *FieldData) {
calledA = true
},
},
FuncByKind: map[reflect.Kind]FillerFunc{
reflect.Int: func(field *FieldData) {
calledB = true
},
},
}
f.Fill(&struct{ Foo int }{})
c.Assert(calledA, Equals, true)
c.Assert(calledB, Equals, false)
}
func (s *FillerSuite) TestFuncByTypeIsEmpty(c *C) {
calledA := false
calledB := false
t := GetTypeHash(reflect.TypeOf(new(FixtureTypeInt)))
f := &Filler{
FuncByType: map[TypeHash]FillerFunc{
t: func(field *FieldData) {
calledA = true
},
},
FuncByKind: map[reflect.Kind]FillerFunc{
reflect.Int: func(field *FieldData) {
calledB = true
},
},
}
f.Fill(&struct{ Foo FixtureTypeInt }{})
c.Assert(calledA, Equals, true)
c.Assert(calledB, Equals, false)
}
func (s *FillerSuite) TestFuncByKindIsNotEmpty(c *C) {
called := false
f := &Filler{FuncByKind: map[reflect.Kind]FillerFunc{
reflect.Int: func(field *FieldData) {
called = true
},
}}
f.Fill(&struct{ Foo int }{Foo: 42})
c.Assert(called, Equals, false)
}
func (s *FillerSuite) TestFuncByKindSlice(c *C) {
fmt.Println(GetTypeHash(reflect.TypeOf(new([]string))))
}
func (s *FillerSuite) TestFuncByKindTag(c *C) {
var called string
f := &Filler{Tag: "foo", FuncByKind: map[reflect.Kind]FillerFunc{
reflect.Int: func(field *FieldData) {
called = field.TagValue
},
}}
f.Fill(&struct {
Foo int `foo:"qux"`
}{})
c.Assert(called, Equals, "qux")
}
func (s *FillerSuite) TestFuncByKindIsEmpty(c *C) {
called := false
f := &Filler{FuncByKind: map[reflect.Kind]FillerFunc{
reflect.Int: func(field *FieldData) {
called = true
},
}}
f.Fill(&struct{ Foo int }{})
c.Assert(called, Equals, true)
}