@@ -32,6 +32,11 @@ type Child struct {
3232 Age int `default:"10"`
3333}
3434
35+ type ChildPtr struct {
36+ Name * string
37+ Age * int `default:"10"`
38+ }
39+
3540type ExampleBasic struct {
3641 Bool bool `default:"true"`
3742 Integer int `default:"33"`
@@ -61,6 +66,27 @@ type ExampleBasic struct {
6166 StringSliceSlice [][]string `default:"[[1],[]]"`
6267
6368 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
6490}
6591
6692func (s * DefaultsSuite ) TestSetDefaultsBasic (c * C ) {
@@ -106,6 +132,24 @@ func (s *DefaultsSuite) assertTypes(c *C, foo *ExampleBasic) {
106132 c .Assert (foo .IntSliceSlice , DeepEquals , [][]int {[]int {1 }, []int {2 }, []int {3 }, []int {4 }})
107133 c .Assert (foo .StringSliceSlice , DeepEquals , [][]string {[]string {"1" }, []string {}})
108134 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 )
109153}
110154
111155func (s * DefaultsSuite ) TestSetDefaultsWithValues (c * C ) {
@@ -118,6 +162,13 @@ func (s *DefaultsSuite) TestSetDefaultsWithValues(c *C) {
118162 Children : []Child {{Name : "alice" }, {Name : "bob" , Age : 2 }},
119163 }
120164
165+ intzero := 0
166+ foo .IntPtr = & intzero
167+
168+ ageZero := 0
169+ childPtr := & ChildPtr {Age : & ageZero }
170+ foo .ChildrenPtr = append (foo .ChildrenPtr , childPtr )
171+
121172 SetDefaults (foo )
122173
123174 c .Assert (foo .Integer , Equals , 55 )
@@ -127,6 +178,10 @@ func (s *DefaultsSuite) TestSetDefaultsWithValues(c *C) {
127178 c .Assert (string (foo .Bytes ), Equals , "foo" )
128179 c .Assert (foo .Children [0 ].Age , Equals , 10 )
129180 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 )
130185}
131186
132187func (s * DefaultsSuite ) BenchmarkLogic (c * C ) {
0 commit comments