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.
§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.
§Example
let value = j!(["alex", "bart", "cucumberbatch"]);
assert_that!(
value,
json::elements_are![starts_with("a"), eq("bart"), char_count(eq(13))]
);Nested example:
let value = j!([["x", "y"], ["z"]]);
assert_that!(
value,
json::elements_are![
json::elements_are![eq("x"), eq("y")],
json::elements_are![eq("z")]
]
);