diff --git a/src/model.rs b/src/model.rs index a361327..7297ae6 100644 --- a/src/model.rs +++ b/src/model.rs @@ -360,7 +360,7 @@ mod tests { } #[test] - fn match_ips() { + fn match_ipv4s() { let buffer = "Lorem ipsum 127.0.0.1 lorem\n Lorem 255.255.10.255 lorem 127.0.0.1 lorem"; let named_pat = vec![]; let custom = vec![]; @@ -368,8 +368,11 @@ mod tests { let results = Model::new(buffer, &alphabet, &named_pat, &custom, false).matches(false); assert_eq!(results.len(), 3); + assert_eq!(results.get(0).unwrap().pattern, "ipv4"); assert_eq!(results.get(0).unwrap().text, "127.0.0.1"); + assert_eq!(results.get(1).unwrap().pattern, "ipv4"); assert_eq!(results.get(1).unwrap().text, "255.255.10.255"); + assert_eq!(results.get(2).unwrap().pattern, "ipv4"); assert_eq!(results.get(2).unwrap().text, "127.0.0.1"); } diff --git a/src/regexes.rs b/src/regexes.rs index f8f3f87..9bb81fa 100644 --- a/src/regexes.rs +++ b/src/regexes.rs @@ -3,6 +3,10 @@ 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")]; +/// Holds all the regex patterns that are currently supported. +/// +/// The email address was obtained at https://www.regular-expressions.info/email.html. +/// Others were obtained from Ferran Basora. pub const PATTERNS: [(&'static str, &'static str); 15] = [ ("markdown-url", r"\[[^]]*\]\(([^)]+)\)"), ( @@ -21,7 +25,7 @@ pub const PATTERNS: [(&'static str, &'static str); 15] = [ ), ("ipfs", r"Qm[0-9a-zA-Z]{44}"), ("sha", r"[0-9a-f]{7,40}"), - ("ip", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"), + ("ipv4", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"), ("ipv6", r"[A-f0-9:]+:+[A-f0-9:]+[%\w\d]+"), ("mem-address", r"0x[0-9a-fA-F]+"), ("number", r"[0-9]{4,}"),