corresponds to boolean value of nefield (#712)

pull/753/merge
Peperoncino 4 years ago committed by GitHub
parent 882ec0def4
commit 5b8f3b8a0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      baked_in.go
  2. 5
      validator_test.go

@ -791,6 +791,9 @@ func isNeField(fl FieldLevel) bool {
case reflect.Slice, reflect.Map, reflect.Array: case reflect.Slice, reflect.Map, reflect.Array:
return int64(field.Len()) != int64(currentField.Len()) return int64(field.Len()) != int64(currentField.Len())
case reflect.Bool:
return field.Bool() != currentField.Bool()
case reflect.Struct: case reflect.Struct:
fieldType := field.Type() fieldType := field.Type()

@ -4589,6 +4589,7 @@ func TestIsNeFieldValidation(t *testing.T) {
i := 1 i := 1
j = 1 j = 1
k = 1.543 k = 1.543
b := true
arr := []string{"test"} arr := []string{"test"}
now := time.Now().UTC() now := time.Now().UTC()
@ -4598,6 +4599,7 @@ func TestIsNeFieldValidation(t *testing.T) {
i2 := 3 i2 := 3
j2 = 2 j2 = 2
k2 = 1.5434456 k2 = 1.5434456
b2 := false
arr2 := []string{"test", "test2"} arr2 := []string{"test", "test2"}
arr3 := []string{"test"} arr3 := []string{"test"}
now2 := now now2 := now
@ -4614,6 +4616,9 @@ func TestIsNeFieldValidation(t *testing.T) {
errs = validate.VarWithValue(k2, k, "nefield") errs = validate.VarWithValue(k2, k, "nefield")
Equal(t, errs, nil) Equal(t, errs, nil)
errs = validate.VarWithValue(b2, b, "nefield")
Equal(t, errs, nil)
errs = validate.VarWithValue(arr2, arr, "nefield") errs = validate.VarWithValue(arr2, arr, "nefield")
Equal(t, errs, nil) Equal(t, errs, nil)

Loading…
Cancel
Save