]> git.proxmox.com Git - rustc.git/blob - vendor/regex-1.4.3/tests/api_str.rs
New upstream version 1.54.0+dfsg1
[rustc.git] / vendor / regex-1.4.3 / tests / api_str.rs
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!(
10 vec![(0, 0), (3, 3), (4, 4), (7, 7), (8, 8)],
11 findall!(re, "Ⅰ1Ⅱ2")
12 );
13 }
14
15 #[test]
16 fn 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]
28 fn 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 }