Skip to content

Commit

Permalink
Merge pull request #82 from Esco441-91/bugix/fix-invalid-test
Browse files Browse the repository at this point in the history
Fix invalid custom test case
  • Loading branch information
yassun7010 authored Jul 9, 2024
2 parents 204e76f + ca2045c commit 430e946
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions serde_valid/src/validation/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::validation::Error>> {
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(),
));
Expand All @@ -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());
}
}

0 comments on commit 430e946

Please sign in to comment.