macro_rules! assert_read_to_string_matches_as_result {
($a_reader:expr, $b_matcher:expr $(,)?) => { ... };
}Expand description
Assert a std::io::Read read_to_string() is a match to a regex.
-
If true, return Result
Ok(()). -
Otherwise, return Result
Errwith a diagnostic message.
Examples
use std::io::Read;
use regex::Regex;
// Return Ok
let mut reader = "hello".as_bytes();
let matcher = Regex::new(r"ell").unwrap();
assert_read_to_string_matches_as_result!(reader, matcher);
//-> ()
let mut reader = "hello".as_bytes();
let matcher = Regex::new(r"xyz").unwrap();
let x = assert_read_to_string_matches_as_result!(reader, matcher);
//-> Err(…)
assert!(x.is_err());
let actual = x.unwrap_err();
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);