diff --git a/lib/src/content_type.rs b/lib/src/content_type.rs index 140107ea..36648afc 100644 --- a/lib/src/content_type.rs +++ b/lib/src/content_type.rs @@ -99,7 +99,7 @@ impl FromStr for ContentType { }; let top_str = &raw[..slash]; - let (sub_str, rest) = match raw.find(';') { + let (sub_str, _rest) = match raw.find(';') { Some(j) => (&raw[(slash + 1)..j], Some(&raw[(j + 1)..])), None => (&raw[(slash + 1)..], None) }; diff --git a/lib/src/router/mod.rs b/lib/src/router/mod.rs index 37075d18..3a597678 100644 --- a/lib/src/router/mod.rs +++ b/lib/src/router/mod.rs @@ -140,6 +140,11 @@ mod test { } } + fn matches<'a>(router: &'a Router, method: Method, uri: &str) -> Vec<&'a Route> { + let request = Request::mock(method, uri); + router.route(&request) + } + #[test] fn test_ok_routing() { let router = router_with_routes(&["/hello"]); @@ -227,11 +232,15 @@ mod test { } macro_rules! assert_ranked_routing { - (to: $to:expr, with: $routes:expr, expect: $want:expr) => ({ + (to: $to:expr, with: $routes:expr, expect: $($want:expr),+) => ({ let router = router_with_ranked_routes(&$routes); - let routed_to = route(&router, Get, $to).unwrap(); - assert_eq!(routed_to.path.as_str() as &str, $want.1); - assert_eq!(routed_to.rank, $want.0); + let routed_to = matches(&router, Get, $to); + let expected = &[$($want),+]; + assert!(routed_to.len() == expected.len()); + for (got, expected) in routed_to.iter().zip(expected.iter()) { + assert_eq!(got.path.as_str() as &str, expected.1); + assert_eq!(got.rank, expected.0); + } }) } @@ -240,19 +249,31 @@ mod test { assert_ranked_routing!( to: "a/b", with: [(1, "a/"), (2, "a/")], - expect: (1, "a/") + expect: (1, "a/"), (2, "a/") ); assert_ranked_routing!( to: "b/b", with: [(1, "a/"), (2, "b/"), (3, "b/b")], - expect: (2, "b/") + expect: (2, "b/"), (3, "b/b") ); assert_ranked_routing!( to: "b/b", with: [(1, "a/"), (2, "b/"), (0, "b/b")], - expect: (0, "b/b") + expect: (0, "b/b"), (2, "b/") + ); + + assert_ranked_routing!( + to: "/profile/sergio/edit", + with: [(1, "///edit"), (2, "/profile/"), (0, "///")], + expect: (0, "///"), (1, "///edit") + ); + + assert_ranked_routing!( + to: "/profile/sergio/edit", + with: [(0, "///edit"), (2, "/profile/"), (5, "///")], + expect: (0, "///edit"), (5, "///") ); }