Module lib::assert_fn_ok
source · Expand description
Assert macros for comparing functions that return Result::Ok.
These macros help compare functions that return results that are ok, such as
std::Result::Ok or similar.
The macros use these capabilities:
-
implements
.is_ok() -> boolean -
implements
.unwrap_ok() -> comparable
Compare a function Ok() with another function Ok():
-
assert_fn_ok_eq!(function1, function2)≈ function1().unwrap_err() = function2().unwrap_err() -
assert_fn_ok_ne!(function1, function2)≈ function1().unwrap_err() ≠ function2().unwrap_err() -
assert_fn_ok_ge!(function1, function2)≈ function1().unwrap_err() ≥ function2().unwrap_err() -
assert_fn_ok_gt!(function1, function2)≈ function1().unwrap_err() > function2().unwrap_err() -
assert_fn_ok_le!(function1, function2)≈ function1().unwrap_err() ≤ function2().unwrap_err() -
assert_fn_ok_lt!(function1, function2)≈ function1().unwrap_err() < function2().unwrap_err()
Compare a function Ok() with an expression:
-
assert_fn_ok_eq!(function, expr)≈ function().unwrap_err() = expr -
assert_fn_ok_ne!(function, expr)≈ function().unwrap_err() ≠ expr -
assert_fn_ok_ge!(function, expr)≈ function().unwrap_err() ≥ expr -
assert_fn_ok_gt!(function, expr)≈ function().unwrap_err() > expr -
assert_fn_ok_le!(function, expr)≈ function().unwrap_err() ≤ expr -
assert_fn_ok_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 = 1;
let b: i8 = 1;
assert_fn_ok_eq!(f, a, f, b);Modules§
- Assert a function Ok(…) is equal to another.
- Assert a function Ok(…) is equal to an expression.
- Assert a function Ok(…) is greater than or equal to another.
- Assert a function Ok(…) is greater than or equal to an expression.
- Assert a function Ok(…) is greater than another.
- Assert a function Ok(…) is greater than an expression.
- Assert a function Ok(…) is less than or equal to another.
- Assert a function Ok(…) is less than or equal to an expression.
- Assert a function Ok(…) is less than another.
- Assert a function Ok(…) is less than an expression.
- Assert a function Ok(…) is not equal to another.
- Assert a function Ok(…) is not equal to an expression.