+ Test for qs_param behavior
Pretty simple and contains a special note about qs_param usage
This commit is contained in:
parent
769aa72cdf
commit
eb338e03a0
@ -40,6 +40,7 @@ pub fn parse_query_string<'qs>(string: &'qs str)
|
||||
}
|
||||
|
||||
// Pulls out Option<type> 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user