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