Macro assertables::assert_fn_gt
source · macro_rules! assert_fn_gt { ($a_function:path, $a_param:expr, $b_function:path, $b_param:expr) => { ... }; ($a_function:path, $a_param:expr, $b_function:path, $b_param:expr, $($message:tt)+) => { ... }; ($a_function:path, $b_function:path) => { ... }; ($a_function:path, $b_function:path, $($message:tt)+) => { ... }; }
Expand description
Assert a function output is greater than another.
-
If true, return
()
. -
Otherwise, call
panic!
with a message and the values of the expressions with their debug representations.
Examples
// Return Ok
let a: i8 = -2;
let b: i8 = 1;
assert_fn_gt!(i8::abs, a, i8::abs, b);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let a: i8 = 1;
let b: i8 = -2;
assert_fn_gt!(i8::abs, a, i8::abs, b);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_fn_gt!(left_function, left_param, right_function, right_param)`\n",
" left_function label: `i8::abs`,\n",
" left_param label: `a`,\n",
" left_param debug: `1`,\n",
" right_function label: `i8::abs`,\n",
" right_param label: `b`,\n",
" right_param debug: `-2`,\n",
" left: `1`,\n",
" right: `2`"
);
assert_eq!(actual, expect);