diff --git a/url_parser_trait/src/lib.rs b/url_parser_trait/src/lib.rs index 399416c..d57cf00 100644 --- a/url_parser_trait/src/lib.rs +++ b/url_parser_trait/src/lib.rs @@ -25,12 +25,13 @@ pub trait QueryParams { mod tests { use super::*; - struct Param { + + struct Param1 { user_id: u8, user_name: String, } - impl QueryParams for Param { + impl QueryParams for Param1 { fn get_items_as_string_map(&self) -> HashMap { let mut map: HashMap = HashMap::new(); map.insert("user_id".to_string(), self.user_id.to_string()); @@ -39,10 +40,31 @@ mod tests { } } + + struct Param2 { + user_id: u8, + } + + impl QueryParams for Param2 { + fn get_items_as_string_map(&self) -> HashMap { + let mut map: HashMap = HashMap::new(); + map.insert("user_id".to_string(), self.user_id.to_string()); + map + } + } + + #[test] fn check_query() { - let param: Param = Param {user_id: 1, user_name: "Awayume".to_string()}; + let param: Param1 = Param1 {user_id: 1, user_name: "Awayume".to_string()}; let query: &str = ¶m.to_query_params(); assert!(query == "?user_id=1&user_name=Awayume" || query == "?user_name=Awayume&user_id=1", "Invalid query: {}", query); } + + #[test] + fn check_1key_query() { + let param: Param2 = Param2 {user_id: 1}; + let query: &str = ¶m.to_query_params(); + assert!(query == "?user_id=1", "Invalid query: {}", query); + } }