diff --git a/json-api/src/http.rs b/json-api/src/http.rs index 416b277..329aed8 100644 --- a/json-api/src/http.rs +++ b/json-api/src/http.rs @@ -40,6 +40,7 @@ pub fn parse_query_string<'qs>(string: &'qs str) } // Pulls out Option from a HashMap<&str, &str> +// NOTE: If you need &str just use the hashmap directly #[macro_export] macro_rules! qs_param { ($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); + } +} \ No newline at end of file