From 0b302a3a65ba988aedef6e9e09e3b23a6cd77b2e Mon Sep 17 00:00:00 2001 From: Arnavion Date: Wed, 19 Apr 2017 02:57:28 -0700 Subject: [PATCH] fixup! Test for attributes with paths. --- tests/test_macro_input.rs | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/test_macro_input.rs b/tests/test_macro_input.rs index 4f06a37e..eca7b332 100644 --- a/tests/test_macro_input.rs +++ b/tests/test_macro_input.rs @@ -215,3 +215,46 @@ fn test_enum() { assert_eq!(expected_meta_items, actual_meta_items); } + +#[test] +fn test_attr_with_path() { + let raw =r#" + #[::attr_args::identity + fn main() { assert_eq!(foo(), "Hello, world!"); }] + struct Dummy; + "#; + + let expected = MacroInput { + ident: "Dummy".into(), + vis: Visibility::Inherited, + attrs: vec![Attribute { + style: AttrStyle::Outer, + path: Path { global: true, segments: vec!["attr_args".into(), "identity".into()] }, + tts: vec![ + TokenTree::Token(Token::Ident(Ident::from("fn"))), + TokenTree::Token(Token::Ident(Ident::from("main"))), + TokenTree::Delimited(Delimited { delim: DelimToken::Paren, tts: vec![] }), + TokenTree::Delimited(Delimited { delim: DelimToken::Brace, tts: vec![ + TokenTree::Token(Token::Ident(Ident::from("assert_eq"))), + TokenTree::Token(Token::Not), + TokenTree::Delimited(Delimited { delim: DelimToken::Paren, tts: vec![ + TokenTree::Token(Token::Ident(Ident::from("foo"))), + TokenTree::Delimited(Delimited { delim: DelimToken::Paren, tts: vec![] }), + TokenTree::Token(Token::Comma), + TokenTree::Token(Token::Literal(Lit::Str("Hello, world!".into(), StrStyle::Cooked))), + ]}), + TokenTree::Token(Token::Semi), + ]}) + ], + is_sugared_doc: false, + }], + generics: Generics::default(), + body: Body::Struct(VariantData::Unit), + }; + + let actual = parse_macro_input(raw).unwrap(); + + assert_eq!(expected, actual); + + assert!(actual.attrs[0].meta_item().is_none()); +}