Expand description
Assert 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() -> bool
-
implements
.unwrap_ok() -> comparable
Compare a function Ok() with another function Ok():
assert_fn_ok_eq!(a_function, b_function)
≈ a_function().unwrap_err() = b_function().unwrap_err()assert_fn_ok_ne!(a_function, b_function)
≈ a_function().unwrap_err() ≠ b_function().unwrap_err()assert_fn_ok_ge!(a_function, b_function)
≈ a_function().unwrap_err() ≥ b_function().unwrap_err()assert_fn_ok_gt!(a_function, b_function)
≈ a_function().unwrap_err() > b_function().unwrap_err()assert_fn_ok_le!(a_function, b_function)
≈ a_function().unwrap_err() ≤ b_function().unwrap_err()assert_fn_ok_lt!(a_function, b_function)
≈ a_function().unwrap_err() < b_function().unwrap_err()
Compare a function Ok() with an expression:
assert_fn_ok_eq_x!(function, expr)
≈ function().unwrap_err() = exprassert_fn_ok_ne_x!(function, expr)
≈ function().unwrap_err() ≠ exprassert_fn_ok_ge_x!(function, expr)
≈ function().unwrap_err() ≥ exprassert_fn_ok_gt_x!(function, expr)
≈ function().unwrap_err() > exprassert_fn_ok_le_x!(function, expr)
≈ function().unwrap_err() ≤ exprassert_fn_ok_lt_x!(function, expr)
≈ function().unwrap_err() < expr
§Example
use assertables::*;
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_
fn_ ok_ eq - Assert a function Ok(…) is equal to another.
- assert_
fn_ ok_ eq_ x - Assert a function Ok(…) is equal to an expression.
- assert_
fn_ ok_ ge - Assert a function Ok(…) is greater than or equal to another.
- assert_
fn_ ok_ ge_ x - Assert a function Ok(…) is greater than or equal to an expression.
- assert_
fn_ ok_ gt - Assert a function Ok(…) is greater than another.
- assert_
fn_ ok_ gt_ x - Assert a function Ok(…) is greater than an expression.
- assert_
fn_ ok_ le - Assert a function Ok(…) is less than or equal to another.
- assert_
fn_ ok_ le_ x - Assert a function Ok(…) is less than or equal to an expression.
- assert_
fn_ ok_ lt - Assert a function Ok(…) is less than another.
- assert_
fn_ ok_ lt_ x - Assert a function Ok(…) is less than an expression.
- assert_
fn_ ok_ ne - Assert a function Ok(…) is not equal to another.
- assert_
fn_ ok_ ne_ x - Assert a function Ok(…) is not equal to an expression.