]>
Commit | Line | Data |
---|---|---|
94b46f34 XL |
1 | macro_rules! searcher { |
2 | ($name:ident, $re:expr, $haystack:expr) => ( | |
3 | searcher!($name, $re, $haystack, vec vec![]); | |
4 | ); | |
5 | ($name:ident, $re:expr, $haystack:expr, $($steps:expr,)*) => ( | |
6 | searcher!($name, $re, $haystack, vec vec![$($steps),*]); | |
7 | ); | |
8 | ($name:ident, $re:expr, $haystack:expr, $($steps:expr),*) => ( | |
9 | searcher!($name, $re, $haystack, vec vec![$($steps),*]); | |
10 | ); | |
11 | ($name:ident, $re:expr, $haystack:expr, vec $expect_steps:expr) => ( | |
12 | #[test] | |
13 | #[allow(unused_imports)] | |
14 | fn $name() { | |
15 | searcher_expr! {{ | |
16 | use std::str::pattern::{Pattern, Searcher}; | |
17 | use std::str::pattern::SearchStep::{Match, Reject, Done}; | |
18 | let re = regex!($re); | |
19 | let mut se = re.into_searcher($haystack); | |
20 | let mut got_steps = vec![]; | |
21 | loop { | |
22 | match se.next() { | |
23 | Done => break, | |
24 | step => { got_steps.push(step); } | |
25 | } | |
26 | } | |
27 | assert_eq!(got_steps, $expect_steps); | |
28 | }} | |
29 | } | |
30 | ); | |
31 | } | |
32 | ||
33 | searcher!(searcher_empty_regex_empty_haystack, r"", "", Match(0, 0)); | |
34 | searcher!(searcher_empty_regex, r"", "ab", | |
35 | Match(0, 0), Reject(0, 1), Match(1, 1), Reject(1, 2), Match(2, 2)); | |
36 | searcher!(searcher_empty_haystack, r"\d", ""); | |
37 | searcher!(searcher_one_match, r"\d", "5", | |
38 | Match(0, 1)); | |
39 | searcher!(searcher_no_match, r"\d", "a", | |
40 | Reject(0, 1)); | |
41 | searcher!(searcher_two_adjacent_matches, r"\d", "56", | |
42 | Match(0, 1), Match(1, 2)); | |
43 | searcher!(searcher_two_non_adjacent_matches, r"\d", "5a6", | |
44 | Match(0, 1), Reject(1, 2), Match(2, 3)); | |
45 | searcher!(searcher_reject_first, r"\d", "a6", | |
46 | Reject(0, 1), Match(1, 2)); | |
47 | searcher!(searcher_one_zero_length_matches, r"\d*", "a1b2", | |
48 | Match(0, 0), // ^ | |
49 | Reject(0, 1), // a | |
50 | Match(1, 2), // a1 | |
51 | Reject(2, 3), // a1b | |
52 | Match(3, 4), // a1b2 | |
53 | ); | |
54 | searcher!(searcher_many_zero_length_matches, r"\d*", "a1bbb2", | |
55 | Match(0, 0), // ^ | |
56 | Reject(0, 1), // a | |
57 | Match(1, 2), // a1 | |
58 | Reject(2, 3), // a1b | |
59 | Match(3, 3), // a1bb | |
60 | Reject(3, 4), // a1bb | |
61 | Match(4, 4), // a1bbb | |
62 | Reject(4, 5), // a1bbb | |
63 | Match(5, 6), // a1bbba | |
64 | ); | |
65 | searcher!(searcher_unicode, r".+?", "Ⅰ1Ⅱ2", | |
66 | Match(0, 3), Match(3, 4), Match(4, 7), Match(7, 8)); |