pub struct Assert<T> { /* private fields */ }Expand description
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);It takes ownership of self and returns ownership back so that assertions can be chained in fluent manner.
Like in the following example:
Assert::that("foo")
.is("foo")
.is_not("bar");Implementations§
Source§impl<T> Assert<T>where
T: Debug,
impl<T> Assert<T>where
T: Debug,
Sourcepub fn is<R>(self, expected: R) -> Self
pub fn is<R>(self, expected: R) -> Self
Assert that self is equal to the expected value.
Assert::that(2).is(2);
Assert::that(String::from("2")).is(String::from("2"));
Assert::that(String::from("2")).is("2");ⓘ
Assert::that(2).is(3);Sourcepub fn is_not<R>(self, other: R) -> Self
pub fn is_not<R>(self, other: R) -> Self
Assert that self is not equal to the other value.
Assert::that(2).is_not(3);ⓘ
Assert::that(2).is_not(2);Sourcepub fn is_gt<R>(self, other: R) -> Selfwhere
T: PartialOrd<R>,
R: Debug,
pub fn is_gt<R>(self, other: R) -> Selfwhere
T: PartialOrd<R>,
R: Debug,
Sourcepub fn is_ge<R>(self, other: R) -> Selfwhere
T: PartialOrd<R>,
R: Debug,
pub fn is_ge<R>(self, other: R) -> Selfwhere
T: PartialOrd<R>,
R: Debug,
Assert that self is greater than or equal to the other value.
Assert::that(3).is_ge(3);
Assert::that(3).is_ge(2);ⓘ
Assert::that(3).is_ge(4);Sourcepub fn is_lt<R>(self, other: R) -> Selfwhere
T: PartialOrd<R>,
R: Debug,
pub fn is_lt<R>(self, other: R) -> Selfwhere
T: PartialOrd<R>,
R: Debug,
Sourcepub fn is_le<R>(self, other: R) -> Selfwhere
T: PartialOrd<R>,
R: Debug,
pub fn is_le<R>(self, other: R) -> Selfwhere
T: PartialOrd<R>,
R: Debug,
Assert that self is less than or equal to the other value.
Assert::that(3).is_le(3);
Assert::that(3).is_le(4);ⓘ
Assert::that(3).is_le(2);Source§impl<T> Assert<Option<T>>
impl<T> Assert<Option<T>>
Source§impl<T, E> Assert<Result<T, E>>
impl<T, E> Assert<Result<T, E>>
Source§impl Assert<String>
DSL for String.
impl Assert<String>
DSL for String.
Sourcepub fn starts_with(self, prefix: &str) -> Self
pub fn starts_with(self, prefix: &str) -> Self
Assert that the actual string starts with the given prefix.
Assert::that(String::from("hello world")).starts_with("hello");ⓘ
Assert::that(String::from("hello world")).starts_with("world");Source§impl<T> Assert<Vec<T>>
DSL for Vec.
impl<T> Assert<Vec<T>>
DSL for Vec.
Sourcepub fn contains(self, expected: &T) -> Self
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);Sourcepub fn is_empty(self) -> Self
pub fn is_empty(self) -> Self
Assert that the actual vector is empty.
Assert::that(Vec::<i32>::new()).is_empty();ⓘ
Assert::that(vec![1, 2, 3]).is_empty();Sourcepub fn has_length(self, expected: usize) -> Self
pub fn has_length(self, expected: usize) -> Self
Assert that the actual vector has the given length.
Assert::that(vec![1, 2, 3]).has_length(3);ⓘ
Assert::that(vec![1, 2, 3]).has_length(2);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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more