#[macro_export]
macro_rules! scopes {
($($key:expr),*) => {{
let mut container = ::std::collections::HashSet::new();
$(
for scope in $key.split_whitespace(){
container.insert(scope.to_owned());
}
)*
container
}};
}
#[cfg(test)]
mod test {
use crate::scopes;
#[test]
fn test_hashset() {
let scopes = scopes!("hello", "world", "foo", "bar");
assert_eq!(scopes.len(), 4);
assert!(scopes.contains("hello"));
assert!(scopes.contains("world"));
assert!(scopes.contains("foo"));
assert!(scopes.contains("bar"));
}
#[test]
fn test_scopes_with_whitespace() {
let scopes = scopes!(" hello world foo bar");
assert_eq!(scopes.len(), 4);
assert!(scopes.contains("hello"));
assert!(scopes.contains("world"));
assert!(scopes.contains("foo"));
assert!(scopes.contains("bar"));
}
}