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 in diff
- Git SHAs
- IPFS CID's
- Colors in hex
- Numbers ( 4+ digits )
- Hex numbers

View File

@ -5,7 +5,7 @@ use std::fmt;
const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] =
[("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"\[[^]]*\]\(([^)]+)\)"),
(
"url",
@ -19,6 +19,7 @@ const PATTERNS: [(&'static str, &'static str); 12] = [
"uid",
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}"),
("ip", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"),
("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");
}
#[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]
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");