macro_rules! pat {
(@wrap_matcher $lit:literal) => { ... };
(@wrap_matcher $expr:expr) => { ... };
({ $($key:literal : $val:expr),* $(,)? }) => { ... };
({ $($key:literal : $val:expr),* , .. }) => { ... };
}Expand description
Matches a JSON object against a pattern of key-value matchers.
Fields listed in the pattern must match; a trailing .. allows extra fields.
§Examples
let value = j!({
"name": "Alice",
"age": 30,
"active": true,
"role": j!("admin")
});
assert_that!(
value,
json::pat!({
"name": starts_with("Al"),
"age": ge(29),
"active": true,
"role": j!("admin"),
.. // allows additional fields
})
);§Errors
Fails when the value is not a JSON object, when a required field is missing, when a field value mismatches, or when extra fields appear without ...
This macro is reexported as json::pat!.
§Supported Inputs
- Literal JSON-compatible values
- Direct
serde_json::Value - Native googletest matchers