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