add unit tests to parse attributes
This commit is contained in:
@@ -180,3 +180,56 @@ fn parse_attributes() {
|
|||||||
attrs
|
attrs
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_attributes_with_values() {
|
||||||
|
use proc_macro2::{Span, TokenStream};
|
||||||
|
use std::str::FromStr;
|
||||||
|
use syn::punctuated::Punctuated;
|
||||||
|
use syn::token::Bracket;
|
||||||
|
use syn::token::Pound;
|
||||||
|
use syn::AttrStyle::Outer;
|
||||||
|
use syn::{Ident, Path, PathArguments, PathSegment};
|
||||||
|
|
||||||
|
let mut punctuated = Punctuated::new();
|
||||||
|
punctuated.push(PathSegment {
|
||||||
|
ident: Ident::new("yaserde", Span::call_site()),
|
||||||
|
arguments: PathArguments::None,
|
||||||
|
});
|
||||||
|
|
||||||
|
// #[()]
|
||||||
|
let attributes = vec![Attribute {
|
||||||
|
pound_token: Pound {
|
||||||
|
spans: [Span::call_site()],
|
||||||
|
},
|
||||||
|
style: Outer,
|
||||||
|
bracket_token: Bracket {
|
||||||
|
span: Span::call_site(),
|
||||||
|
},
|
||||||
|
path: Path {
|
||||||
|
leading_colon: None,
|
||||||
|
segments: punctuated,
|
||||||
|
},
|
||||||
|
tokens: TokenStream::from_str("(attribute, flatten, default_namespace=\"example\", namespace=\"example: http://example.org\")").unwrap(),
|
||||||
|
}];
|
||||||
|
|
||||||
|
let attrs = YaSerdeAttribute::parse(&attributes);
|
||||||
|
|
||||||
|
let mut namespaces = BTreeMap::new();
|
||||||
|
namespaces.insert("example".to_string(), "http://example.org".to_string());
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
YaSerdeAttribute {
|
||||||
|
attribute: true,
|
||||||
|
default: None,
|
||||||
|
default_namespace: Some("example".to_string()),
|
||||||
|
flatten: true,
|
||||||
|
namespaces,
|
||||||
|
prefix: None,
|
||||||
|
root: None,
|
||||||
|
rename: None,
|
||||||
|
text: false,
|
||||||
|
},
|
||||||
|
attrs
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user