MapAssertion

Trait MapAssertion 

Source
pub trait MapAssertion<'a, K: 'a + Eq, V, ML, R>
where AssertionResult: AssertionStrategy<R>, ML: MapLike<K, V>,
{ // Required methods fn has_length(&self, length: usize) -> R; fn is_empty(&self) -> R where K: Debug; fn is_not_empty(&self) -> R where K: Debug; fn contains_key<BK>(&self, key: BK) -> R where BK: Borrow<K>, K: Eq + Hash + Debug; fn does_not_contain_key<BK>(&self, key: BK) -> R where BK: Borrow<K>, K: Eq + Hash + Debug; fn contains_entry<BK, BV>(&self, key: BK, value: BV) -> R where BK: Borrow<K>, BV: Borrow<V>, K: Eq + Hash + Debug, V: Eq + Debug; fn does_not_contain_entry<BK, BV>(&self, key: BK, value: BV) -> R where BK: Borrow<K>, BV: Borrow<V>, K: Eq + Hash + Debug, V: Eq + Debug; fn contains_at_least<BM, OML>(&self, expected: BM) -> R where K: Eq + Hash + Debug, V: Eq + Debug, OML: MapLike<K, V> + 'a, BM: Borrow<OML> + 'a; fn does_not_contain_any<BM, OML>(&self, expected: BM) -> R where K: Eq + Hash + Debug, V: Eq + Debug, OML: MapLike<K, V> + 'a, BM: Borrow<OML> + 'a; fn contains_exactly<BM, OML>(&self, expected: BM) -> R where K: Eq + Hash + Debug, V: Eq + Debug, OML: MapLike<K, V> + 'a, BM: Borrow<OML> + 'a; fn key_set<'b>(&'b self) -> Subject<'_, ML::It<'b>, (), R> where K: 'b; }
Expand description

Trait for map assertion.

§Example

use std::collections::HashMap;
use assertor::*;

let mut map = HashMap::new();
assert_that!(map).is_empty();

map.insert("one", 1);
map.insert("two", 2);
map.insert("three", 3);

assert_that!(map).has_length(3);
assert_that!(map).contains_key("one");
assert_that!(map).key_set().contains_exactly(vec!["three","two","one"].iter());

Required Methods§

Source

fn has_length(&self, length: usize) -> R

Checks that the subject has the given length.

Source

fn is_empty(&self) -> R
where K: Debug,

Checks that the subject is empty.

Source

fn is_not_empty(&self) -> R
where K: Debug,

Checks that the subject is not empty.

Source

fn contains_key<BK>(&self, key: BK) -> R
where BK: Borrow<K>, K: Eq + Hash + Debug,

Checks that the subject has the given key.

Source

fn does_not_contain_key<BK>(&self, key: BK) -> R
where BK: Borrow<K>, K: Eq + Hash + Debug,

Checks that the subject does not have the given key.

Source

fn contains_entry<BK, BV>(&self, key: BK, value: BV) -> R
where BK: Borrow<K>, BV: Borrow<V>, K: Eq + Hash + Debug, V: Eq + Debug,

Checks that the subject has entry with the given key and value.

Source

fn does_not_contain_entry<BK, BV>(&self, key: BK, value: BV) -> R
where BK: Borrow<K>, BV: Borrow<V>, K: Eq + Hash + Debug, V: Eq + Debug,

Checks that the subject does not contain entry with the given key and value.

Source

fn contains_at_least<BM, OML>(&self, expected: BM) -> R
where K: Eq + Hash + Debug, V: Eq + Debug, OML: MapLike<K, V> + 'a, BM: Borrow<OML> + 'a,

Checks that the subject contains all entries from expected.

Source

fn does_not_contain_any<BM, OML>(&self, expected: BM) -> R
where K: Eq + Hash + Debug, V: Eq + Debug, OML: MapLike<K, V> + 'a, BM: Borrow<OML> + 'a,

Checks that the subject does not contain any entries from expected.

Source

fn contains_exactly<BM, OML>(&self, expected: BM) -> R
where K: Eq + Hash + Debug, V: Eq + Debug, OML: MapLike<K, V> + 'a, BM: Borrow<OML> + 'a,

Checks that the subject contains only entries from expected.

Source

fn key_set<'b>(&'b self) -> Subject<'_, ML::It<'b>, (), R>
where K: 'b,

Returns a new subject which is an key set of the subject and which implements crate::IteratorAssertion.

§Example
use std::collections::HashMap;
use assertor::*;
use assertor::IteratorAssertion;

let mut map = HashMap::new();
map.insert("one", 1);
map.insert("two", 2);
map.insert("three", 3);

assert_that!(map).key_set().contains(&"one");
assert_that!(map).key_set().contains_exactly(vec!["three","two","one"].iter());
assert_that!(map).key_set().contains_all_of(vec!["one", "two"].iter());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, K, V, ML, R> MapAssertion<'a, K, V, ML, R> for Subject<'a, ML, (), R>
where AssertionResult: AssertionStrategy<R>, K: 'a + Eq, ML: MapLike<K, V>,