diff --git a/serde_valid/src/validation/custom.rs b/serde_valid/src/validation/custom.rs index 16aa25a..7c2b278 100644 --- a/serde_valid/src/validation/custom.rs +++ b/serde_valid/src/validation/custom.rs @@ -47,23 +47,21 @@ mod test { } assert!(wrap_closure_validation(&1i32, single_error).is_ok()); + assert!(wrap_closure_validation(&0i32, single_error).is_err()); + assert!(wrap_closure_validation(&-1i32, single_error).is_err()); } #[test] fn test_custom_fn_multiple_errors() { fn multiple_errors(data: &i32) -> Result<(), Vec> { let mut errors = Vec::new(); - if *data > 0 { - return Ok(()); - } else { + if *data < 1 { errors.push(crate::validation::Error::Custom( "Value must be greater than 0".to_string(), )); } - if *data < 10 { - return Ok(()); - } else { + if *data >= 10 { errors.push(crate::validation::Error::Custom( "Value must be less than 10".to_string(), )); @@ -77,5 +75,9 @@ mod test { } assert!(wrap_closure_validation(&1i32, multiple_errors).is_ok()); + assert!(wrap_closure_validation(&10i32, multiple_errors).is_err()); + assert!(wrap_closure_validation(&11i32, multiple_errors).is_err()); + assert!(wrap_closure_validation(&0i32, multiple_errors).is_err()); + assert!(wrap_closure_validation(&-1i32, multiple_errors).is_err()); } }