From c2f3528f82a127686a5bafdd186e95dc916647bd Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Mon, 28 Jun 2021 00:37:28 +0300 Subject: [PATCH] test for path state after matching --- actix-router/src/resource.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/actix-router/src/resource.rs b/actix-router/src/resource.rs index d0caaebf..038cc57d 100644 --- a/actix-router/src/resource.rs +++ b/actix-router/src/resource.rs @@ -674,6 +674,10 @@ mod tests { assert!(!re.is_match("/name/")); assert!(!re.is_match("/name~")); + let mut path = Path::new("/name"); + assert!(re.match_path(&mut path)); + assert_eq!(path.unprocessed(), ""); + assert_eq!(re.is_prefix_match("/name"), Some(5)); assert_eq!(re.is_prefix_match("/name1"), None); assert_eq!(re.is_prefix_match("/name/"), None); @@ -687,6 +691,10 @@ mod tests { let re = ResourceDef::new("/user/profile"); assert!(re.is_match("/user/profile")); assert!(!re.is_match("/user/profile/profile")); + + let mut path = Path::new("/user/profile"); + assert!(re.match_path(&mut path)); + assert_eq!(path.unprocessed(), ""); } #[test] @@ -700,10 +708,12 @@ mod tests { let mut path = Path::new("/user/profile"); assert!(re.match_path(&mut path)); assert_eq!(path.get("id").unwrap(), "profile"); + assert_eq!(path.unprocessed(), ""); let mut path = Path::new("/user/1245125"); assert!(re.match_path(&mut path)); assert_eq!(path.get("id").unwrap(), "1245125"); + assert_eq!(path.unprocessed(), ""); let re = ResourceDef::new("/v{version}/resource/{id}"); assert!(re.is_match("/v1/resource/320120")); @@ -714,6 +724,7 @@ mod tests { assert!(re.match_path(&mut path)); assert_eq!(path.get("version").unwrap(), "151"); assert_eq!(path.get("id").unwrap(), "adage32"); + assert_eq!(path.unprocessed(), ""); let re = ResourceDef::new("/{id:[[:digit:]]{6}}"); assert!(re.is_match("/012345")); @@ -724,6 +735,7 @@ mod tests { let mut path = Path::new("/012345"); assert!(re.match_path(&mut path)); assert_eq!(path.get("id").unwrap(), "012345"); + assert_eq!(path.unprocessed(), ""); } #[allow(clippy::cognitive_complexity)] @@ -742,10 +754,12 @@ mod tests { let mut path = Path::new("/user/profile"); assert!(re.match_path(&mut path)); assert_eq!(path.get("id").unwrap(), "profile"); + assert_eq!(path.unprocessed(), ""); let mut path = Path::new("/user/1245125"); assert!(re.match_path(&mut path)); assert_eq!(path.get("id").unwrap(), "1245125"); + assert_eq!(path.unprocessed(), ""); assert!(re.is_match("/v1/resource/320120")); assert!(!re.is_match("/v/resource/1")); @@ -878,6 +892,14 @@ mod tests { assert!(re.is_match("/name1")); assert!(re.is_match("/name~")); + let mut path = Path::new("/name"); + assert!(re.match_path(&mut path)); + assert_eq!(path.unprocessed(), ""); + + let mut path = Path::new("/name/test"); + assert!(re.match_path(&mut path)); + assert_eq!(path.unprocessed(), "/test"); + assert_eq!(re.is_prefix_match("/name"), Some(5)); assert_eq!(re.is_prefix_match("/name/"), Some(5)); assert_eq!(re.is_prefix_match("/name/test/test"), Some(5)); @@ -893,6 +915,10 @@ mod tests { assert!(re.is_match("/name/")); assert!(re.is_match("/name/gs")); assert!(!re.is_match("/name")); + + let mut path = Path::new("/name/gs"); + assert!(re.match_path(&mut path)); + assert_eq!(path.unprocessed(), "/gs"); } #[test] @@ -910,11 +936,13 @@ mod tests { assert!(re.match_path(&mut path)); assert_eq!(&path["name"], "test2"); assert_eq!(&path[0], "test2"); + assert_eq!(path.unprocessed(), ""); let mut path = Path::new("/test2/subpath1/subpath2/index.html"); assert!(re.match_path(&mut path)); assert_eq!(&path["name"], "test2"); assert_eq!(&path[0], "test2"); + assert_eq!(path.unprocessed(), "subpath1/subpath2/index.html"); } #[test]