Function xpct::match_fields
source · pub fn match_fields<'a, T>(spec: FieldsSpec<'a, T>) -> Matcher<'a, T, ()>where
T: 'a,
Expand description
Succeeds when all the fields of a struct succeed.
This matcher operates on a struct and allows for matching on each field separately. This is used
with the fields!
macro.
This succeeds when each field of the struct succeeds, and skipping/omitting fields does not make it fail.
This matcher can be used for both regular structs and tuple structs. See fields!
for
details.
Examples
use xpct::{be_gt, be_some, be_true, expect, fields, have_prefix, match_fields};
struct Person {
id: String,
name: Option<String>,
age: u32,
is_superstar: bool,
}
let value = Person {
id: String::from("REV12-62-05-JAM41"),
name: Some(String::from("Raphaël")),
age: 44,
is_superstar: true,
};
expect!(value).to(match_fields(fields!(Person {
id: have_prefix("REV"),
name: be_some(),
age: be_gt(0),
is_superstar: be_true(),
})));