assertables

Macro assert_io_read_to_string_matches

source
macro_rules! assert_io_read_to_string_matches {
    ($a_reader:expr, $b_matcher:expr $(,)?) => { ... };
    ($a_reader:expr, $b_matcher:expr, $($message:tt)+) => { ... };
}
Expand description

Assert a std::io::Read read_to_string() is a match to a regex.

Pseudocode:
(reader.read_to_string(a) ⇒ a) matches matcher

  • If true, return ().

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

§Examples

use assertables::*;
use std::io::Read;
use regex::Regex;

let mut reader = "hello".as_bytes();
let matcher = Regex::new(r"ell").unwrap();
assert_io_read_to_string_matches!(reader, &matcher);

// This will panic
let mut reader = "hello".as_bytes();
let matcher = Regex::new(r"zz").unwrap();
assert_io_read_to_string_matches!(reader, &matcher);
// assertion failed: `assert_io_read_to_string_matches!(a_reader, &matcher)`
// https://docs.rs/assertables/8.18.0/assertables/macro.assert_io_read_to_string_matches.html
//   reader label: `reader`,
//   reader debug: `[]`,
//  matcher label: `&matcher`,
//  matcher debug: `Regex(\"zz\")`,
//  reader string: `\"hello\"`

§Module macros