Chih-Hung Hsieh | e42c505 | 2020-04-16 10:44:21 -0700 | [diff] [blame] | 1 | #![cfg_attr(feature = "pattern", feature(pattern))] |
| 2 | |
| 3 | extern crate rand; |
| 4 | extern crate regex; |
| 5 | |
| 6 | // Due to macro scoping rules, this definition only applies for the modules |
| 7 | // defined below. Effectively, it allows us to use the same tests for both |
| 8 | // native and dynamic regexes. |
| 9 | // |
| 10 | // This is also used to test the various matching engines. This one exercises |
| 11 | // the normal code path which automatically chooses the engine based on the |
| 12 | // regex and the input. Other dynamic tests explicitly set the engine to use. |
| 13 | macro_rules! regex_new { |
| 14 | ($re:expr) => {{ |
| 15 | use regex::Regex; |
| 16 | Regex::new($re) |
| 17 | }}; |
| 18 | } |
| 19 | |
| 20 | macro_rules! regex { |
| 21 | ($re:expr) => { |
| 22 | regex_new!($re).unwrap() |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | macro_rules! regex_set_new { |
| 27 | ($re:expr) => {{ |
| 28 | use regex::RegexSet; |
| 29 | RegexSet::new($re) |
| 30 | }}; |
| 31 | } |
| 32 | |
| 33 | macro_rules! regex_set { |
| 34 | ($res:expr) => { |
| 35 | regex_set_new!($res).unwrap() |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | // Must come before other module definitions. |
| 40 | include!("macros_str.rs"); |
| 41 | include!("macros.rs"); |
| 42 | |
| 43 | mod api; |
| 44 | mod api_str; |
| 45 | mod crazy; |
| 46 | mod flags; |
| 47 | mod fowler; |
| 48 | mod misc; |
| 49 | mod multiline; |
| 50 | mod noparse; |
| 51 | mod regression; |
Haibo Huang | 1d704cd | 2020-11-02 18:46:32 -0800 | [diff] [blame] | 52 | mod regression_fuzz; |
Chih-Hung Hsieh | e42c505 | 2020-04-16 10:44:21 -0700 | [diff] [blame] | 53 | mod replace; |
| 54 | mod searcher; |
| 55 | mod set; |
| 56 | mod shortest_match; |
| 57 | mod suffix_reverse; |
| 58 | #[cfg(feature = "unicode")] |
| 59 | mod unicode; |
| 60 | #[cfg(feature = "unicode-perl")] |
| 61 | mod word_boundary; |
| 62 | #[cfg(feature = "unicode-perl")] |
| 63 | mod word_boundary_unicode; |
| 64 | |
| 65 | #[test] |
| 66 | fn disallow_non_utf8() { |
| 67 | assert!(regex::Regex::new(r"(?-u)\xFF").is_err()); |
| 68 | assert!(regex::Regex::new(r"(?-u).").is_err()); |
| 69 | assert!(regex::Regex::new(r"(?-u)[\xFF]").is_err()); |
| 70 | assert!(regex::Regex::new(r"(?-u)☃").is_err()); |
| 71 | } |
| 72 | |
| 73 | #[test] |
| 74 | fn disallow_octal() { |
| 75 | assert!(regex::Regex::new(r"\0").is_err()); |
| 76 | } |
| 77 | |
| 78 | #[test] |
| 79 | fn allow_octal() { |
| 80 | assert!(regex::RegexBuilder::new(r"\0").octal(true).build().is_ok()); |
| 81 | } |
| 82 | |
| 83 | #[test] |
| 84 | fn oibits() { |
| 85 | use regex::bytes; |
| 86 | use regex::{Regex, RegexBuilder}; |
| 87 | use std::panic::UnwindSafe; |
| 88 | |
| 89 | fn assert_send<T: Send>() {} |
| 90 | fn assert_sync<T: Sync>() {} |
| 91 | fn assert_unwind_safe<T: UnwindSafe>() {} |
| 92 | |
| 93 | assert_send::<Regex>(); |
| 94 | assert_sync::<Regex>(); |
| 95 | assert_unwind_safe::<Regex>(); |
| 96 | assert_send::<RegexBuilder>(); |
| 97 | assert_sync::<RegexBuilder>(); |
| 98 | assert_unwind_safe::<RegexBuilder>(); |
| 99 | |
| 100 | assert_send::<bytes::Regex>(); |
| 101 | assert_sync::<bytes::Regex>(); |
| 102 | assert_unwind_safe::<bytes::Regex>(); |
| 103 | assert_send::<bytes::RegexBuilder>(); |
| 104 | assert_sync::<bytes::RegexBuilder>(); |
| 105 | assert_unwind_safe::<bytes::RegexBuilder>(); |
| 106 | } |
| 107 | |
| 108 | // See: https://github.com/rust-lang/regex/issues/568 |
| 109 | #[test] |
| 110 | fn oibits_regression() { |
| 111 | use regex::Regex; |
| 112 | use std::panic; |
| 113 | |
| 114 | let _ = panic::catch_unwind(|| Regex::new("a").unwrap()); |
| 115 | } |