Module assertables::assert_fn_err
source · Expand description
Assert macros for comparing functions that return errors.
These macros help compare functions that return results that are errors,
such as std::Result::Err or similar.
The macros use these capabilities:
-
implements
.is_err() -> boolean -
implements
.unwrap_err() -> comparable
Compare a function Err() with another function Err():
-
assert_fn_err_eq!(function1, function2)≈ function1().unwrap_err() = function2().unwrap_err() -
assert_fn_err_ne!(function1, function2)≈ function1().unwrap_err() ≠ function2().unwrap_err() -
assert_fn_err_ge!(function1, function2)≈ function1().unwrap_err() ≥ function2().unwrap_err() -
assert_fn_err_gt!(function1, function2)≈ function1().unwrap_err() > function2().unwrap_err() -
assert_fn_err_le!(function1, function2)≈ function1().unwrap_err() ≤ function2().unwrap_err() -
assert_fn_err_lt!(function1, function2)≈ function1().unwrap_err() < function2().unwrap_err()
Compare a function Err() with an expression:
-
assert_fn_err_eq!(function, expr)≈ function().unwrap_err() = expr -
assert_fn_err_ne!(function, expr)≈ function().unwrap_err() ≠ expr -
assert_fn_err_ge!(function, expr)≈ function().unwrap_err() ≥ expr -
assert_fn_err_gt!(function, expr)≈ function().unwrap_err() > expr -
assert_fn_err_le!(function, expr)≈ function().unwrap_err() ≤ expr -
assert_fn_err_lt!(function, expr)≈ function().unwrap_err() < expr
§Example
fn f(i: i8) -> Result<String, String> {
match i {
0..=9 => Ok(format!("{}", i)),
_ => Err(format!("{:?} is out of range", i)),
}
}
let a: i8 = 10;
let b: i8 = 10;
assert_fn_err_eq!(f, a, f, b);Modules§
- Assert a function err() is equal to another.
- Assert a function err() is equal to an expression.
- Assert a function err() is greater than or equal to another.
- Assert a function err() is greater than or equal to an expression.
- Assert a function err() is greater than another.
- Assert a function err() is greater than an expression.
- Assert a function err() is less than or equal to another.
- Assert a function err() is less than or equal to an expression.
- Assert a function err() is less than another.
- Assert a function err() is less than an expression.
- Assert a function err() is not equal to another.
- Assert a function err() is not equal to an expression.