Add support for IPFS CIDs

This commit is contained in:
Ferran Basora 2019-11-17 17:44:08 +00:00
parent 3390330c0c
commit 094475faab
2 changed files with 16 additions and 1 deletions

View File

@ -15,6 +15,7 @@ letter hint to yank the text in your tmux buffer.
- File paths - File paths
- File in diff - File in diff
- Git SHAs - Git SHAs
- IPFS CID's
- Colors in hex - Colors in hex
- Numbers ( 4+ digits ) - Numbers ( 4+ digits )
- Hex numbers - Hex numbers

View File

@ -5,7 +5,7 @@ use std::fmt;
const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] = const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] =
[("bash", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")]; [("bash", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")];
const PATTERNS: [(&'static str, &'static str); 12] = [ const PATTERNS: [(&'static str, &'static str); 13] = [
("markdown_url", r"\[[^]]*\]\(([^)]+)\)"), ("markdown_url", r"\[[^]]*\]\(([^)]+)\)"),
( (
"url", "url",
@ -19,6 +19,7 @@ const PATTERNS: [(&'static str, &'static str); 12] = [
"uid", "uid",
r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
), ),
("ipfs", r"Qm[0-9a-zA-Z]{44}"),
("sha", r"[0-9a-f]{7,40}"), ("sha", r"[0-9a-f]{7,40}"),
("ip", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"), ("ip", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"),
("ipv6", r"[A-f0-9:]+:+[A-f0-9:]+[%\w\d]+"), ("ipv6", r"[A-f0-9:]+:+[A-f0-9:]+[%\w\d]+"),
@ -363,6 +364,19 @@ mod tests {
assert_eq!(results.get(3).unwrap().text.clone(), "#abcd00"); assert_eq!(results.get(3).unwrap().text.clone(), "#abcd00");
} }
#[test]
fn match_ipfs() {
let lines = split("Lorem QmRdbNSxDJBXmssAc9fvTtux4duptMvfSGiGuq6yHAQVKQ lorem Qmfoobar");
let custom = [].to_vec();
let results = State::new(&lines, "abcd", &custom).matches(false, false);
assert_eq!(results.len(), 1);
assert_eq!(
results.get(0).unwrap().text.clone(),
"QmRdbNSxDJBXmssAc9fvTtux4duptMvfSGiGuq6yHAQVKQ"
);
}
#[test] #[test]
fn match_process_port() { fn match_process_port() {
let lines = split("Lorem 5695 52463 lorem\n Lorem 973113 lorem 99999 lorem 8888 lorem\n 23456 lorem 5432 lorem 23444"); let lines = split("Lorem 5695 52463 lorem\n Lorem 973113 lorem 99999 lorem 8888 lorem\n 23456 lorem 5432 lorem 23444");