@@ -32,6 +32,11 @@ type Child struct {
32
32
Age int `default:"10"`
33
33
}
34
34
35
+ type ChildPtr struct {
36
+ Name * string
37
+ Age * int `default:"10"`
38
+ }
39
+
35
40
type ExampleBasic struct {
36
41
Bool bool `default:"true"`
37
42
Integer int `default:"33"`
@@ -61,6 +66,27 @@ type ExampleBasic struct {
61
66
StringSliceSlice [][]string `default:"[[1],[]]"`
62
67
63
68
DateTime string `default:"{{date:1,-10,0}} {{time:1,-5,10}}"`
69
+
70
+ BoolPtr * bool `default:"false"`
71
+ IntPtr * int `default:"33"`
72
+ Int8Ptr * int8 `default:"8"`
73
+ Int16Ptr * int16 `default:"16"`
74
+ Int32Ptr * int32 `default:"32"`
75
+ Int64Ptr * int64 `default:"64"`
76
+ UIntPtr * uint `default:"11"`
77
+ UInt8Ptr * uint8 `default:"18"`
78
+ UInt16Ptr * uint16 `default:"116"`
79
+ UInt32Ptr * uint32 `default:"132"`
80
+ UInt64Ptr * uint64 `default:"164"`
81
+ Float32Ptr * float32 `default:"3.2"`
82
+ Float64Ptr * float64 `default:"6.4"`
83
+ DurationPtr * time.Duration `default:"1s"`
84
+ SecondPtr * time.Duration `default:"1s"`
85
+ StructPtr * struct {
86
+ Bool bool `default:"true"`
87
+ Integer * int `default:"33"`
88
+ }
89
+ ChildrenPtr []* ChildPtr
64
90
}
65
91
66
92
func (s * DefaultsSuite ) TestSetDefaultsBasic (c * C ) {
@@ -106,6 +132,24 @@ func (s *DefaultsSuite) assertTypes(c *C, foo *ExampleBasic) {
106
132
c .Assert (foo .IntSliceSlice , DeepEquals , [][]int {[]int {1 }, []int {2 }, []int {3 }, []int {4 }})
107
133
c .Assert (foo .StringSliceSlice , DeepEquals , [][]string {[]string {"1" }, []string {}})
108
134
c .Assert (foo .DateTime , Equals , "2020-08-10 12:55:10" )
135
+ c .Assert (* foo .BoolPtr , Equals , false )
136
+ c .Assert (* foo .IntPtr , Equals , 33 )
137
+ c .Assert (* foo .Int8Ptr , Equals , int8 (8 ))
138
+ c .Assert (* foo .Int16Ptr , Equals , int16 (16 ))
139
+ c .Assert (* foo .Int32Ptr , Equals , int32 (32 ))
140
+ c .Assert (* foo .Int64Ptr , Equals , int64 (64 ))
141
+ c .Assert (* foo .UIntPtr , Equals , uint (11 ))
142
+ c .Assert (* foo .UInt8Ptr , Equals , uint8 (18 ))
143
+ c .Assert (* foo .UInt16Ptr , Equals , uint16 (116 ))
144
+ c .Assert (* foo .UInt32Ptr , Equals , uint32 (132 ))
145
+ c .Assert (* foo .UInt64Ptr , Equals , uint64 (164 ))
146
+ c .Assert (* foo .Float32Ptr , Equals , float32 (3.2 ))
147
+ c .Assert (* foo .Float64Ptr , Equals , 6.4 )
148
+ c .Assert (* foo .DurationPtr , Equals , time .Second )
149
+ c .Assert (* foo .SecondPtr , Equals , time .Second )
150
+ c .Assert (foo .StructPtr .Bool , Equals , true )
151
+ c .Assert (* foo .StructPtr .Integer , Equals , 33 )
152
+ c .Assert (foo .ChildrenPtr , IsNil )
109
153
}
110
154
111
155
func (s * DefaultsSuite ) TestSetDefaultsWithValues (c * C ) {
@@ -118,6 +162,13 @@ func (s *DefaultsSuite) TestSetDefaultsWithValues(c *C) {
118
162
Children : []Child {{Name : "alice" }, {Name : "bob" , Age : 2 }},
119
163
}
120
164
165
+ intzero := 0
166
+ foo .IntPtr = & intzero
167
+
168
+ ageZero := 0
169
+ childPtr := & ChildPtr {Age : & ageZero }
170
+ foo .ChildrenPtr = append (foo .ChildrenPtr , childPtr )
171
+
121
172
SetDefaults (foo )
122
173
123
174
c .Assert (foo .Integer , Equals , 55 )
@@ -127,6 +178,10 @@ func (s *DefaultsSuite) TestSetDefaultsWithValues(c *C) {
127
178
c .Assert (string (foo .Bytes ), Equals , "foo" )
128
179
c .Assert (foo .Children [0 ].Age , Equals , 10 )
129
180
c .Assert (foo .Children [1 ].Age , Equals , 2 )
181
+ c .Assert (* foo .ChildrenPtr [0 ].Age , Equals , 0 )
182
+ c .Assert (foo .ChildrenPtr [0 ].Name , IsNil )
183
+
184
+ c .Assert (* foo .IntPtr , Equals , 0 )
130
185
}
131
186
132
187
func (s * DefaultsSuite ) BenchmarkLogic (c * C ) {
0 commit comments