]>
Commit | Line | Data |
---|---|---|
94b46f34 XL |
1 | // These tests don't really make sense with the bytes API, so we only test them |
2 | // on the Unicode API. | |
3 | ||
4 | #[test] | |
5 | fn empty_match_unicode_find_iter() { | |
6 | // Tests that we still yield byte ranges at valid UTF-8 sequence boundaries | |
7 | // even when we're susceptible to empty width matches. | |
8 | let re = regex!(r".*?"); | |
9 | assert_eq!(vec![(0, 0), (3, 3), (4, 4), (7, 7), (8, 8)], | |
10 | findall!(re, "Ⅰ1Ⅱ2")); | |
11 | } | |
12 | ||
13 | #[test] | |
14 | fn empty_match_unicode_captures_iter() { | |
15 | // Same as empty_match_unicode_find_iter, but tests capture iteration. | |
16 | let re = regex!(r".*?"); | |
17 | let ms: Vec<_> = re.captures_iter(text!("Ⅰ1Ⅱ2")) | |
18 | .map(|c| c.get(0).unwrap()) | |
19 | .map(|m| (m.start(), m.end())) | |
20 | .collect(); | |
21 | assert_eq!(vec![(0, 0), (3, 3), (4, 4), (7, 7), (8, 8)], ms); | |
22 | } | |
23 | ||
24 | #[test] | |
25 | fn match_as_str() { | |
26 | let re = regex!(r"fo+"); | |
27 | let caps = re.captures("barfoobar").unwrap(); | |
28 | assert_eq!(caps.get(0).map(|m| m.as_str()), Some("foo")); | |
29 | assert_eq!(caps.get(0).map(From::from), Some("foo")); | |
30 | assert_eq!(caps.get(0).map(Into::into), Some("foo")); | |
31 | } |