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

Assert one function output is less than another.

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

  • When true, return Result Err with a diagnostic message.

Examples

let a: i32 = 1;
let b: i32 = -2;
let x = assert_fn_lt_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_lt_other_as_result!(i32::abs, a, b);
//-> Err(…)
let actual = x.unwrap_err();
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);