macro_rules! assert_fn_err_le_expr { ($a_function:path, $a_param:expr, $b_expr:expr $(,)?) => { ... }; ($a_function:path, $a_param:expr, $b_expr:expr, $($message:tt)+) => { ... }; ($a_function:path, $b_expr:expr $(,)?) => { ... }; ($a_function:path, $b_expr:expr, $($message:tt)+) => { ... }; }
Expand description
Assert a function error is less than or equal to an expression.
Pseudocode:
(function(param) ⇒ Err(a) ⇒ a) ≤ expr
-
If true, return
()
. -
Otherwise, call
panic!
with a message and the values of the expressions with their debug representations.
§Examples
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 = String::from("20 is out of range");
assert_fn_err_le_expr!(f, a, b);
let a: i8 = 20;
let b = String::from("10 is out of range");
assert_fn_err_le_expr!(f, a, b);
// assertion failed: `assert_fn_err_le_expr!(a_function, a_param, b_expr)`
// https://docs.rs/assertables/8.9.0/assertables/macro.assert_fn_err_le_expr.html
// a_function label: `f`,
// a_param label: `a`,
// a_param debug: `20`,
// b_expr label: `b`,
// b_expr debug: `\"10 is out of range\"`,
// a: `\"20 is out of range\"`,
// b: `\"10 is out of range\"`