use std::sync::Arc;
use caramelo::{MatchType::ToHave, Matcher, TypedMatcher};
use crate::mock::Request;
pub fn path(value: &str) -> Arc<dyn TypedMatcher<Request> + Send + Sync + 'static> {
let regex = regex::Regex::new(value);
match regex {
Ok(regex) => Arc::new(Path(regex)),
Err(_) => panic!("Invalid regex pattern"),
}
}
#[derive(Clone)]
pub struct Path(regex::Regex);
unsafe impl Send for Path {}
unsafe impl Sync for Path {}
impl Matcher<Request> for Path {
fn matches(&self, value: &Request) -> bool {
self.0.is_match(
&value
.path()
.to_string(),
)
}
fn description(&self) -> String {
format!("path matching {:?}", self.0)
}
}
impl TypedMatcher<Request> for Path {
fn matcher_type(&self) -> caramelo::MatchType {
ToHave
}
}