macro_rules! assert_read_to_string_matches {
($a_reader:expr, $b_matcher:expr $(,)?) => { ... };
($a_reader:expr, $b_matcher:expr, $($arg:tt)+) => { ... };
}Expand description
Assert a a std::io::Read read_to_string() is a match to a given regex.
-
If true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
Examples
use std::io::Read;
use regex::Regex;
let mut reader = "hello".as_bytes();
let matcher = Regex::new(r"ell").unwrap();
assert_read_to_string_matches!(reader, matcher);
//-> ()
let result = panic::catch_unwind(|| {
let mut reader = "hello".as_bytes();
let matcher = Regex::new(r"xyz").unwrap();
assert_read_to_string_matches!(reader, matcher);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_read_to_string_matches!(left_reader, right_matcher)`\n",
" left_reader label: `reader`,\n",
" left_reader debug: `[]`,\n",
" right_matcher label: `matcher`,\n",
" right_matcher debug: `xyz`,\n",
" left: `\"hello\"`,\n",
" right: `xyz`"
);
assert_eq!(actual, expect);