mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 16:10:07 +01:00
feat: match email addresses
This commit is contained in:
parent
7ce0b517dc
commit
0f66b6fbd9
2 changed files with 24 additions and 1 deletions
22
src/model.rs
22
src/model.rs
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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})"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue