macro_rules! assert_fn_le_other_as_result {
    ($function:path, $a_input:expr, $b_input:expr $(,)?) => { ... };
}
Expand description

Assert one function output is less than or equal to another function output.

  • If true, return Result Ok(()).

  • Otherwise, return Result Err with a diagnostic message.

Examples

let a: i32 = 1;
let b: i32 = -2;
let x = assert_fn_le_other_as_result!(i32::abs, a, b);
//-> Ok(())
let actual = x.unwrap();
let expect = ();
assert_eq!(actual, expect);

let a: i32 = -2;
let b: i32 = 1;
let x = assert_fn_le_other_as_result!(i32::abs, a, b);
//-> Err(…)
let actual = x.unwrap_err();
let expect = concat!(
    "assertion failed: `assert_fn_le_other!(pair_function, left_input, right_input)`\n",
    " pair_function label: `i32::abs`,\n",
    "    left_input label: `a`,\n",
    "    left_input debug: `-2`,\n",
    "   right_input label: `b`,\n",
    "   right_input debug: `1`,\n",
    "                left: `2`,\n",
    "               right: `1`"
);
assert_eq!(actual, expect);