Skip to content

Commit 430e946

Browse files
authored
Merge pull request #82 from Esco441-91/bugix/fix-invalid-test
Fix invalid custom test case
2 parents 204e76f + ca2045c commit 430e946

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

serde_valid/src/validation/custom.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,21 @@ mod test {
4747
}
4848

4949
assert!(wrap_closure_validation(&1i32, single_error).is_ok());
50+
assert!(wrap_closure_validation(&0i32, single_error).is_err());
51+
assert!(wrap_closure_validation(&-1i32, single_error).is_err());
5052
}
5153

5254
#[test]
5355
fn test_custom_fn_multiple_errors() {
5456
fn multiple_errors(data: &i32) -> Result<(), Vec<crate::validation::Error>> {
5557
let mut errors = Vec::new();
56-
if *data > 0 {
57-
return Ok(());
58-
} else {
58+
if *data < 1 {
5959
errors.push(crate::validation::Error::Custom(
6060
"Value must be greater than 0".to_string(),
6161
));
6262
}
6363

64-
if *data < 10 {
65-
return Ok(());
66-
} else {
64+
if *data >= 10 {
6765
errors.push(crate::validation::Error::Custom(
6866
"Value must be less than 10".to_string(),
6967
));
@@ -77,5 +75,9 @@ mod test {
7775
}
7876

7977
assert!(wrap_closure_validation(&1i32, multiple_errors).is_ok());
78+
assert!(wrap_closure_validation(&10i32, multiple_errors).is_err());
79+
assert!(wrap_closure_validation(&11i32, multiple_errors).is_err());
80+
assert!(wrap_closure_validation(&0i32, multiple_errors).is_err());
81+
assert!(wrap_closure_validation(&-1i32, multiple_errors).is_err());
8082
}
8183
}

0 commit comments

Comments
 (0)