macro_rules! elements_are {
([$($matcher:expr),* $(,)?]) => { ... };
($($matcher:expr),* $(,)?) => { ... };
}Expand description
Matches a JSON array with elements that satisfy the given matchers, in order.
Each element of the JSON array is matched against a corresponding
Matcher. The array must have the same length
as the list of matchers, and all matchers must succeed.
This macro supports two forms:
- Bracketed:
elements_are!([matcher1, matcher2, ...]) - Unbracketed:
elements_are!(matcher1, matcher2, ...)
Callers should prefer the public-facing json::elements_are! macro.
§Examples
Basic usage:
let value = j!(["alex", "bart", "cucumberbatch"]);
assert_that!(
value,
json::elements_are![
j!("alex"),
starts_with("b"),
char_count(eq(13))
]
);Nested example:
let value = j!([["x", "y"], ["z"]]);
assert_that!(
value,
json::elements_are![
json::elements_are![j!("x"), eq("y")],
json::elements_are![eq("z")]
]
);§Notes
- Both JSON-aware and native GoogleTest matchers (such as
starts_with,contains_substring) can be used directly. - Wrapping with
json::primitive!is no longer needed. - Direct
serde_json::Valueinputs (e.g.json!(...)) are supported and compared by structural equality.