macro_rules! assert_expands {
(
{
#[ $macro_name:ident $(( $($attrs:tt)* ))? ]
$item:item
},
{
$($expanded:tt)*
}
) => { ... };
(
{
#[ $(::)? $_:ident :: $($macro_path:ident)::* $(( $($attrs:tt)* ))? ]
$item:item
},
{
$($expanded:tt)*
}
) => { ... };
}Expand description
Asserts that the first code block with attribute macro expands to the second code block.
The first code block must consist of a attribute macro and an item. The implementation function of the macro must
- present in the same scope with the same name as the attribute macro
- have a signature of
(macro_attributes: A, applied_item: I) -> Result<R, _>, whereAandIimplementFrom<proc_macro2::TokenStream>, andRimplementsInto<proc_macro2::TokenStream>
The second code block may consist of arbitrary tokens.
See also assert_yields! for macros
that does not modify the original input.
ยงExamples
use proc_macro_tester::assert_expands;
assert_expands!(
{
#[add_id_field(u32)]
struct Person {
name: String,
}
},
{
struct Person {
id: u32,
name: String,
}
}
);