Skip to content

Commit

Permalink
tests: Fix invalid custom test
Browse files Browse the repository at this point in the history
In the custom tests, only the first test case is ever checked, if the
value is above zero. Fix this by inverting the conditions and letting
the function return Ok later. Returning Ok was already present in the
function.

Signed-off-by: Esa Laakso <[email protected]>
  • Loading branch information
efdx committed Jul 9, 2024
1 parent fc5ae84 commit ca2045c
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions serde_valid/src/validation/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ mod 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 Down

0 comments on commit ca2045c

Please sign in to comment.