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 | |
| 20 | nomatset!(nset1, &["a", "a"], "b"); |
| 21 | nomatset!(nset2, &["^foo", "bar$"], "bar foo"); |
| 22 | nomatset!( |
| 23 | nset3, |
| 24 | { |
| 25 | let xs: &[&str] = &[]; |
| 26 | xs |
| 27 | }, |
| 28 | "a" |
| 29 | ); |
| 30 | nomatset!(nset4, &[r"^rooted$", r"\.log$"], "notrooted"); |
| 31 | |
| 32 | // See: https://github.com/rust-lang/regex/issues/187 |
| 33 | #[test] |
| 34 | fn regression_subsequent_matches() { |
| 35 | let set = regex_set!(&["ab", "b"]); |
| 36 | let text = text!("ba"); |
| 37 | assert!(set.matches(text).matched(1)); |
| 38 | assert!(set.matches(text).matched(1)); |
| 39 | } |
| 40 | |
| 41 | #[test] |
| 42 | fn get_set_patterns() { |
| 43 | let set = regex_set!(&["a", "b"]); |
| 44 | assert_eq!(vec!["a", "b"], set.patterns()); |
| 45 | } |