blob: 480116da739fe8000cd8faf0b43282c2b1e60399 [file] [log] [blame]
Chih-Hung Hsiehe42c5052020-04-16 10:44:21 -07001// These tests don't really make sense with the bytes API, so we only test them
2// on the Unicode API.
3
4#[test]
5fn 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!(
10 vec![(0, 0), (3, 3), (4, 4), (7, 7), (8, 8)],
11 findall!(re, "Ⅰ1Ⅱ2")
12 );
13}
14
15#[test]
16fn empty_match_unicode_captures_iter() {
17 // Same as empty_match_unicode_find_iter, but tests capture iteration.
18 let re = regex!(r".*?");
19 let ms: Vec<_> = re
20 .captures_iter(text!("Ⅰ1Ⅱ2"))
21 .map(|c| c.get(0).unwrap())
22 .map(|m| (m.start(), m.end()))
23 .collect();
24 assert_eq!(vec![(0, 0), (3, 3), (4, 4), (7, 7), (8, 8)], ms);
25}
26
27#[test]
28fn match_as_str() {
29 let re = regex!(r"fo+");
30 let caps = re.captures("barfoobar").unwrap();
31 assert_eq!(caps.get(0).map(|m| m.as_str()), Some("foo"));
32 assert_eq!(caps.get(0).map(From::from), Some("foo"));
33 assert_eq!(caps.get(0).map(Into::into), Some("foo"));
34}