pub trait IteratorAssertion<'a, S, T, R>where
AssertionResult: AssertionStrategy<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<EI: Iterator<Item = T> + Clone>(
self,
expected_iter: EI,
) -> R
where T: PartialEq + Debug;
fn contains_exactly_in_order<EI: Iterator<Item = T> + Clone>(
self,
expected_iter: EI,
) -> R
where T: PartialEq + Debug;
fn contains_all_of<EI: Iterator<Item = T> + Clone>(
self,
expected_iter: EI,
) -> R
where T: PartialEq + Debug;
fn does_not_contain_any<EI: Iterator<Item = T> + Clone>(
&self,
elements: EI,
) -> R
where T: PartialEq + Debug;
fn contains_all_of_in_order<EI: Iterator<Item = T> + Clone>(
self,
expected_iter: EI,
) -> 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
where T: Debug;
}Expand description
Trait for iterator assertion.
§Example
use assertor::*;
assert_that!(Vec::<usize>::new()).is_empty();
assert_that!(vec![1,2,3].iter()).contains(&2);
assert_that!(vec![1,2,3].iter()).contains_exactly(vec![3,2,1].iter());
assert_that!(vec![1,2,3].iter()).contains_exactly_in_order(vec![1,2,3].iter());use assertor::*;
assert_that!(vec![1,2,3].iter()).contains(&4); // <- Panic here
// expected to contain : 4
// but did not
// though it did contain: [1, 2, 3]use assertor::*;
assert_that!(vec![1,2,3].iter()).contains_exactly_in_order(vec![3,2,1].iter()); // <- Panic here
// contents match, but order was wrong
// ---
// expected: [3, 2, 1]
// actual : [1, 2, 3]Required Methods§
Sourcefn contains<B>(&self, element: B) -> R
fn contains<B>(&self, element: B) -> R
Checks that the subject iterator contains the element expected.
§Example
use assertor::*;
assert_that!(vec![1, 2, 3].iter()).contains(&2);
assert_that!("foobar".chars()).contains(&'a');use assertor::*;
assert_that!("foobar".chars()).contains(&'z');
// expected to contain : 'z'
// but did not
// though it did contain: ['f', 'o', 'o', 'b', 'a', 'r']§Related:
Sourcefn does_not_contain<B>(&self, element: B) -> R
fn does_not_contain<B>(&self, element: B) -> R
Checks that the subject iterator does not contains the element expected.
§Example
use assertor::*;
assert_that!(vec![1, 2, 3].iter()).does_not_contain(&5);
assert_that!("foobar".chars()).does_not_contain(&'x');use assertor::*;
assert_that!("foobar".chars()).does_not_contain(&'a');
// expected to not contain : 'a'
// but element was found
// though it did contain: ['f', 'o', 'o', 'b', 'a', 'r']§Related:
Sourcefn contains_exactly<EI: Iterator<Item = T> + Clone>(
self,
expected_iter: EI,
) -> R
fn contains_exactly<EI: Iterator<Item = T> + Clone>( self, expected_iter: EI, ) -> R
Checks that the subject exactly contains elements of expected_iter.
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].iter()).contains_exactly(vec![3, 2, 1].iter());
assert_that!("foobarbaz".chars()).contains_exactly("bazbarfoo".chars());use assertor::*;
assert_that!("foobarbaz".chars()).contains_exactly("bazbar".chars());
// unexpected (3): ['f', 'o', 'o']
//---
// expected : ['b', 'a', 'z', 'b', 'a', 'r']
// actual : ['f', 'o', 'o', 'b', 'a', 'r', 'b', 'a', 'z']Sourcefn contains_exactly_in_order<EI: Iterator<Item = T> + Clone>(
self,
expected_iter: EI,
) -> R
fn contains_exactly_in_order<EI: Iterator<Item = T> + Clone>( self, expected_iter: EI, ) -> R
Checks that the subject exactly contains elements of expected_iter in the same order.
§Example
use assertor::*;
assert_that!(vec![1, 2, 3].iter()).contains_exactly_in_order(vec![1, 2, 3].iter());
assert_that!("foobarbaz".chars()).contains_exactly_in_order("foobarbaz".chars());use assertor::*;
assert_that!("foobarbaz".chars()).contains_exactly_in_order("bazbar".chars());
// unexpected (3): ['f', 'o', 'o']
//---
// expected : ['b', 'a', 'z', 'b', 'a', 'r']
// actual : ['f', 'o', 'o', 'b', 'a', 'r', 'b', 'a', 'z']use assertor::*;
assert_that!("foobarbaz".chars()).contains_exactly_in_order("bazbarfoo".chars());
// contents match, but order was wrong
// ---
// expected: ['b', 'a', 'z', 'b', 'a', 'r', 'f', 'o', 'o']
// actual : ['f', 'o', 'o', 'b', 'a', 'r', 'b', 'a', 'z']Sourcefn contains_all_of<EI: Iterator<Item = T> + Clone>(self, expected_iter: EI) -> R
fn contains_all_of<EI: Iterator<Item = T> + Clone>(self, expected_iter: EI) -> R
Checks that the subject contains at least all elements of expected_iter.
This method doesn’t take care of the order. Use contains_all_of_in_order to check elements are in the same order.
§Example
use assertor::*;
assert_that!(vec![1, 2, 3].iter()).contains_all_of(vec![2, 3].iter());
assert_that!("foobarbaz".chars()).contains_all_of("bazbar".chars());Sourcefn does_not_contain_any<EI: Iterator<Item = T> + Clone>(
&self,
elements: EI,
) -> R
fn does_not_contain_any<EI: Iterator<Item = T> + Clone>( &self, elements: EI, ) -> R
Checks that the subject does not contains any elements of elements.
§Example
use assertor::*;
assert_that!(vec![1, 2, 3].iter()).does_not_contain_any(vec![0, -5].iter());
assert_that!("foobarbaz".chars()).does_not_contain_any("xyw".chars());use assertor::*;
assert_that!("foobarbaz".chars()).does_not_contain_any("ab".chars());
// unexpected (2): ['a', 'b']
//---
// expected to contain none of : ['a', 'b']
// but was : ['f', 'o', 'o', 'b', 'a', 'r', 'b', 'a', 'z']Sourcefn contains_all_of_in_order<EI: Iterator<Item = T> + Clone>(
self,
expected_iter: EI,
) -> R
fn contains_all_of_in_order<EI: Iterator<Item = T> + Clone>( self, expected_iter: EI, ) -> R
Checks that the subject contains at least all elements of expected_iter in the same order.
§Example
use assertor::*;
assert_that!(vec![1, 2, 3].iter()).contains_all_of_in_order(vec![2, 3].iter());
assert_that!("foobarbaz".chars()).contains_all_of_in_order("obarb".chars());Sourcefn is_not_empty(&self) -> Rwhere
T: Debug,
fn is_not_empty(&self) -> Rwhere
T: Debug,
Sourcefn has_length(&self, length: usize) -> Rwhere
T: Debug,
fn has_length(&self, length: usize) -> Rwhere
T: Debug,
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.