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

Assert one function ok() is greater than another.

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

  • Otherwise, return Result Err with a diagnostic message.

Examples

fn example_digit_to_string(i: i32) -> Result<String, String> {
    match i {
        0..=9 => Ok(format!("{}", i)),
        _ => Err(format!("{:?} is out of range", i)),
    }
}

let a: i32 = 2;
let b = String::from("1");
let x = assert_fn_ok_gt_as_result!(example_digit_to_string, a, b);
//-> Ok(())
let actual = x.unwrap();
let expect = ();
assert_eq!(actual, expect);

let a: i32 = 1;
let b = String::from("2");
let x = assert_fn_ok_gt_as_result!(example_digit_to_string, a, b);
//-> Err(…)
let actual = x.unwrap_err();
let expect = concat!(
    "assertion failed: `assert_fn_ok_gt!(left_function, left_input, right_expr)`\n",
    " left_function label: `example_digit_to_string`,\n",
    "    left_input label: `a`,\n",
    "    left_input debug: `1`,\n",
    "    right_expr label: `b`,\n",
    "    right_expr debug: `\"2\"`,\n",
    "                left: `\"1\"`,\n",
    "               right: `\"2\"`"
);
assert_eq!(actual, expect);