Started with regex/program.
This commit is contained in:
parent
d66849e42f
commit
1c4e976562
|
|
@ -4,3 +4,4 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
regex = "1.11.1"
|
||||
|
|
|
|||
17
src/lib.rs
17
src/lib.rs
|
|
@ -0,0 +1,17 @@
|
|||
use regex::Regex;
|
||||
|
||||
fn slug_from_link(link: String) -> Result<String, String> {
|
||||
let re = Regex::new(r"\.wikipedia\.org\/wiki\/|\?").unwrap();
|
||||
let v: Vec<&str> = re.split(&link).collect();
|
||||
println!("{v:?}");
|
||||
if v.len() >= 2 { Ok(v[1].to_string()) } else { Err("Illegal link {link} provided".to_string()) }
|
||||
}
|
||||
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_slug_from_link_1() {
|
||||
assert_eq!(slug_from_link("https://en.wikipedia.org/wiki/Buck-a-beer?wprov=sfla1".to_string()).unwrap().as_str(), "Buck-a-beer")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue