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

Assert a function err() is less than another.

  • When true, return ().

  • Otherwise, call panic! with a message and the values of the expressions with their debug representations.

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 = 10;
let b = String::from("20 is out of range");
assert_fn_err_lt!(example_digit_to_string, a, b);
//-> ()

let result = panic::catch_unwind(|| {
let a = 20;
let b = String::from("10 is out of range");
assert_fn_err_lt!(example_digit_to_string, a, b);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
    "assertion failed: `assert_fn_err_lt!(function, left_input, right_expr)`\n",
    "    function name: `example_digit_to_string`,\n",
    "  left input name: `a`,\n",
    "  right expr name: `b`,\n",
    "       left input: `20`,\n",
    "       right expr: `\"10 is out of range\"`,\n",
    "      left output: `\"20 is out of range\"`,\n",
    "             left: `\"20 is out of range\"`,\n",
    "            right: `\"10 is out of range\"`"
);
assert_eq!(actual, expect);