Struct Assert

Source
pub struct Assert<T> { /* private fields */ }

Implementations§

Source§

impl<T> Assert<T>

Entry point for the Assert DSL.

Assert provides a fluent API for assertions. An Assert holds the actual value that can be used in assertion statements.

Assert::that(3).is(3);
Source

pub fn that(actual: T) -> Self

Create an Assert instance for the actual value.

All assertions start with Assert::that(actual).

Source

pub fn map<R>(self, f: impl Fn(T) -> R) -> Assert<R>

Maps the actual value using lambda f.

This method is intended to map the actual value in order to apply further assertions.

Assert::that("3")
    .map(|v| v.parse::<i32>().unwrap())
    .is(3);
Source§

impl<T> Assert<Option<T>>
where T: PartialEq + Debug,

DSL for Option assertions.

Source

pub fn is_some(self, expected: T) -> Self

Assert that actual is equal to Some `expected’ value.

Source

pub fn is_none(self) -> Self

Assert that actual is equal to None.

Source

pub fn unwrap(self) -> Assert<T>

Unwrap the Option value, panic for None.

Source§

impl<T> Assert<Vec<T>>
where T: PartialEq + Debug,

Assert DSL for Vec.

Source

pub fn contains(self, expected: T) -> Self

Assert that the actual vector contains a specific expected value.

Assert::that(vec![1, 2, 3]).contains(2);
Source

pub fn get(&mut self, index: usize) -> Assert<Option<T>>

Returns an Assert for a value from the Vec.

Assert::that(vec!['a', 'b', 'c']).get(1).is_some('b');
Assert::that(vec!['a', 'b', 'c']).get(5).is_none();

Trait Implementations§

Source§

impl<T, R> AssertEquals<R> for Assert<T>
where T: PartialEq<R> + Debug, R: Debug,

Default implementation of AssertEquals.

Source§

fn is(self, expected: R) -> Self

Assert that self is equal to the expected value.
Source§

fn is_not(self, other: R) -> Self

Assert that self is not equal to the other value.

Auto Trait Implementations§

§

impl<T> Freeze for Assert<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Assert<T>
where T: RefUnwindSafe,

§

impl<T> Send for Assert<T>
where T: Send,

§

impl<T> Sync for Assert<T>
where T: Sync,

§

impl<T> Unpin for Assert<T>
where T: Unpin,

§

impl<T> UnwindSafe for Assert<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.