2016-02-05 00:36:06 +01:00
|
|
|
#![allow(unused)]
|
2018-07-28 17:34:52 +02:00
|
|
|
#![warn(clippy::invalid_regex, clippy::trivial_regex, clippy::regex_macro)]
|
2016-02-05 00:36:06 +01:00
|
|
|
|
|
|
|
extern crate regex;
|
|
|
|
|
2018-12-09 23:26:16 +01:00
|
|
|
use regex::bytes::{Regex as BRegex, RegexBuilder as BRegexBuilder, RegexSet as BRegexSet};
|
|
|
|
use regex::{Regex, RegexBuilder, RegexSet};
|
2016-02-05 00:36:06 +01:00
|
|
|
|
2017-10-20 15:51:35 +02:00
|
|
|
const OPENING_PAREN: &str = "(";
|
|
|
|
const NOT_A_REAL_REGEX: &str = "foobar";
|
2016-02-05 16:48:35 +01:00
|
|
|
|
2016-02-05 23:10:48 +01:00
|
|
|
fn syntax_error() {
|
2016-02-05 00:36:06 +01:00
|
|
|
let pipe_in_wrong_position = Regex::new("|");
|
2016-05-25 21:36:51 +02:00
|
|
|
let pipe_in_wrong_position_builder = RegexBuilder::new("|");
|
2016-02-05 21:54:29 +01:00
|
|
|
let wrong_char_ranice = Regex::new("[z-a]");
|
2016-05-08 00:56:23 +02:00
|
|
|
let some_unicode = Regex::new("[é-è]");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-05 16:48:35 +01:00
|
|
|
let some_regex = Regex::new(OPENING_PAREN);
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-05-25 17:15:19 +02:00
|
|
|
let binary_pipe_in_wrong_position = BRegex::new("|");
|
|
|
|
let some_binary_regex = BRegex::new(OPENING_PAREN);
|
2016-05-25 21:36:51 +02:00
|
|
|
let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN);
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-05 16:48:35 +01:00
|
|
|
let closing_paren = ")";
|
|
|
|
let not_linted = Regex::new(closing_paren);
|
2016-05-25 17:15:19 +02:00
|
|
|
|
2018-12-09 23:26:16 +01:00
|
|
|
let set = RegexSet::new(&[r"[a-z]+@[a-z]+\.(com|org|net)", r"[a-z]+\.(com|org|net)"]);
|
2016-05-25 17:15:19 +02:00
|
|
|
let bset = BRegexSet::new(&[
|
|
|
|
r"[a-z]+@[a-z]+\.(com|org|net)",
|
|
|
|
r"[a-z]+\.(com|org|net)",
|
2018-04-07 22:18:51 +02:00
|
|
|
r".", // regression test
|
2016-05-25 17:15:19 +02:00
|
|
|
]);
|
|
|
|
|
2018-12-09 23:26:16 +01:00
|
|
|
let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]);
|
|
|
|
let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]);
|
2018-01-23 16:52:14 +01:00
|
|
|
|
|
|
|
let raw_string_error = Regex::new(r"[...\/...]");
|
|
|
|
let raw_string_error = Regex::new(r#"[...\/...]"#);
|
2016-02-05 00:36:06 +01:00
|
|
|
}
|
2016-02-05 23:10:48 +01:00
|
|
|
|
|
|
|
fn trivial_regex() {
|
|
|
|
let trivial_eq = Regex::new("^foobar$");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-05-25 21:36:51 +02:00
|
|
|
let trivial_eq_builder = RegexBuilder::new("^foobar$");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-05 23:10:48 +01:00
|
|
|
let trivial_starts_with = Regex::new("^foobar");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-05 23:10:48 +01:00
|
|
|
let trivial_ends_with = Regex::new("foobar$");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-05 23:10:48 +01:00
|
|
|
let trivial_contains = Regex::new("foobar");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-05 23:10:48 +01:00
|
|
|
let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-06 18:06:39 +01:00
|
|
|
let trivial_backslash = Regex::new("a\\.b");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-05 23:10:48 +01:00
|
|
|
// unlikely corner cases
|
|
|
|
let trivial_empty = Regex::new("");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-06 18:06:39 +01:00
|
|
|
let trivial_empty = Regex::new("^");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-05 23:10:48 +01:00
|
|
|
let trivial_empty = Regex::new("^$");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-05-25 17:15:19 +02:00
|
|
|
let binary_trivial_empty = BRegex::new("^$");
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2016-02-05 23:10:48 +01:00
|
|
|
// non-trivial regexes
|
2016-02-06 18:06:39 +01:00
|
|
|
let non_trivial_dot = Regex::new("a.b");
|
2016-05-25 21:36:51 +02:00
|
|
|
let non_trivial_dot_builder = RegexBuilder::new("a.b");
|
2016-02-05 23:10:48 +01:00
|
|
|
let non_trivial_eq = Regex::new("^foo|bar$");
|
|
|
|
let non_trivial_starts_with = Regex::new("^foo|bar");
|
|
|
|
let non_trivial_ends_with = Regex::new("^foo|bar");
|
|
|
|
let non_trivial_ends_with = Regex::new("foo|bar");
|
2016-05-25 17:15:19 +02:00
|
|
|
let non_trivial_binary = BRegex::new("foo|bar");
|
2016-05-25 21:36:51 +02:00
|
|
|
let non_trivial_binary_builder = BRegexBuilder::new("foo|bar");
|
2016-02-05 23:10:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
syntax_error();
|
|
|
|
trivial_regex();
|
|
|
|
}
|