Function galvanic_assert::matchers::collection::has_entry [] [src]

pub fn has_entry<'a, K: 'a, V: 'a, M: 'a>(
    key: K,
    value: V
) -> Box<Matcher<'a, M> + 'a> where
    &'a M: IntoIterator<Item = (&'a K, &'a V)> + 'a,
    HasEntry<K, V>: Matcher<'a, M>, 

Matches if the map-like collection contains the given key/value pair.

The Matcher tests for this by converting the map-like data structure into a key/value pair iterator.

The alternative would be to use the Index trait though experiments showed that this would not be composable with all_of! or any_of!.

Examples

use galvanic_assert::matchers::collection::*;
let mut map = std::collections::HashMap::<i32,i32>::new();
map.insert(0, 2);
map.insert(1, 2);
map.insert(2, 5);
map.insert(3, 3);
map.insert(4, 3);

assert_that!(&map, has_entry(1, 2));