add test for nested route

This commit is contained in:
takashiidobe 2020-06-23 13:32:40 -04:00
parent 45b57816ee
commit 90add4ca26
2 changed files with 10 additions and 3 deletions

View File

@ -135,6 +135,7 @@ impl HttpRequest {
#[inline] #[inline]
pub fn match_pattern(&self) -> Option<String> { pub fn match_pattern(&self) -> Option<String> {
self.0.rmap.match_pattern(self.path()) self.0.rmap.match_pattern(self.path())
}
/// Checks if a given path matches a route /// Checks if a given path matches a route
#[inline] #[inline]
@ -645,14 +646,14 @@ mod tests {
move |req: HttpRequest| { move |req: HttpRequest| {
assert_eq!( assert_eq!(
req.match_name(), req.match_name(),
Some("/user/{id}/profile".to_owned()) Some(&ResourceDef::new("/profile"))
); );
HttpResponse::Ok().finish() HttpResponse::Ok().finish()
}, },
))) )))
.default_service(web::to(move |req: HttpRequest| { .default_service(web::to(move |req: HttpRequest| {
assert!(req.match_pattern().is_none()); assert!(req.match_name().is_none());
HttpResponse::Ok().finish() HttpResponse::Ok().finish()
})), })),
), ),

View File

@ -195,7 +195,13 @@ impl ServiceRequest {
pub fn match_info(&self) -> &Path<Url> { pub fn match_info(&self) -> &Path<Url> {
self.0.match_info() self.0.match_info()
} }
/// Counterpart to [`HttpRequest::match_name`](../struct.HttpRequest.html#method.match_name).
#[inline]
pub fn match_name(&self) -> Option<&ResourceDef> {
self.0.match_name()
}
/// Counterpart to [`HttpRequest::match_pattern`](../struct.HttpRequest.html#method.match_pattern). /// Counterpart to [`HttpRequest::match_pattern`](../struct.HttpRequest.html#method.match_pattern).
#[inline] #[inline]
pub fn match_pattern(&self) -> Option<String> { pub fn match_pattern(&self) -> Option<String> {