Skip to main content

Assertion

Struct Assertion 

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

Implementations§

Source§

impl Assertion<bool>

Specific assertions for booleans

Source

pub fn be_true(self) -> Self

Asserts that the value is true

§Examples
use fluent_assertions::*;
true.should().be_true();
Source

pub fn be_false(self) -> Self

Asserts that the value is false

§Examples
use fluent_assertions::*;
false.should().be_false();
Source§

impl<E: Error> Assertion<E>

Source

pub fn match_error<T: Error + Debug>(self, error: T) -> Self

Asserts that the error is equal to the given error

§Examples
use fluent_assertions::*;
std::io::Error::other("boom")
    .should()
    .match_error(std::io::Error::other("boom"));
Source

pub fn contain_message(self, expected_message: &str) -> Self

Asserts that the error message contains the given message

§Examples
use fluent_assertions::*;
std::io::Error::other("boom happened").should().contain_message("boom");
Source§

impl<T> Assertion<T>
where T: PartialOrd + Display + Zero + Copy,

Specific assertions for numeric types

Source

pub fn be_greater_than_or_equal_to(self, other: T) -> Self

Asserts that the value is greater than or equal to the given value

§Examples
use fluent_assertions::*;
5.should().be_greater_than_or_equal_to(5);
Source

pub fn be_greater_than(self, other: T) -> Self

Asserts that the value is greater than the given value

§Examples
use fluent_assertions::*;
5.should().be_greater_than(4);
Source

pub fn be_less_than_or_equal_to(self, other: T) -> Self

Asserts that the value is less than or equal to the given value

§Examples
use fluent_assertions::*;
5.should().be_less_than_or_equal_to(5);
Source

pub fn be_less_than(self, other: T) -> Self

Asserts that the value is less than the given value

§Examples
use fluent_assertions::*;
5.should().be_less_than(6);
Source

pub fn be_positive(self) -> Self

Asserts that the value is positive

§Examples
use fluent_assertions::*;
5.should().be_positive();
Source

pub fn be_negative(self) -> Self

Asserts that the value is negative

§Examples
use fluent_assertions::*;
(-5).should().be_negative();
Source

pub fn be_in_range(self, range: impl RangeBounds<T> + Debug) -> Self

Asserts that the value is in the given range

§Examples
use fluent_assertions::*;
5.should().be_in_range(1..=10);
Source

pub fn not_be_in_range(self, range: impl RangeBounds<T> + Debug) -> Self

Asserts that the value is not in the given range

§Examples
use fluent_assertions::*;
20.should().not_be_in_range(1..=10);
Source§

impl<T> Assertion<T>
where T: Float + Display,

Specific assertions for floating-point types

Source

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

Asserts that the value is within tolerance of expected

The tolerance bound is inclusive: a difference exactly equal to tolerance still passes.

§Examples
use fluent_assertions::*;
// The difference is exactly 0.5, and the inclusive bound accepts it.
0.5_f64.should().be_close_to(1.0, 0.5);
Source§

impl<T: Debug + PartialEq> Assertion<Option<T>>

Source

pub fn be_some(self) -> Assertion<T>

Asserts that the Option is Some and unwraps it into an Assertion<T>

§Examples
use fluent_assertions::*;
Some(5).should().be_some().be(5);
Source

pub fn be_none(self) -> Self

Asserts that the Option is None

§Examples
use fluent_assertions::*;
None::<i32>.should().be_none();
Source§

impl<T, E> Assertion<Result<T, E>>
where T: Debug, E: Debug,

Specific assertions for Result types

Source

pub fn be_ok(self) -> Assertion<T>

Asserts that the Result is Ok

§Examples
use fluent_assertions::*;
Ok::<i32, String>(42).should().be_ok().be(42);
Source

pub fn be_err(self) -> Assertion<E>

Asserts that the Result is Err

§Examples
use fluent_assertions::*;
Err::<i32, String>("boom".to_string()).should().be_err().be("boom");
Source§

impl<T: AsRef<str>> Assertion<T>

Specific assertions for strings

Source

pub fn be_empty(self) -> Self

Asserts that the string is empty

§Examples
use fluent_assertions::*;
"".should().be_empty();
Source

pub fn not_be_empty(self) -> Self

