Macro assertables::assert_fn_lt
source · macro_rules! assert_fn_lt {
($function:path, $a_input:expr, $b_expr:expr $(,)?) => { ... };
($function:path, $a_input:expr, $b_expr:expr, $($message:tt)+) => { ... };
}Expand description
Assert a function output is less than an expression.
-
If true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
Examples
// Return Ok
let a: i32 = -1;
let b: i32 = 2;
assert_fn_lt!(i32::abs, a, b);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let a: i32 = -2;
let b: i32 = 1;
assert_fn_lt!(i32::abs, a, b);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_fn_lt!(left_function, left_input, right_expr)`\n",
" left_function label: `i32::abs`,\n",
" left_input label: `a`,\n",
" left_input debug: `-2`,\n",
" right_expr label: `b`,\n",
" right_expr debug: `1`,\n",
" left: `2`,\n",
" right: `1`"
);
assert_eq!(actual, expect);