Macro assertables::assert_fn_lt_other
source · [−]macro_rules! assert_fn_lt_other {
($function:path, $a_input:expr, $b_input:expr $(,)?) => { ... };
($function:path, $a_input:expr, $b_input:expr, $($arg:tt)+) => { ... };
}Expand description
Assert a function output is less than another.
-
When true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
Examples
let a: i32 = 1;
let b: i32 = -2;
assert_fn_lt_other!(i32::abs, a, b);
//-> ()
let a: i32 = -2;
let b: i32 = 1;
let result = panic::catch_unwind(|| {
assert_fn_lt_other!(i32::abs, a, b);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_fn_lt_other!(function, left_input, right_input)`\n",
" function name: `i32::abs`,\n",
" left input name: `a`,\n",
" right input name: `b`,\n",
" left input: `-2`,\n",
" right input: `1`,\n",
" left output: `2`,\n",
" right output: `1`"
);
assert_eq!(actual, expect);