+ Test for qs_param behavior

Pretty simple and contains a special note about qs_param usage
This commit is contained in:
shockrah 2021-02-05 16:57:31 -08:00
parent 769aa72cdf
commit eb338e03a0

View File

@ -40,6 +40,7 @@ pub fn parse_query_string<'qs>(string: &'qs str)
} }
// Pulls out Option<type> from a HashMap<&str, &str> // Pulls out Option<type> from a HashMap<&str, &str>
// NOTE: If you need &str just use the hashmap directly
#[macro_export] #[macro_export]
macro_rules! qs_param { macro_rules! qs_param {
($obj:expr, $id:literal, $type:ty) => { ($obj:expr, $id:literal, $type:ty) => {
@ -55,3 +56,23 @@ macro_rules! qs_param {
} }
} }
} }
#[cfg(test)]
mod tests {
use std::collections::HashMap;
#[test]
fn validate_qs_param() {
let mut map: HashMap<&str, &str> = HashMap::new();
map.insert("key", "value");
map.insert("asdf", "123");
// It should be noted if you want &str values then just
// use the hashmap directly, since the macro is a bit clumsy with strings
// Thust the cast to a String not &str is required
assert_eq!(qs_param!(map, "key", String).is_some(), true);
assert_eq!(qs_param!(map, "not-there", String).is_some(), false);
assert_eq!(qs_param!(map, "asdf", u64).is_some(), true);
assert_eq!(qs_param!(map, "asdf", bool).is_some(), false);
}
}