Expand description
Assert 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() -> bool -
implements
.unwrap_err() -> comparable
Compare a function Err() with another function Err():
assert_fn_err_eq!(a_function, b_function)≈ a_function().unwrap_err() = b_function().unwrap_err()assert_fn_err_ne!(a_function, b_function)≈ a_function().unwrap_err() ≠ b_function().unwrap_err()assert_fn_err_ge!(a_function, b_function)≈ a_function().unwrap_err() ≥ b_function().unwrap_err()assert_fn_err_gt!(a_function, b_function)≈ a_function().unwrap_err() > b_function().unwrap_err()assert_fn_err_le!(a_function, b_function)≈ a_function().unwrap_err() ≤ b_function().unwrap_err()assert_fn_err_lt!(a_function, b_function)≈ a_function().unwrap_err() < b_function().unwrap_err()
Compare a function Err() with an expression:
assert_fn_err_eq_x!(function, expr)≈ function().unwrap_err() = exprassert_fn_err_ne_x!(function, expr)≈ function().unwrap_err() ≠ exprassert_fn_err_ge_x!(function, expr)≈ function().unwrap_err() ≥ exprassert_fn_err_gt_x!(function, expr)≈ function().unwrap_err() > exprassert_fn_err_le_x!(function, expr)≈ function().unwrap_err() ≤ exprassert_fn_err_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 = 10;
let b: i8 = 10;
assert_fn_err_eq!(f, a, f, b);Modules§
- assert_
fn_ err_ eq - Assert a function Err(…) is equal to another.
- assert_
fn_ err_ eq_ x - Assert a function Err(…) is equal to an expression.
- assert_
fn_ err_ ge - Assert a function Err(…) is greater than or equal to another.
- assert_
fn_ err_ ge_ x - Assert a function Err(…) is greater than or equal to an expression.
- assert_
fn_ err_ gt - Assert a function Err(…) is greater than another.
- assert_
fn_ err_ gt_ x - Assert a function Err(…) is greater than an expression.
- assert_
fn_ err_ le - Assert a function Err(…) is less than or equal to another.
- assert_
fn_ err_ le_ x - Assert a function Err(…) is less than or equal to an expression.
- assert_
fn_ err_ lt - Assert a function Err(…) is less than another.
- assert_
fn_ err_ lt_ x - Assert a function Err(…) is less than an expression.
- assert_
fn_ err_ ne - Assert a function Err(…) is not equal to another.
- assert_
fn_ err_ ne_ x - Assert a function Err(…) is not equal to an expression.