use crate::{http::Request, MatchType::ToHave, Matcher, TypedMatcher};
pub fn path(value: &str) -> Path {
let regex = regex::Regex::new(value);
match regex {
Ok(regex) => Path(regex),
Err(_) => panic!("Invalid regex pattern"),
}
}
pub struct Path(regex::Regex);
impl Matcher<Request> for Path {
fn matches(&self, value: &Request) -> bool {
self.0
.is_match(value.path())
}
fn description(&self) -> String {
format!("path matching {:?}", self.0)
}
}
impl TypedMatcher<Request> for Path {
fn matcher_type(&self) -> crate::MatchType {
ToHave
}
}