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§
Sourcefn contains<B>(&self, element: B) -> R
fn contains<B>(&self, element: B) -> R
Checks that the subject contains the element expected.
§Example
use assertor::*;
assert_that!(vec![1, 2, 3]).contains(2);Sourcefn does_not_contain<B>(&self, element: B) -> R
fn does_not_contain<B>(&self, element: B) -> R
Checks that the subject does not contains the element.
§Example
use assertor::*;
assert_that!(vec![1, 2, 3]).does_not_contain(5);Sourcefn contains_exactly<B: Borrow<Vec<T>>>(self, expected_vec: B) -> R
fn contains_exactly<B: Borrow<Vec<T>>>(self, expected_vec: B) -> R
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]);Sourcefn contains_exactly_in_order<B: Borrow<Vec<T>>>(self, expected_vec: B) -> R
fn contains_exactly_in_order<B: Borrow<Vec<T>>>(self, expected_vec: B) -> R
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]);Sourcefn does_not_contain_any<B: Borrow<Vec<T>>>(&self, elements: B) -> R
fn does_not_contain_any<B: Borrow<Vec<T>>>(&self, elements: B) -> R
Sourcefn is_empty(&self) -> Rwhere
T: Debug,
fn is_empty(&self) -> Rwhere
T: Debug,
Checks that the subject is empty.
§Example
use assertor::*;
assert_that!(Vec::<usize>::new()).is_empty();Sourcefn is_not_empty(&self) -> Rwhere
T: Debug,
fn is_not_empty(&self) -> Rwhere
T: Debug,
Checks that the subject is not empty.
§Example
use assertor::*;
assert_that!(vec![1]).is_not_empty();Sourcefn has_length(&self, length: usize) -> R
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.