macro_rules! assertable_f_err_string_eq {
($function:path, $left:expr, $right:expr $(,)?) => { ... };
($function:path, $left:expr, $right:expr, $($arg:tt)+) => { ... };
}Expand description
Assert one function ok() is equal to another function ok().
-
When true, return
Ok(()). -
Otherwise, return
Errwith a message and the values of the expressions with their debug representations.
Examples
fn example_digit_to_string(i: isize) -> Result<String, String> {
match i {
0..=9 => Ok(format!("{}", i)),
_ => Err(format!("{:?} is out of range", i)),
}
}
let x = assertable_f_err_string_eq!(example_digit_to_string, 10, 10);
//-> Ok(())
assert_eq!(x.unwrap(), ());
let x = assertable_f_err_string_eq!(example_digit_to_string, 10, 20);
//-> Err("…")
// assertable failed: `assertable_f_err_string_eq!(function, left, right)`
// function: `\"example_digit_to_string\"`,
// left input: `10`,
// right input: `20`,
// left output: `\"10 is out of range\"`,
// right output: `\"20 is out of range\"`
assert_eq!(x.unwrap_err(), "assertable failed: `assertable_f_err_string_eq!(function, left, right)`\n function: `\"example_digit_to_string\"`,\n left input: `10`,\n right input: `20`,\n left is err: `true`,\n right is err: `true`,\n left output: `\"10 is out of range\"`,\n right output: `\"20 is out of range\"`".to_string());This macro has a second form where a custom message can be provided.