From 560760c489db611451c5243cbb65a0ed8ef0fefb Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Tue, 24 Nov 2020 15:08:05 -0500 Subject: [PATCH] Added another test for RoutingNode --- src/routing.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/routing.rs b/src/routing.rs index d021d95..e77faf8 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -23,6 +23,31 @@ use crate::types::Request; /// /// Routing is only performed on normalized paths, so "/endpoint" and "/endpoint/" are /// considered to be the same route. +/// +/// ``` +/// # use northstar::routing::RoutingNode; +/// let mut routes = RoutingNode::<&'static str>::default(); +/// routes.add_route("/", "base"); +/// routes.add_route("/trans/rights/", "short route"); +/// routes.add_route("/trans/rights/r/human", "long route"); +/// +/// assert_eq!( +/// routes.match_path(&["any", "other", "request"]), +/// Some((vec![&"any", &"other", &"request"], &"base")) +/// ); +/// assert_eq!( +/// routes.match_path(&["trans", "rights"]), +/// Some((vec![], &"short route")) +/// ); +/// assert_eq!( +/// routes.match_path(&["trans", "rights", "now"]), +/// Some((vec![&"now"], &"short route")) +/// ); +/// assert_eq!( +/// routes.match_path(&["trans", "rights", "r", "human", "rights"]), +/// Some((vec![&"rights"], &"long route")) +/// ); +/// ``` pub struct RoutingNode(Option, HashMap); impl RoutingNode {