diff options
author | Kartikaya Gupta <kgupta@mozilla.com> | 2016-06-08 10:28:24 -0400 |
---|---|---|
committer | Kartikaya Gupta <kgupta@mozilla.com> | 2016-06-08 10:28:24 -0400 |
commit | 9bd405a328f9119ab6d2a1feed79643316e6f254 (patch) | |
tree | 9e6d18823c875d51f3e1e3cc0c32253e2612faff | |
parent | d6f0e2530ec6cfbdd50e23afaadeaf538120b293 (diff) |
Add a simple assert_match macro for help with testing
-rw-r--r-- | src/lib.rs | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -336,6 +336,15 @@ pub fn parse_headers(raw_data: &[u8]) -> Result<(Vec<MailHeader>, usize), MailPa mod tests { use super::*; + macro_rules! assert_match { + ( $x:expr, $p:pat ) => { + match $x { + $p => (), + _ => panic!("Expression {} does not match given pattern", $x), + } + } + } + #[test] fn parse_basic_header() { let (parsed, _) = parse_header(b"Key: Value").unwrap(); @@ -474,13 +483,7 @@ mod tests { assert_eq!(parsed.get_first_value("NoKey").unwrap(), None); assert_eq!(parsed.get_all_values("NoKey").unwrap(), Vec::<String>::new()); - assert!(match parse_headers(b"Bad\nKey").unwrap_err() { - MailParseError::Generic(_, 3) => true, - _ => false, - }); - assert!(match parse_headers(b"K:V\nBad\nKey").unwrap_err() { - MailParseError::Generic(_, 7) => true, - _ => false, - }); + assert_match!(parse_headers(b"Bad\nKey").unwrap_err(), MailParseError::Generic(_, 3)); + assert_match!(parse_headers(b"K:V\nBad\nKey").unwrap_err(), MailParseError::Generic(_, 7)); } } |