blob: 9b996b33b90fdca607eb314e169e7580b7a36a3d [file] [log] [blame]
Chih-Hung Hsiehe42c5052020-04-16 10:44:21 -07001// 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() } }
7
8macro_rules! no_expand {
9 ($text:expr) => {{
10 use regex::NoExpand;
11 NoExpand(text!($text))
12 }}
13}
14
15macro_rules! show { ($text:expr) => { $text } }
16
17// N.B. The expansion API for &str and &[u8] APIs differs slightly for now,
18// but they should be unified in 1.0. Then we can move this macro back into
19// tests/api.rs where it is used. ---AG
20macro_rules! expand {
21 ($name:ident, $re:expr, $text:expr, $expand:expr, $expected:expr) => {
22 #[test]
23 fn $name() {
24 let re = regex!($re);
25 let cap = re.captures(t!($text)).unwrap();
26
27 let mut got = String::new();
28 cap.expand(t!($expand), &mut got);
29 assert_eq!(show!(t!($expected)), show!(&*got));
30 }
31 }
32}
33
34#[cfg(feature = "pattern")]
35macro_rules! searcher_expr { ($e:expr) => ($e) }
36#[cfg(not(feature = "pattern"))]
37macro_rules! searcher_expr { ($e:expr) => ({}) }