VecAssertion

Trait VecAssertion 

Source
pub trait VecAssertion<'a, S, T, R>{
    // Required methods
    fn contains<B>(&self, element: B) -> R
       where B: Borrow<T>,
             T: PartialEq + Debug;
    fn does_not_contain<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 does_not_contain_any<B: Borrow<Vec<T>>>(&self, elements: B) -> R
       where T: PartialEq + Debug;
    fn is_empty(&self) -> R
       where T: Debug;
    fn is_not_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§

Source

fn contains<B>(&self, element: B) -> R
where B: Borrow<T>, T: PartialEq + Debug,

Checks that the subject contains the element expected.

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

fn does_not_contain<B>(&self, element: B) -> R
where B: Borrow<T>, T: PartialEq + Debug,

Checks that the subject does not contains the element.

§Example
use assertor::*;
assert_that!(vec![1, 2, 3]).does_not_contain(5);
Source

fn contains_exactly<B: Borrow<Vec<T>>>(self, expected_vec: B) -> R
where T: PartialEq + Debug,

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]);
Source

fn contains_exactly_in_order<B: Borrow<Vec<T>>>(self, expected_vec: B) -> R
where T: PartialEq + Debug,

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]);
Source

fn does_not_contain_any<B: Borrow<Vec<T>>>(&self, elements: B) -> R
where T: PartialEq + Debug,

Checks that the subject does not contain any element of elements.

§Example
use assertor::*;
assert_that!(vec![1, 2, 3]).does_not_contain_any(vec![0, -5]);
use assertor::*;
assert_that!(vec![1,2]).does_not_contain_any(vec![1]);
Source

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

Checks that the subject is empty.

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

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

Checks that the subject is not empty.

§Example
use assertor::*;
assert_that!(vec![1]).is_not_empty();
Source

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

Checks that the subject is the given length.

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

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, T, R> VecAssertion<'a, Vec<T>, T, R> for Subject<'a, Vec<T>, (), R>