We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 06f9224 commit 9593a0fCopy full SHA for 9593a0f
validator_test.go
@@ -8839,3 +8839,28 @@ func TestLookup(t *testing.T) {
8839
}
8840
Equal(t, New().Struct(lookup), nil)
8841
8842
+
8843
+func TestAbilityToValidateNils(t *testing.T) {
8844
8845
+ type TestStruct struct {
8846
+ Test *string `validate:"nil"`
8847
+ }
8848
8849
+ ts := TestStruct{}
8850
+ val := New()
8851
+ fn := func(fl FieldLevel) bool {
8852
+ return fl.Field().Kind() == reflect.Ptr && fl.Field().IsNil()
8853
8854
8855
+ err := val.RegisterValidation("nil", fn, true)
8856
+ Equal(t, err, nil)
8857
8858
+ errs := val.Struct(ts)
8859
+ Equal(t, errs, nil)
8860
8861
+ str := "string"
8862
+ ts.Test = &str
8863
8864
+ errs = val.Struct(ts)
8865
+ NotEqual(t, errs, nil)
8866
+}
0 commit comments