macro_rules! unordered_elements_are {
($(,)?) => { ... };
($($matcher:expr),* $(,)?) => { ... };
}Expand description
Matches a JSON array whose elements, in any order, have a 1:1 correspondence with the provided matchers.
Each element in the input array must match exactly one of the given matchers, and vice versa. Matching fails if the input is not an array, if the number of elements and matchers differ, or if no perfect one-to-one mapping can be found.
§Example
This passes:
let value = j!(["a", "b", "c"]);
assert_that!(
value,
json::unordered_elements_are![
j!("c"),
eq("a"),
starts_with("b"),
]
);This fails because the element "x" does not match any expected element:
ⓘ
let value = j!(["a", "x", "c"]);
assert_that!(
value,
json::unordered_elements_are![
eq("c"),
eq("a"),
eq("b"),
]
);This fails because the input is not an array:
ⓘ
let value = json!("not an array");
assert_that!(
value,
json::unordered_elements_are![
eq("a"),
eq("b"),
]
);§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.