1 macro_rules
! searcher
{
2 ($name
:ident
, $re
:expr
, $haystack
:expr
) => (
3 searcher
!($name
, $re
, $haystack
, vec vec
![]);
5 ($name
:ident
, $re
:expr
, $haystack
:expr
, $
($steps
:expr
,)*) => (
6 searcher
!($name
, $re
, $haystack
, vec vec
![$
($steps
),*]);
8 ($name
:ident
, $re
:expr
, $haystack
:expr
, $
($steps
:expr
),*) => (
9 searcher
!($name
, $re
, $haystack
, vec vec
![$
($steps
),*]);
11 ($name
:ident
, $re
:expr
, $haystack
:expr
, vec $expect_steps
:expr
) => (
13 #[allow(unused_imports)]
16 use std
::str::pattern
::{Pattern, Searcher}
;
17 use std
::str::pattern
::SearchStep
::{Match, Reject, Done}
;
19 let mut se
= re
.into_searcher($haystack
);
20 let mut got_steps
= vec
![];
24 step
=> { got_steps.push(step); }
27 assert_eq
!(got_steps
, $expect_steps
);
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",
39 searcher
!(searcher_no_match
, r
"\d", "a",
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",
54 searcher
!(searcher_many_zero_length_matches
, r
"\d*", "a1bbb2",
62 Reject(4, 5), // a1bbb
63 Match(5, 6), // a1bbba
65 searcher
!(searcher_unicode
, r
".+?", "Ⅰ1Ⅱ2",
66 Match(0, 3), Match(3, 4), Match(4, 7), Match(7, 8));