5 #![deny(invalid_regex, trivial_regex, regex_macro)]
9 use regex::{Regex, RegexSet};
10 use regex::bytes::{Regex as BRegex, RegexSet as BRegexSet};
12 const OPENING_PAREN : &'static str = "(";
13 const NOT_A_REAL_REGEX : &'static str = "foobar";
16 let pipe_in_wrong_position = Regex::new("|");
17 //~^ERROR: regex syntax error: empty alternate
18 let wrong_char_ranice = Regex::new("[z-a]");
19 //~^ERROR: regex syntax error: invalid character class range
20 let some_unicode = Regex::new("[é-è]");
21 //~^ERROR: regex syntax error: invalid character class range
23 let some_regex = Regex::new(OPENING_PAREN);
24 //~^ERROR: regex syntax error on position 0: unclosed
26 let binary_pipe_in_wrong_position = BRegex::new("|");
27 //~^ERROR: regex syntax error: empty alternate
28 let some_binary_regex = BRegex::new(OPENING_PAREN);
29 //~^ERROR: regex syntax error on position 0: unclosed
31 let closing_paren = ")";
32 let not_linted = Regex::new(closing_paren);
34 let set = RegexSet::new(&[
35 r"[a-z]+@[a-z]+\.(com|org|net)",
36 r"[a-z]+\.(com|org|net)",
38 let bset = BRegexSet::new(&[
39 r"[a-z]+@[a-z]+\.(com|org|net)",
40 r"[a-z]+\.(com|org|net)",
43 let set_error = RegexSet::new(&[
45 //~^ERROR: regex syntax error on position 0: unclosed
46 r"[a-z]+\.(com|org|net)",
48 let bset_error = BRegexSet::new(&[
50 //~^ERROR: regex syntax error on position 0: unclosed
51 r"[a-z]+\.(com|org|net)",
56 let trivial_eq = Regex::new("^foobar$");
57 //~^ERROR: trivial regex
58 //~|HELP consider using `==` on `str`s
60 let trivial_starts_with = Regex::new("^foobar");
61 //~^ERROR: trivial regex
62 //~|HELP consider using `str::starts_with`
64 let trivial_ends_with = Regex::new("foobar$");
65 //~^ERROR: trivial regex
66 //~|HELP consider using `str::ends_with`
68 let trivial_contains = Regex::new("foobar");
69 //~^ERROR: trivial regex
70 //~|HELP consider using `str::contains`
72 let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
73 //~^ERROR: trivial regex
74 //~|HELP consider using `str::contains`
76 let trivial_backslash = Regex::new("a\\.b");
77 //~^ERROR: trivial regex
78 //~|HELP consider using `str::contains`
80 // unlikely corner cases
81 let trivial_empty = Regex::new("");
82 //~^ERROR: trivial regex
83 //~|HELP the regex is unlikely to be useful
85 let trivial_empty = Regex::new("^");
86 //~^ERROR: trivial regex
87 //~|HELP the regex is unlikely to be useful
89 let trivial_empty = Regex::new("^$");
90 //~^ERROR: trivial regex
91 //~|HELP consider using `str::is_empty`
93 let binary_trivial_empty = BRegex::new("^$");
94 //~^ERROR: trivial regex
95 //~|HELP consider using `str::is_empty`
97 // non-trivial regexes
98 let non_trivial_dot = Regex::new("a.b");
99 let non_trivial_eq = Regex::new("^foo|bar$");
100 let non_trivial_starts_with = Regex::new("^foo|bar");
101 let non_trivial_ends_with = Regex::new("^foo|bar");
102 let non_trivial_ends_with = Regex::new("foo|bar");
103 let non_trivial_binary = BRegex::new("foo|bar");