@@ -231,6 +231,82 @@ func AssertMapFieldError(t *testing.T, s map[string]*FieldError, field string, e
231231 EqualSkip (t , 2 , val .Tag , expectedTag )
232232}
233233
234+ func TestSliceMapArrayChanFuncPtrInterfaceRequiredValidation (t * testing.T ) {
235+
236+ var m map [string ]string
237+
238+ errs := validate .Field (m , "required" )
239+ NotEqual (t , errs , nil )
240+ // AssertError(t, errs, "", "", "required")
241+
242+ m = map [string ]string {}
243+ errs = validate .Field (m , "required" )
244+ Equal (t , errs , nil )
245+
246+ var arr [5 ]string
247+ errs = validate .Field (arr , "required" )
248+ NotEqual (t , errs , nil )
249+ // AssertError(t, errs, "", "", "required")
250+
251+ arr [0 ] = "ok"
252+ errs = validate .Field (arr , "required" )
253+ Equal (t , errs , nil )
254+
255+ var s []string
256+ errs = validate .Field (s , "required" )
257+ NotEqual (t , errs , nil )
258+ // AssertError(t, errs, "", "", "required")
259+
260+ s = []string {}
261+ errs = validate .Field (s , "required" )
262+ Equal (t , errs , nil )
263+
264+ var c chan string
265+ errs = validate .Field (c , "required" )
266+ NotEqual (t , errs , nil )
267+ // AssertError(t, errs, "", "", "required")
268+
269+ c = make (chan string )
270+ errs = validate .Field (c , "required" )
271+ Equal (t , errs , nil )
272+
273+ var tst * int
274+ errs = validate .Field (tst , "required" )
275+ NotEqual (t , errs , nil )
276+ // AssertError(t, errs, "", "", "required")
277+
278+ one := 1
279+ tst = & one
280+ errs = validate .Field (tst , "required" )
281+ Equal (t , errs , nil )
282+
283+ var iface interface {}
284+
285+ errs = validate .Field (iface , "required" )
286+ NotEqual (t , errs , nil )
287+ // AssertError(t, errs, "", "", "required")
288+
289+ errs = validate .Field (iface , "omitempty,required" )
290+ Equal (t , errs , nil )
291+
292+ errs = validate .Field (iface , "" )
293+ Equal (t , errs , nil )
294+
295+ errs = validate .Field (iface , "len=1" )
296+ NotEqual (t , errs , nil )
297+
298+ var f func (string )
299+
300+ errs = validate .Field (f , "required" )
301+ NotEqual (t , errs , nil )
302+ // AssertError(t, errs, "", "", "required")
303+
304+ f = func (name string ) {}
305+
306+ errs = validate .Field (f , "required" )
307+ Equal (t , errs , nil )
308+ }
309+
234310func TestBadKeyValidation (t * testing.T ) {
235311 type Test struct {
236312 Name string `validate:"required, "`
@@ -3735,14 +3811,14 @@ func TestStructSliceValidation(t *testing.T) {
37353811 Min : []int {1 , 2 },
37363812 Max : []int {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 },
37373813 MinMax : []int {1 , 2 , 3 , 4 , 5 },
3738- OmitEmpty : [] int {} ,
3814+ OmitEmpty : nil ,
37393815 }
37403816
37413817 err := validate .Struct (tSuccess )
37423818 Equal (t , err , nil )
37433819
37443820 tFail := & TestSlice {
3745- Required : [] int {} ,
3821+ Required : nil ,
37463822 Len : []int {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 1 },
37473823 Min : []int {},
37483824 Max : []int {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 1 },
@@ -3810,7 +3886,7 @@ func TestPoolObjectMaxSizeValidation(t *testing.T) {
38103886 Min : []int {1 , 2 },
38113887 Max : []int {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 },
38123888 MinMax : []int {1 , 2 , 3 , 4 , 5 },
3813- OmitEmpty : [] int {} ,
3889+ OmitEmpty : nil ,
38143890 }
38153891
38163892 for i := 0 ; i < 2 ; i ++ {
0 commit comments