1 use std::collections::HashMap;
2
3 use darling::FromMeta;
4 use syn::{parse_quote, Attribute, Path};
5
6 #[derive(Debug, FromMeta, PartialEq, Eq)]
7 struct MapValue {
8 name: String,
9 #[darling(default)]
10 option: bool,
11 }
12
13 #[test]
parse_map()14 fn parse_map() {
15 let attr: Attribute = parse_quote! {
16 #[foo(first(name = "Hello", option), the::second(name = "Second"))]
17 };
18
19 let meta = attr.meta;
20 let map: HashMap<Path, MapValue> = FromMeta::from_meta(&meta).unwrap();
21
22 let comparison: HashMap<Path, MapValue> = vec![
23 (
24 parse_quote!(first),
25 MapValue {
26 name: "Hello".into(),
27 option: true,
28 },
29 ),
30 (
31 parse_quote!(the::second),
32 MapValue {
33 name: "Second".into(),
34 option: false,
35 },
36 ),
37 ]
38 .into_iter()
39 .collect();
40
41 assert_eq!(comparison, map);
42 }
43