macro_rules! assert_fn_err_lt {
    ($a_function:path, $a_param:expr, $b_function:path, $b_param:expr) => { ... };
    ($a_function:path, $a_param:expr, $b_function:path, $b_param:expr, $($message:tt)+) => { ... };
    ($a_function:path, $b_function:path) => { ... };
    ($a_function:path, $b_function:path, $($message:tt)+) => { ... };
}
Expand description

Assert a function err() is less than another.

  • If true, return ().

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

Examples

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

// Return Ok
let a: i8 = 10;
let b: i8 = 20;
assert_fn_err_lt!(f, a, f, b);
//-> ()

let a: i8 = 20;
let b: i8 = 10;
// Panic with error message
let result = panic::catch_unwind(|| {
assert_fn_err_lt!(f, a, f, b);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
    "assertion failed: `assert_fn_err_lt!(left_function, left_param, right_function, right_param)`\n",
    "  left_function label: `f`,\n",
    "     left_param label: `a`,\n",
    "     left_param debug: `20`,\n",
    " right_function label: `f`,\n",
    "    right_param label: `b`,\n",
    "    right_param debug: `10`,\n",
    "                 left: `\"20 is out of range\"`,\n",
    "                right: `\"10 is out of range\"`"
);
assert_eq!(actual, expect);

// Panic with error message
let result = panic::catch_unwind(|| {
assert_fn_err_lt!(f, a, f, b, "message");
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = "message";
assert_eq!(actual, expect);