Updating & re-injecting tests

updating test for the new error return formet
updated assertion functions to handle a nil Map,Slice,Ptr.....type
fixed hasValue check not comparing Interface but field Value.
pull/114/head
joeybloggs 9 years ago
parent 88cc19b9e1
commit 24d46304a8
  1. 2
      baked_in.go
  2. 10
      validator.go
  3. 1455
      validator_test.go

@ -408,7 +408,7 @@ func hasValue(topStruct reflect.Value, currentStruct reflect.Value, field reflec
return !field.IsNil() && int64(field.Len()) > 0 return !field.IsNil() && int64(field.Len()) > 0
default: default:
return field.IsValid() && field != reflect.Zero(fieldType).Interface() return field.IsValid() && field.Interface() != reflect.Zero(fieldType).Interface()
} }
} }

@ -111,6 +111,10 @@ func (v *Validate) Field(field interface{}, tag string) ValidationErrors {
v.traverseField(fieldVal, fieldVal, fieldVal, "", errs, false, tag, "") v.traverseField(fieldVal, fieldVal, fieldVal, "", errs, false, tag, "")
if len(errs) == 0 {
return nil
}
return errs return errs
} }
@ -122,6 +126,10 @@ func (v *Validate) FieldWithValue(val interface{}, field interface{}, tag string
v.traverseField(topVal, topVal, reflect.ValueOf(field), "", errs, false, tag, "") v.traverseField(topVal, topVal, reflect.ValueOf(field), "", errs, false, tag, "")
if len(errs) == 0 {
return nil
}
return errs return errs
} }
@ -321,7 +329,7 @@ func (v *Validate) traverseField(topStruct reflect.Value, currentStruct reflect.
v.traverseMap(topStruct, currentStruct, current, errPrefix, errs, diveSubTag, name) v.traverseMap(topStruct, currentStruct, current, errPrefix, errs, diveSubTag, name)
default: default:
// throw error, if not a slice or map then should not have gotten here // throw error, if not a slice or map then should not have gotten here
// bad dive tag usage // bad dive tag
panic("dive error! can't dive on a non slice or map") panic("dive error! can't dive on a non slice or map")
} }
} }

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save