1// These tests are only run for the "default" test target because some of them
2// can take quite a long time. Some of them take long enough that it's not
3// practical to run them in debug mode. :-/
4
5use regex::Regex;
6
7macro_rules! regex {
8 ($pattern:expr) => {
9 regex::Regex::new($pattern).unwrap()
10 };
11}
12
13// See: https://oss-fuzz.com/testcase-detail/5673225499181056
14//
15// Ignored by default since it takes too long in debug mode (almost a minute).
16#[test]
17#[ignore]
18fn fuzz1() {
19 regex!(r"1}{55}{0}*{1}{55}{55}{5}*{1}{55}+{56}|;**");
20}
21
22// See: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26505
23// See: https://github.com/rust-lang/regex/issues/722
24#[test]
25#[cfg(feature = "unicode")]
26fn empty_any_errors_no_panic() {
27 assert!(Regex::new(r"\P{any}").is_ok());
28}
29
30// This tests that a very large regex errors during compilation instead of
31// using gratuitous amounts of memory. The specific problem is that the
32// compiler wasn't accounting for the memory used by Unicode character classes
33// correctly.
34//
35// See: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33579
36#[test]
37fn big_regex_fails_to_compile() {
38 let pat = "[\u{0}\u{e}\u{2}\\w~~>[l\t\u{0}]p?<]{971158}";
39 assert!(Regex::new(pat).is_err());
40}
41
42// This was caught while on master but before a release went out(!).
43//
44// See: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58173
45#[test]
46fn todo() {
47 let pat = "(?:z|xx)@|xx";
48 assert!(Regex::new(pat).is_ok());
49}
50
51// This was caused by the fuzzer, and then minimized by hand.
52//
53// This was caused by a bug in DFA determinization that mishandled NFA fail
54// states.
55#[test]
56fn fail_branch_prevents_match() {
57 let pat = r".*[a&&b]A|B";
58 let hay = "B";
59 let re = Regex::new(pat).unwrap();
60 assert!(re.is_match(hay));
61}
62