Macro databake::test_bake

source ·
macro_rules! test_bake {
    ($type:ty, const, $expr:expr $(, $krate:ident)? $(, [$($env_crate:ident),+])? $(,)?) => { ... };
    ($type:ty, $expr:expr $(, $krate:ident)? $(, [$($env_crate:ident),+])? $(,)?) => { ... };
}
Expand description

This macro tests that an expression evaluates to a value that bakes to the same expression.

Its mandatory arguments are a type and an expression (of that type).

test_bake!(usize, 18usize);

§Const

We usually want baked output to be const constructible. To test this, add the const: prefix to the expression:

test_bake!(usize, const, 18usize);

§Crates and imports

As most output will need to reference its crate, and its not possible to name a crate from within it, a third parameter can be used to specify the crate name. The crate identifier in the original expression will be replaced by this in the expected output.

test_bake!(
    MyStruct,
    crate::MyStruct(42usize), // matches `::my_crate::MyStruct(42usize)`
    my_crate,
);

A fourth, optional, parameter is a list of crate names that are expected to be added to the CrateEnv. The crate-replacement crate will always be checked.