pub struct Assertion<T> { /* private fields */ }Implementations§
Source§impl<E: Error> Assertion<E>
impl<E: Error> Assertion<E>
Sourcepub fn match_error<T: Error + Debug>(self, error: T) -> Self
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"));Sourcepub fn contain_message(self, expected_message: &str) -> Self
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>
Specific assertions for numeric types
impl<T> Assertion<T>
Specific assertions for numeric types
Sourcepub fn be_greater_than_or_equal_to(self, other: T) -> Self
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);Sourcepub fn be_greater_than(self, other: T) -> Self
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);Sourcepub fn be_less_than_or_equal_to(self, other: T) -> Self
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);Sourcepub fn be_less_than(self, other: T) -> Self
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);Sourcepub fn be_positive(self) -> Self
pub fn be_positive(self) -> Self
Sourcepub fn be_negative(self) -> Self
pub fn be_negative(self) -> Self
Sourcepub fn be_in_range(self, range: impl RangeBounds<T> + Debug) -> Self
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);Sourcepub fn not_be_in_range(self, range: impl RangeBounds<T> + Debug) -> Self
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>
Specific assertions for floating-point types
impl<T> Assertion<T>
Specific assertions for floating-point types
Sourcepub fn be_close_to(self, expected: T, tolerance: T) -> Self
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>>
impl<T: Debug + PartialEq> Assertion<Option<T>>
Source§impl<T, E> Assertion<Result<T, E>>
Specific assertions for Result types
impl<T, E> Assertion<Result<T, E>>
Specific assertions for Result types
Source§impl<T: AsRef<str>> Assertion<T>
Specific assertions for strings
impl<T: AsRef<str>> Assertion<T>
Specific assertions for strings
Sourcepub fn not_be_empty(self) -> Self
pub fn not_be_empty(self) -> Self
Asserts that the string is not empty
§Examples
use fluent_assertions::*;
"hello".should().not_be_empty();Sourcepub fn start_with(self, prefix: &str) -> Self
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");Sourcepub fn end_with(self, suffix: &str) -> Self
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");Sourcepub fn contain(self, substring: &str) -> Self
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");Sourcepub fn have_length(self, length: usize) -> Self
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>
impl<T> Assertion<T>
Sourcepub fn into_inner(self) -> T
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);