Add unit test for attribute filtering

This commit is contained in:
Ephraim Kunz 2021-02-04 20:02:39 -08:00
parent 7d2658adaf
commit 07c2106256

View File

@ -235,6 +235,55 @@ fn parse_attributes() {
); );
} }
#[test]
fn only_parse_yaserde_attributes() {
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("serde", 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("(flatten)").unwrap(),
}];
let attrs = YaSerdeAttribute::parse(&attributes);
assert_eq!(
YaSerdeAttribute {
attribute: false,
default: None,
default_namespace: None,
flatten: false,
namespaces: BTreeMap::new(),
prefix: None,
rename: None,
skip_serializing_if: None,
text: false,
},
attrs
);
}
#[test] #[test]
fn parse_attributes_with_values() { fn parse_attributes_with_values() {
use proc_macro2::{Span, TokenStream}; use proc_macro2::{Span, TokenStream};