Macro assert_expands

Source
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

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,
        }
    }
);