Trait assertor::VecAssertion[][src]

pub trait VecAssertion<'a, S, T, R> where
    AssertionResult: AssertionStrategy<R>,
    Self: Sized
{ fn contains<B>(&self, element: B) -> R
    where
        B: Borrow<T>,
        T: PartialEq + Debug
;
fn contains_exactly<B: Borrow<Vec<T>>>(self, expected_vec: B) -> R
    where
        T: PartialEq + Debug
;
fn contains_exactly_in_order<B: Borrow<Vec<T>>>(self, expected_vec: B) -> R
    where
        T: PartialEq + Debug
;
fn is_empty(&self) -> R
    where
        T: Debug
;
fn has_length(&self, length: usize) -> R; }
Expand description

Trait for vector assertion.

Compared to crate::IteratorAssertion, VecAssertion simplifies code because it is not needed to take reference of the expected value and to call vec.iter() in the actual value.

use assertor::*;
assert_that!(vec![1,2,3].iter()).contains(&2);  // IteratorAssertion
assert_that!(vec![1,2,3]).contains(2); // VecAssertion

Example

use assertor::*;
use assertor::VecAssertion;

assert_that!(Vec::<usize>::new()).is_empty();
assert_that!(vec![1,2,3]).has_length(3);
assert_that!(vec![1,2,3]).contains(2);
assert_that!(vec![1,2,3]).contains_exactly(vec![3,2,1]);
assert_that!(vec![1,2,3]).contains_exactly_in_order(vec![1,2,3]);

Required methods

Checks that the subject contains the element expected.

Example

use assertor::*;
assert_that!(vec![1, 2, 3]).contains(2);

Checks that the subject exactly contains elements of expected_vec.

This method doesn’t take care of the order. Use contains_exactly_in_order to check elements are in the same order.

Example

use assertor::*;
assert_that!(vec![1, 2, 3]).contains_exactly(vec![3, 2, 1]);
use assertor::*;
assert_that!(vec![1]).contains_exactly(vec![1,2]);
assert_that!(vec![1,2]).contains_exactly(vec![1]);

Checks that the subject exactly contains expected_vec in the same order.

Example

use assertor::*;
assert_that!(vec![1, 2, 3]).contains_exactly_in_order(vec![1, 2, 3]);
use assertor::*;
assert_that!(vec![1]).contains_exactly_in_order(vec![1,2]);
assert_that!(vec![1,2]).contains_exactly_in_order(vec![1]);

Checks that the subject is empty.

Example

use assertor::*;
assert_that!(Vec::<usize>::new()).is_empty();

Checks that the subject is the given length.

Example

use assertor::*;
assert_that!(vec![1, 2, 3]).has_length(3);

Implementors