1// Macros for use in writing tests generic over &str/&[u8].
2macro_rules! text { ($text:expr) => { $text } }
3macro_rules! t { ($text:expr) => { text!($text) } }
4macro_rules! match_text { ($text:expr) => { $text.as_str() } }
5macro_rules! use_ { ($($path: tt)*) => { use regex::$($path)*; } }
6macro_rules! empty_vec { () => { <Vec<&str>>::new() } }
7macro_rules! bytes { ($text:expr) => { std::str::from_utf8($text.as_ref()).unwrap() } }
8
9macro_rules! no_expand {
10    ($text:expr) => {{
11        use regex::NoExpand;
12        NoExpand(text!($text))
13    }}
14}
15
16macro_rules! show { ($text:expr) => { $text } }
17
18// N.B. The expansion API for &str and &[u8] APIs differs slightly for now,
19// but they should be unified in 1.0. Then we can move this macro back into
20// tests/api.rs where it is used. ---AG
21macro_rules! expand {
22    ($name:ident, $re:expr, $text:expr, $expand:expr, $expected:expr) => {
23        #[test]
24        fn $name() {
25            let re = regex!($re);
26            let cap = re.captures(t!($text)).unwrap();
27
28            let mut got = String::new();
29            cap.expand(t!($expand), &mut got);
30            assert_eq!(show!(t!($expected)), show!(&*got));
31        }
32    }
33}
34
35#[cfg(feature = "pattern")]
36macro_rules! searcher_expr { ($e:expr) => ($e) }
37#[cfg(not(feature = "pattern"))]
38macro_rules! searcher_expr { ($e:expr) => ({}) }
39