feat: match email addresses

This commit is contained in:
graelo 2020-06-04 07:16:07 +02:00
parent 7ce0b517dc
commit 0f66b6fbd9
2 changed files with 24 additions and 1 deletions

View file

@ -429,6 +429,28 @@ mod tests {
assert_eq!(results.get(3).unwrap().pattern, "url");
}
#[test]
fn match_emails() {
let buffer =
"Lorem ipsum <first.last+social@example.com> john@server.department.company.com lorem";
let named_pat = vec![];
let custom = vec![];
let alphabet = Alphabet("abcd".to_string());
let results = Model::new(buffer, &alphabet, &named_pat, &custom, false).matches(false);
assert_eq!(results.len(), 2);
assert_eq!(results.get(0).unwrap().pattern, "email");
assert_eq!(
results.get(0).unwrap().text,
"first.last+social@example.com"
);
assert_eq!(results.get(1).unwrap().pattern, "email");
assert_eq!(
results.get(1).unwrap().text,
"john@server.department.company.com"
);
}
#[test]
fn match_addresses() {
let buffer = "Lorem 0xfd70b5695 0x5246ddf lorem\n Lorem 0x973113tlorem";

View file

@ -3,12 +3,13 @@ use crate::error;
pub const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] =
[("ansi_colors", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")];
pub const PATTERNS: [(&'static str, &'static str); 14] = [
pub const PATTERNS: [(&'static str, &'static str); 15] = [
("markdown_url", r"\[[^]]*\]\(([^)]+)\)"),
(
"url",
r"((https?://|git@|git://|ssh://|ftp://|file:///)[^ \(\)\[\]\{\}]+)",
),
("email", r"\b[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,}\b"),
("diff_a", r"--- a/([^ ]+)"),
("diff_b", r"\+\+\+ b/([^ ]+)"),
("docker", r"sha256:([0-9a-f]{64})"),