Asserts that the string is not empty

§Examples
use fluent_assertions::*;
"hello".should().not_be_empty();
Source

pub fn start_with(self, prefix: &str) -> Self

Asserts that the string starts with a given prefix

§Examples
use fluent_assertions::*;
"hello world".should().start_with("hello");
Source

pub fn end_with(self, suffix: &str) -> Self

Asserts that the string ends with a given suffix

§Examples
use fluent_assertions::*;
"hello world".should().end_with("world");
Source

pub fn contain(self, substring: &str) -> Self

Asserts that the string contains a given substring

§Examples
use fluent_assertions::*;
"hello world".should().contain("lo wo");
Source

pub fn have_length(self, length: usize) -> Self

Asserts that the string has a given length

The length is measured with str::len, i.e. the number of bytes, not the number of characters. For strings containing multi-byte UTF-8 characters these two counts differ.

§Examples
use fluent_assertions::*;
"hello".should().have_length(5);
// Bytes, not chars: 'é' is a two-byte UTF-8 sequence.
"é".should().have_length(2);
Source§

impl<T> Assertion<T>

Source

pub fn into_inner(self) -> T

Consumes the assertion and returns the inner value.

This enables assert-and-continue patterns, unwrapping an inner value after asserting on it:

use fluent_assertions::*;
let v = Some(5).should().be_some().into_inner();
assert_eq!(v, 5);
Source§

impl<T> Assertion<T>
where T: Debug,

General assertions for all types

Source

pub fn be<U: Debug>(self, other: U) -> Self
where T: PartialEq<U>,

Asserts that the value equals other, allowing cross-type comparison.

§Examples
use fluent_assertions::*;
"foo".to_string().should().be("foo");
Source

pub fn not_be<U: Debug>(self, other: U) -> Self
where T: PartialEq<U>,

Asserts that the value does not equal other.

§Examples
use fluent_assertions::*;
42.should().not_be(0);

Trait Implementations§

Source§

impl<T: Debug> CollectionAssertion<T> for Assertion<Vec<T>>

Source§

fn be_empty(self) -> Self

Asserts that the collection is empty Read more
Source§

fn not_be_empty(self) -> Self

Asserts that the collection is not empty Read more
Source§

fn have_length(self, length: usize) -> Self

Asserts that the collection has a given length Read more
Source§

fn contain(self, expected: &T) -> Self
where T: PartialEq,

Asserts that the collection contains a given element Read more
Source§

impl<T: Debug> CollectionAssertion<T> for Assertion<&[T]>

Source§

fn be_empty(self) -> Self

Asserts that the collection is empty Read more
Source§

fn not_be_empty(self) -> Self

Asserts that the collection is not empty Read more
Source§

fn have_length(self, length: usize) -> Self

Asserts that the collection has a given length Read more
Source§

fn contain(self, expected: &T) -> Self
where T: PartialEq,

Asserts that the collection contains a given element Read more
Source§

impl<T: Debug, const N: usize> CollectionAssertion<T> for Assertion<[T; N]>

Source§

fn be_empty(self) -> Self

Asserts that the collection is empty Read more
Source§

fn not_be_empty(self) -> Self

Asserts that the collection is not empty Read more
Source§

fn have_length(self, length: usize) -> Self

Asserts that the collection has a given length Read more
Source§

fn contain(self, expected: &T) -> Self
where T: PartialEq,

Asserts that the collection contains a given element Read more
Source§

impl<T: Debug> CollectionAssertion<T> for Assertion<&Vec<T>>

Source§

fn be_empty(self) -> Self

Asserts that the collection is empty Read more
Source§

fn not_be_empty(self) -> Self

Asserts that the collection is not empty Read more
Source§

fn have_length(self, length: usize) -> Self

Asserts that the collection has a given length Read more
Source§

fn contain(self, expected: &T) -> Self
where T: PartialEq,

Asserts that the collection contains a given element Read more
Source§

impl<T: Debug + PartialEq> OptionAssertion<T> for Assertion<Option<T>>

Source§

fn contain(self, expected: &T) -> Self

Asserts that the Option is Some and contains the expected value Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for Assertion<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Assertion<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> Should for T

Source§

fn should(self) -> Assertion<T>

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.