|
|
|
@ -231,49 +231,49 @@ func TestMapDiveValidation(t *testing.T) { |
|
|
|
|
|
|
|
|
|
func TestArrayDiveValidation(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// type Test struct {
|
|
|
|
|
// Errs []string `validate:"gt=0,dive,required"`
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// test := &Test{
|
|
|
|
|
// Errs: []string{"ok", "", "ok"},
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// errs := validate.Struct(test)
|
|
|
|
|
// NotEqual(t, errs, nil)
|
|
|
|
|
// Equal(t, len(errs.Errors), 1)
|
|
|
|
|
|
|
|
|
|
// fieldErr, ok := errs.Errors["Errs"]
|
|
|
|
|
// Equal(t, ok, true)
|
|
|
|
|
// Equal(t, fieldErr.IsPlaceholderErr, true)
|
|
|
|
|
// Equal(t, fieldErr.IsSliceOrArray, true)
|
|
|
|
|
// Equal(t, len(fieldErr.SliceOrArrayErrs), 1)
|
|
|
|
|
|
|
|
|
|
// innerErr, ok := fieldErr.SliceOrArrayErrs[1].(*FieldError)
|
|
|
|
|
// Equal(t, ok, true)
|
|
|
|
|
// Equal(t, innerErr.Tag, required)
|
|
|
|
|
// Equal(t, innerErr.IsPlaceholderErr, false)
|
|
|
|
|
// Equal(t, innerErr.Field, "Errs")
|
|
|
|
|
|
|
|
|
|
// test = &Test{
|
|
|
|
|
// Errs: []string{"ok", "ok", ""},
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// errs = validate.Struct(test)
|
|
|
|
|
// NotEqual(t, errs, nil)
|
|
|
|
|
// Equal(t, len(errs.Errors), 1)
|
|
|
|
|
|
|
|
|
|
// fieldErr, ok = errs.Errors["Errs"]
|
|
|
|
|
// Equal(t, ok, true)
|
|
|
|
|
// Equal(t, fieldErr.IsPlaceholderErr, true)
|
|
|
|
|
// Equal(t, fieldErr.IsSliceOrArray, true)
|
|
|
|
|
// Equal(t, len(fieldErr.SliceOrArrayErrs), 1)
|
|
|
|
|
|
|
|
|
|
// innerErr, ok = fieldErr.SliceOrArrayErrs[2].(*FieldError)
|
|
|
|
|
// Equal(t, ok, true)
|
|
|
|
|
// Equal(t, innerErr.Tag, required)
|
|
|
|
|
// Equal(t, innerErr.IsPlaceholderErr, false)
|
|
|
|
|
// Equal(t, innerErr.Field, "Errs")
|
|
|
|
|
type Test struct { |
|
|
|
|
Errs []string `validate:"gt=0,dive,required"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
test := &Test{ |
|
|
|
|
Errs: []string{"ok", "", "ok"}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
errs := validate.Struct(test) |
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
|
Equal(t, len(errs.Errors), 1) |
|
|
|
|
|
|
|
|
|
fieldErr, ok := errs.Errors["Errs"] |
|
|
|
|
Equal(t, ok, true) |
|
|
|
|
Equal(t, fieldErr.IsPlaceholderErr, true) |
|
|
|
|
Equal(t, fieldErr.IsSliceOrArray, true) |
|
|
|
|
Equal(t, len(fieldErr.SliceOrArrayErrs), 1) |
|
|
|
|
|
|
|
|
|
innerErr, ok := fieldErr.SliceOrArrayErrs[1].(*FieldError) |
|
|
|
|
Equal(t, ok, true) |
|
|
|
|
Equal(t, innerErr.Tag, required) |
|
|
|
|
Equal(t, innerErr.IsPlaceholderErr, false) |
|
|
|
|
Equal(t, innerErr.Field, "Errs[1]") |
|
|
|
|
|
|
|
|
|
test = &Test{ |
|
|
|
|
Errs: []string{"ok", "ok", ""}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
errs = validate.Struct(test) |
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
|
Equal(t, len(errs.Errors), 1) |
|
|
|
|
|
|
|
|
|
fieldErr, ok = errs.Errors["Errs"] |
|
|
|
|
Equal(t, ok, true) |
|
|
|
|
Equal(t, fieldErr.IsPlaceholderErr, true) |
|
|
|
|
Equal(t, fieldErr.IsSliceOrArray, true) |
|
|
|
|
Equal(t, len(fieldErr.SliceOrArrayErrs), 1) |
|
|
|
|
|
|
|
|
|
innerErr, ok = fieldErr.SliceOrArrayErrs[2].(*FieldError) |
|
|
|
|
Equal(t, ok, true) |
|
|
|
|
Equal(t, innerErr.Tag, required) |
|
|
|
|
Equal(t, innerErr.IsPlaceholderErr, false) |
|
|
|
|
Equal(t, innerErr.Field, "Errs[2]") |
|
|
|
|
|
|
|
|
|
type TestMultiDimensional struct { |
|
|
|
|
Errs [][]string `validate:"gt=0,dive,dive,required"` |
|
|
|
@ -283,25 +283,17 @@ func TestArrayDiveValidation(t *testing.T) { |
|
|
|
|
|
|
|
|
|
errArray = append(errArray, []string{"ok", "", ""}) |
|
|
|
|
errArray = append(errArray, []string{"ok", "", ""}) |
|
|
|
|
// fmt.Println(len(errArray))
|
|
|
|
|
// errArray = append(errArray, []string{"", "ok", "ok"})
|
|
|
|
|
// errArray = append(errArray, []string{"", "", "ok"})
|
|
|
|
|
// errArray = append(errArray, []string{"", "", "ok"})
|
|
|
|
|
|
|
|
|
|
tm := &TestMultiDimensional{ |
|
|
|
|
Errs: errArray, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
errs := validate.Struct(tm) |
|
|
|
|
fmt.Println(errs) |
|
|
|
|
// validate.Struct(tm)
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("%#v\n", errs.Errors["Errs"].SliceOrArrayErrs)
|
|
|
|
|
errs = validate.Struct(tm) |
|
|
|
|
|
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
|
Equal(t, len(errs.Errors), 1) |
|
|
|
|
|
|
|
|
|
fieldErr, ok := errs.Errors["Errs"] |
|
|
|
|
fieldErr, ok = errs.Errors["Errs"] |
|
|
|
|
Equal(t, ok, true) |
|
|
|
|
Equal(t, fieldErr.IsPlaceholderErr, true) |
|
|
|
|
Equal(t, fieldErr.IsSliceOrArray, true) |
|
|
|
@ -319,14 +311,6 @@ func TestArrayDiveValidation(t *testing.T) { |
|
|
|
|
Equal(t, innerSliceError1.Tag, required) |
|
|
|
|
Equal(t, innerSliceError1.IsSliceOrArray, false) |
|
|
|
|
Equal(t, len(innerSliceError1.SliceOrArrayErrs), 0) |
|
|
|
|
// fmt.Println(fieldErr.SliceOrArrayErrs)
|
|
|
|
|
|
|
|
|
|
// Equal(t, fieldErr.IsPlaceholderErr, true)
|
|
|
|
|
// Equal(t, fieldErr.IsSliceOrArray, true)
|
|
|
|
|
// Equal(t, len(fieldErr.SliceOrArrayErrs), 3)
|
|
|
|
|
|
|
|
|
|
// fmt.Println(fieldErr.SliceOrArrayErrs)
|
|
|
|
|
// fmt.Println(len(fieldErr.SliceOrArrayErrs))
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestNilStructPointerValidation(t *testing.T) { |
|
|
|
|