Skip to main content

matches_struct

Macro matches_struct 

Source
matches_struct!() { /* proc-macro */ }
Expand description

Matches a struct by applying an inner matcher to each named field.

Without a trailing .. every field must be listed, exactly as in a struct pattern; with .. the unlisted fields are ignored.

use test_better::prelude::*;
use test_better::matches_struct;

#[derive(Debug)]
struct User {
    name: String,
    age: u32,
    email: String,
}

fn check(user: User) -> TestResult {
    check!(user).satisfies(matches_struct!(User {
        name: eq(String::from("alice")),
        age: gt(0u32),
        email: contains_str("@"),
        .. // remaining fields ignored
    }))?;
    Ok(())
}