Macro assertables::assert_is_match

source ·
macro_rules! assert_is_match {
    ($matcher:expr, $matchee:expr $(,)?) => { ... };
    ($matcher:expr, $matchee:expr, $($message:tt)+) => { ... };
}
Expand description

Assert a matcher is a match for an expression.

  • If true, return ().

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

§Examples

use std::process::Command;
use regex::Regex;

// Return Ok
let a = Regex::new(r"lf").unwrap();
let b = "alfa";
assert_is_match!(a, b);
//-> ()

// Panic with error message
let result = panic::catch_unwind(|| {
let a = Regex::new(r"lf").unwrap();
let b = "bravo";
assert_is_match!(a, b);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
    "assertion failed: `assert_is_match!(matcher, matchee)`\n",
    " matcher label: `a`,\n",
    " matcher debug: `Regex(\"lf\")`,\n",
    " matchee label: `b`,\n",
    " matchee debug: `\"bravo\"`"
);
assert_eq!(actual, expect);

§Module macros