unordered_elements_are

Macro unordered_elements_are 

Source
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.

§Examples

This passes:

let value = json!(["a", "b", "c"]);
assert_that!(
    value,
    json::unordered_elements_are![
        eq("c"),
        eq("a"),
        starts_with("b"),
    ]
);

This fails because the element "x" does not match any expected element:

let value = json!(["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"),
    ]
);

§Alias

This macro is re-exported as json::unordered_elements_are!.