Struct smoothy::BasicAsserter

source ·
pub struct BasicAsserter<AssertedType> { /* private fields */ }
Expand description

Main struct with various assertions on AssertedType

Implementations§

source§

impl<AssertedType> BasicAsserter<AssertedType>where AssertedType: PartialEq + Debug,

source

pub fn equals(self, expected: impl Into<AssertedType>)

Asserts that the assertable is equal to the expected value.

This is done by transforming the expected-value to a instance of AssertedType by using the Into-trait and then comparing both values with PartialEq

Examples
assert_that(String::from("Hello World!")).equals("Hello World!");
Panics

When the values are not matching according to PartialEq

source§

impl<AssertedType> BasicAsserter<AssertedType>where AssertedType: PartialEq + Debug,

source

pub fn is(self, expected: AssertedType)

Asserts that the assertable is equal to the expected value while having the same type.

Examples
assert_that("Hello World!").is("Hello World!");
Panics

When the values are not matching.

source§

impl<AssertedType> BasicAsserter<AssertedType>where AssertedType: PartialEq + Debug,

source

pub fn is_not(self, expected: AssertedType)

Asserts that the assertable is not equal to the expected value while having the same type.

Examples
assert_that("Hello World!").is_not("Hello There!");
Panics

When the values are matching.

source§

impl<AssertedType> BasicAsserter<AssertedType>where AssertedType: PartialEq + Debug,

source

pub fn not_equals(self, expected: impl Into<AssertedType>)

Asserts that the assertable is not equal to the expected value.

This is done by transforming the expected-value to a instance of AssertedType by using the Into-trait and then comparing both values with PartialEq

Examples
assert_that(String::from("Hello World!")).not_equals("Hello There!");
Panics

When the values are matching according to PartialEq

source§

impl<AssertedType> BasicAsserter<AssertedType>where AssertedType: ToString,

source

pub fn to_string(self) -> BasicAsserter<String>

Converts the assertable to a string for futher assertions

Examples
let asserter: BasicAsserter<String> = assert_that(42).to_string();
// further assertions
asserter.equals("42");
source§

impl<AssertedType> BasicAsserter<AssertedType>where AssertedType: PartialEq + Debug,

source

pub fn try_into_equals<T>(self, expected: T)where T: TryInto<AssertedType>, <T as TryInto<AssertedType>>::Error: Debug,

Asserts that the assertable is equal to the expected value.

This is done by transforming the expected-value to a instance of AssertedType by using the TryInto-trait and then comparing both values with PartialEq

Examples
assert_that(42u8).try_into_equals(42i8);
Panics

When the transformation fails or the values are not matching according to PartialEq

source§

impl<AssertedType> BasicAsserter<AssertedType>where AssertedType: PartialEq + Debug,

source

pub fn try_into_not_equals<T>(self, expected: T)where T: TryInto<AssertedType>, <T as TryInto<AssertedType>>::Error: Debug,

Asserts that the assertable is not equal to the expected value.

This is done by transforming the expected-value to a instance of AssertedType by using the TryInto-trait and then comparing both values with PartialEq

Examples
assert_that(42u8).try_into_not_equals(100i8);
Panics

When the transformation fails or the values are matching according to PartialEq

source§

impl<SomeValue> BasicAsserter<Option<SomeValue>>where SomeValue: Debug,

source

pub fn is_none(self)

Asserts that the Option is None.

Examples
let option: Option<String> = None;

assert_that(option).is_none();
Panics

When the Option is Some

source§

impl<SomeValue> BasicAsserter<Option<SomeValue>>where SomeValue: Debug,

source

pub fn is_some(self) -> SomeAsserter<SomeValue>

Asserts that the Option is Some.

Allows the usage of chained assertions on an option-type (see SomeAsserter).

Examples
let option: Option<String> = Some(String::new());

assert_that(option).is_some();
Panics

When the Option is None

source§

impl<OkValue, ErrValue> BasicAsserter<Result<OkValue, ErrValue>>where OkValue: Debug, ErrValue: Debug,

source

pub fn is_err(self) -> ErrAsserter<ErrValue>

Asserts that the Result is an Err.

Allows the usage of chained assertions on an error-type (see ErrAsserter).

Examples
let result: Result<(), String> = Err(String::new());

assert_that(result).is_err();
Panics

When the Result is an Ok

source§

impl<OkValue, ErrValue> BasicAsserter<Result<OkValue, ErrValue>>where OkValue: Debug + PartialEq, ErrValue: Debug + PartialEq,

source

pub fn is_ok(self) -> OkAsserter<OkValue>

Asserts that the Result is an Ok.

Allows the usage of chained assertions on an ok-value (see OkAsserter).

Examples
let result: Result<String, ()> = Ok(String::new());

assert_that(result).is_ok();
Panics

When the Result is an Err

Auto Trait Implementations§

§

impl<AssertedType> RefUnwindSafe for BasicAsserter<AssertedType>where AssertedType: RefUnwindSafe,

§

impl<AssertedType> Send for BasicAsserter<AssertedType>where AssertedType: Send,

§

impl<AssertedType> Sync for BasicAsserter<AssertedType>where AssertedType: Sync,

§

impl<AssertedType> Unpin for BasicAsserter<AssertedType>where AssertedType: Unpin,

§

impl<AssertedType> UnwindSafe for BasicAsserter<AssertedType>where AssertedType: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.