Chih-Hung Hsieh | e42c505 | 2020-04-16 10:44:21 -0700 | [diff] [blame] | 1 | matset!(set1, &["a", "a"], "a", 0, 1); |
| 2 | matset!(set2, &["a", "a"], "ba", 0, 1); |
| 3 | matset!(set3, &["a", "b"], "a", 0); |
| 4 | matset!(set4, &["a", "b"], "b", 1); |
| 5 | matset!(set5, &["a|b", "b|a"], "b", 0, 1); |
| 6 | matset!(set6, &["foo", "oo"], "foo", 0, 1); |
| 7 | matset!(set7, &["^foo", "bar$"], "foo", 0); |
| 8 | matset!(set8, &["^foo", "bar$"], "foo bar", 0, 1); |
| 9 | matset!(set9, &["^foo", "bar$"], "bar", 1); |
| 10 | matset!(set10, &[r"[a-z]+$", "foo"], "01234 foo", 0, 1); |
| 11 | matset!(set11, &[r"[a-z]+$", "foo"], "foo 01234", 1); |
| 12 | matset!(set12, &[r".*?", "a"], "zzzzzza", 0, 1); |
| 13 | matset!(set13, &[r".*", "a"], "zzzzzza", 0, 1); |
| 14 | matset!(set14, &[r".*", "a"], "zzzzzz", 0); |
| 15 | matset!(set15, &[r"(?-u)\ba\b"], "hello a bye", 0); |
| 16 | matset!(set16, &["a"], "a", 0); |
| 17 | matset!(set17, &[".*a"], "a", 0); |
| 18 | matset!(set18, &["a", "β"], "β", 1); |
| 19 | |
Haibo Huang | 49cbe5f | 2020-05-28 20:14:24 -0700 | [diff] [blame^] | 20 | // regexes that match the empty string |
| 21 | matset!(setempty1, &["", "a"], "abc", 0, 1); |
| 22 | matset!(setempty2, &["", "b"], "abc", 0, 1); |
| 23 | matset!(setempty3, &["", "z"], "abc", 0); |
| 24 | matset!(setempty4, &["a", ""], "abc", 0, 1); |
| 25 | matset!(setempty5, &["b", ""], "abc", 0, 1); |
| 26 | matset!(setempty6, &["z", ""], "abc", 1); |
| 27 | matset!(setempty7, &["b", "(?:)"], "abc", 0, 1); |
| 28 | matset!(setempty8, &["(?:)", "b"], "abc", 0, 1); |
| 29 | matset!(setempty9, &["c(?:)", "b"], "abc", 0, 1); |
| 30 | |
Chih-Hung Hsieh | e42c505 | 2020-04-16 10:44:21 -0700 | [diff] [blame] | 31 | nomatset!(nset1, &["a", "a"], "b"); |
| 32 | nomatset!(nset2, &["^foo", "bar$"], "bar foo"); |
| 33 | nomatset!( |
| 34 | nset3, |
| 35 | { |
| 36 | let xs: &[&str] = &[]; |
| 37 | xs |
| 38 | }, |
| 39 | "a" |
| 40 | ); |
| 41 | nomatset!(nset4, &[r"^rooted$", r"\.log$"], "notrooted"); |
| 42 | |
| 43 | // See: https://github.com/rust-lang/regex/issues/187 |
| 44 | #[test] |
| 45 | fn regression_subsequent_matches() { |
| 46 | let set = regex_set!(&["ab", "b"]); |
| 47 | let text = text!("ba"); |
| 48 | assert!(set.matches(text).matched(1)); |
| 49 | assert!(set.matches(text).matched(1)); |
| 50 | } |
| 51 | |
| 52 | #[test] |
| 53 | fn get_set_patterns() { |
| 54 | let set = regex_set!(&["a", "b"]); |
| 55 | assert_eq!(vec!["a", "b"], set.patterns()); |
| 56 | } |