diff --git a/validator_test.go b/validator_test.go index 48b0f84..6f42a91 100644 --- a/validator_test.go +++ b/validator_test.go @@ -8839,3 +8839,28 @@ func TestLookup(t *testing.T) { } Equal(t, New().Struct(lookup), nil) } + +func TestAbilityToValidateNils(t *testing.T) { + + type TestStruct struct { + Test *string `validate:"nil"` + } + + ts := TestStruct{} + val := New() + fn := func(fl FieldLevel) bool { + return fl.Field().Kind() == reflect.Ptr && fl.Field().IsNil() + } + + err := val.RegisterValidation("nil", fn, true) + Equal(t, err, nil) + + errs := val.Struct(ts) + Equal(t, errs, nil) + + str := "string" + ts.Test = &str + + errs = val.Struct(ts) + NotEqual(t, errs, nil) +}