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

Assert a function ok() is not equal to another.

  • If 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: i32 = 1;
let b = String::from("2");
assert_fn_ok_ne!(example_digit_to_string, a, b);
//-> ()

let result = panic::catch_unwind(|| {
let a: i32 = 1;
let b = String::from("1");
assert_fn_ok_ne!(example_digit_to_string, a, b);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
    "assertion failed: `assert_fn_ok_ne!(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: `\"1\"`,\n",
    "                left: `\"1\"`,\n",
    "               right: `\"1\"`"
);
assert_eq!(actual, expect);