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