Skip to main content

AssertIteratorContainsInOrder

Trait AssertIteratorContainsInOrder 

Source
pub trait AssertIteratorContainsInOrder<E> {
    type Sequence;

    // Required methods
    fn contains_exactly(self, expected: E) -> Self::Sequence;
    fn contains_sequence(self, expected: E) -> Self::Sequence;
    fn contains_all_in_order(self, expected: E) -> Self::Sequence;
    fn starts_with(self, expected: E) -> Self::Sequence;
    fn ends_with(self, expected: E) -> Self::Sequence;
}
Expand description

Assert values in an ordered collection.

These assertions are applicable to collections which iterate over their values in a defined order.

Required Associated Types§

Source

type Sequence

A spec-like type that contains the collected values from the iterator as the subject, which is returned by the mapping assertion methods.

Usually this a Spec<'a, Vec<T>, R> with T as the type of the items yielded by the iterator.

Required Methods§

Source

fn contains_exactly(self, expected: E) -> Self::Sequence

Verifies that the actual collection/iterator contains exactly the given values and nothing else in the given order.

§Examples
use asserting::prelude::*;
use std::collections::BTreeMap;

let some_array = [1, 3, 5, 7];
assert_that!(some_array).contains_exactly([1, 3, 5, 7]);

let some_slice = &['b', 'X', 'k', 'G'][..];
assert_that!(some_slice).contains_exactly(&['b', 'X', 'k', 'G']);

let some_vec = vec![12, 4, 6, 10, 8];
assert_that!(some_vec).contains_exactly([12, 4, 6, 10, 8]);

let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
assert_that!(some_btree_map).contains_exactly([('a', 3), ('b', 0), ('c', 8)]);
Source

fn contains_sequence(self, expected: E) -> Self::Sequence

Verifies that the actual collection/iterator contains the given sequence of values in the given order and without extra values between the sequence values.

May contain more values as in the given sequence before and after the sequence.

§Examples
use asserting::prelude::*;
use std::collections::BTreeMap;

let some_array = [1, 3, 5, 7, 9];
assert_that!(some_array).contains_sequence([3, 5, 7]);

let some_slice = &['b', 'X', 'k', 'G'][..];
assert_that!(some_slice).contains_sequence(&['b', 'X']);

let some_vec = vec![12, 4, 6, 10, 8];
assert_that!(some_vec).contains_sequence([6, 10, 8]);

let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
assert_that!(some_btree_map).contains_sequence([('a', 3), ('b', 0), ('c', 8)]);
Source

fn contains_all_in_order(self, expected: E) -> Self::Sequence

Verifies that the actual collection/iterator contains all the given values and in the given order, possibly with other values between them.

§Examples
use asserting::prelude::*;
use std::collections::BTreeMap;

let some_array = [1, 3, 5, 7, 9];
assert_that!(some_array).contains_all_in_order([3, 5, 9]);

let some_slice = &['b', 'X', 'k', 'G'][..];
assert_that!(some_slice).contains_all_in_order(&['b', 'G']);

let some_vec = vec![12, 4, 6, 10, 8];
assert_that!(some_vec).contains_all_in_order([12, 4, 10, 8]);

let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
assert_that!(some_btree_map).contains_all_in_order([('a', 3), ('c', 8)]);
Source

fn starts_with(self, expected: E) -> Self::Sequence

Verifies that the actual collection/iterator contains the given values as the first elements in order.

§Examples
use asserting::prelude::*;
use std::collections::BTreeMap;

let some_array = [1, 3, 5, 7];
assert_that!(some_array).starts_with([1, 3, 5]);

let some_slice = &['b', 'X', 'k', 'G'][..];
assert_that!(some_slice).starts_with(&['b', 'X']);

let some_vec = vec![12, 4, 6, 10, 8];
assert_that!(some_vec).starts_with([12, 4, 6]);

let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
assert_that!(some_btree_map).starts_with([('a', 3), ('b', 0)]);
Source

fn ends_with(self, expected: E) -> Self::Sequence

Verifies that the actual collection/iterator contains the given values as the last elements in order.

§Examples
use asserting::prelude::*;
use std::collections::BTreeMap;

let some_array = [1, 3, 5, 7];
assert_that!(some_array).ends_with([3, 5, 7]);

let some_slice = &['b', 'X', 'k', 'G'][..];
assert_that!(some_slice).ends_with(&['k', 'G']);

let some_vec = vec![12, 4, 6, 10, 8];
assert_that!(some_vec).ends_with([10, 8]);

let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
assert_that!(some_btree_map).ends_with([('b', 0), ('c', 8)]);

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§