Skip to content

Commit

Permalink
test: Add a test for query that has only one key
Browse files Browse the repository at this point in the history
  • Loading branch information
Awayume committed Sep 17, 2023
1 parent a358cb8 commit 653ded2
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions url_parser_trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> {
let mut map: HashMap<String, String> = HashMap::new();
map.insert("user_id".to_string(), self.user_id.to_string());
Expand All @@ -39,10 +40,31 @@ mod tests {
}
}


struct Param2 {
user_id: u8,
}

impl QueryParams for Param2 {
fn get_items_as_string_map(&self) -> HashMap<String, String> {
let mut map: HashMap<String, String> = 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 = &param.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 = &param.to_query_params();
assert!(query == "?user_id=1", "Invalid query: {}", query);
}
}

0 comments on commit 653ded2

Please sign in to comment.