macro_rules! tree_assertion { (@build $tree_assertion:expr,) => { ... }; (@build $tree_assertion:expr, var $key:ident: { $($sub:tt)* }) => { ... }; (@build $tree_assertion:expr, var $key:ident: { $($sub:tt)* }, $($rest:tt)*) => { ... }; (@build $tree_assertion:expr, var $key:ident: contains { $($sub:tt)* }) => { ... }; (@build $tree_assertion:expr, var $key:ident: contains { $($sub:tt)* }, $($rest:tt)*) => { ... }; (@build $tree_assertion:expr, var $key:ident: $assertion:expr) => { ... }; (@build $tree_assertion:expr, var $key:ident: $assertion:expr, $($rest:tt)*) => { ... }; (@build $tree_assertion:expr, $key:ident: $($rest:tt)+) => { ... }; (@build $tree_assertion:expr, ref $key:path: $($rest:tt)+) => { ... }; (@build $tree_assertion:expr, $key:tt: $($rest:tt)+) => { ... }; (@build $tree_assertion:expr, $key:expr => $($rest:tt)+) => { ... }; (@build $tree_assertion:expr, $child_assertion:expr, $($rest:tt)*) => { ... }; (var $key:ident: { $($sub:tt)* }) => { ... }; (var $key:ident: contains { $($sub:tt)* }) => { ... }; ($key:ident: $($rest:tt)+) => { ... }; ($key:tt: $($rest:tt)+) => { ... }; }
Expand description
Macro to simplify creating TreeAssertion
s. Commonly used indirectly through the second
parameter of assert_data_tree!
. See assert_data_tree!
for more usage examples.
Each leaf value must be a type that implements either PropertyAssertion
or TreeAssertion
.
Example:
// Manual creation of `TreeAssertion`.
let mut root = TreeAssertion::new("root", true);
root.add_property_assertion("a-string-property", Box::new("expected-string-value"));
let mut child = TreeAssertion::new("child", true);
child.add_property_assertion("any-property", Box::new(AnyProperty));
root.add_child_assertion(child);
root.add_child_assertion(opaque_child);
// Creation with `tree_assertion!`.
let root = tree_assertion!(
root: {
"a-string-property": "expected-string-value",
child: {
"any-property": AnyProperty,
},
opaque_child, // required trailing comma for `TreeAssertion` expressions
}
);
Note that TreeAssertion
s given directly to the macro must always be followed by ,
.