Struct Spec

Source
pub struct Spec<'a, S, R> { /* private fields */ }
Expand description

Data of an actual assertion.

It holds the data needed to execute an assertion such as the subject, the name of the subject or expression, an optional description of the current assertion and the location of the assertion in the source code respectively test code.

It also holds the concrete FailingStrategy on how to behave in case an assertion fails.

In case of the CollectFailures failing strategy, the AssertFailures are collected in this struct.

Implementations§

Source§

impl<S, R> Spec<'_, S, R>

Source

pub fn subject(&self) -> &S

Returns the subject.

Source

pub fn expression(&self) -> Option<&Expression<'_>>

Returns the expression (or subject name) if one has been set.

Source

pub fn location(&self) -> Option<Location<'_>>

Returns the location in source code or test code if it has been set.

Source

pub fn description(&self) -> Option<&str>

Returns the description or the assertion if it has been set.

Source

pub const fn diff_format(&self) -> &DiffFormat

Returns the diff format used with this assertion.

Source

pub fn failing_strategy(&self) -> &R

Returns the failing strategy that is used in case an assertion fails.

Source

pub fn failures(&self) -> Vec<AssertFailure>

Returns the assertion failures that have been collected so far.

Source

pub fn display_failures(&self) -> Vec<String>

Returns the assertion failures collected so far as formatted text.

Source§

impl<'a, S, R> Spec<'a, S, R>

Source

pub const fn new(subject: S, failing_strategy: R) -> Self

Constructs a new Spec for the given subject and with the specified failing strategy.

The diff format is set to “no highlighting”. Failure messages will not highlight differences between the actual and the expected value.

Source

pub fn named(self, subject_name: impl Into<Cow<'a, str>>) -> Self

Sets the subject name or expression for this assertion.

Source

pub fn described_as(self, description: impl Into<Cow<'a, str>>) -> Self

Sets a custom description about what is being asserted.

Source

pub const fn located_at(self, location: Location<'a>) -> Self

Sets the location of the assertion in the source code respectively test code.

Source

pub const fn with_diff_format(self, diff_format: DiffFormat) -> Self

Sets the diff format that is used to highlight differences between the actual value and the expected value.

Note: This method must be called before an assertion method is called to have an effect on the failure message of the assertion as failure messages are formatted immediately when an assertion is executed.

Source

pub fn with_configured_diff_format(self) -> Self

Available on crate feature colored only.

Sets the diff format used to highlight differences between the actual value and the expected value according the configured mode.

The mode is configured via environment variables like described in the module colored.

Source

pub fn extracting<F, U>(self, extractor: F) -> Spec<'a, U, R>
where F: FnOnce(S) -> U,

Maps the current subject to some other value.

It takes a closure that maps the current subject to a new subject and returns a new Spec with the value returned by the closure as the new subject. The new subject may have a different type than the original subject. All other data like expression, description and location are taken over from this Spec into the returned Spec.

This function is useful when having a custom type and some specific property of this type shall be asserted only.

This is an alias function to the mapping() function. Both functions do exactly the same. The idea is to provide different names to be able to express the intent more clearly when used in assertions.

§Example
use asserting::prelude::*;

struct MyStruct {
    important_property: String,
    other_property: f64,
}

let some_thing = MyStruct {
    important_property: "imperdiet aliqua zzril eiusmod".into(),
    other_property: 99.9,
};

assert_that!(some_thing).extracting(|s| s.important_property)
    .is_equal_to("imperdiet aliqua zzril eiusmod");
Source

pub fn mapping<F, U>(self, mapper: F) -> Spec<'a, U, R>
where F: FnOnce(S) -> U,

Maps the current subject to some other value.

It takes a closure that maps the current subject to a new subject and returns a new Spec with the value returned by the closure as the new subject. The new subject may have a different type than the original subject. All other data like expression, description and location are taken over from this Spec into the returned Spec.

This function is useful if some type does not implement a trait that is required for an assertion.

Spec also provides the extracting() function, which is an alias to this function. Both functions do exactly the same. Choose that function of which its name expresses the intent more clearly.

§Example
use asserting::prelude::*;

struct Point {
    x: i64,
    y: i64,
}

let target = Point { x: 12, y: -64 };

assert_that!(target).mapping(|s| (s.x, s.y)).is_equal_to((12, -64));

The custom type Point does not implement the PartialEq trait nor the Debug trait, which are both required for an is_equal_to assertion. So we map the subject of the type Point to a tuple of its fields.

Source§

impl<S, R> Spec<'_, S, R>
where R: FailingStrategy,

Source

pub fn expecting(self, expectation: impl Expectation<S>) -> Self

Asserts the given expectation.

In case the expectation is not meet, it does fail according the current failing strategy of this Spec.

This method is called from the implementations of the assertion traits defined in the assertions module. Implementations of custom assertions will call this method with a proper expectation.

§Examples
use asserting::expectations::{IsEmpty, IsEqualTo};
use asserting::prelude::*;

assert_that!(7 * 6).expecting(IsEqualTo {expected: 42 });

assert_that!("").expecting(IsEmpty);
Source

pub fn satisfies<P>(self, predicate: P) -> Self
where P: Fn(&S) -> bool,

Asserts whether the given predicate is meet.

This method takes a predicate function and calls it as an expectation. In case the predicate function returns false, it does fail with a generic failure message and according to the current failing strategy of this Spec.

This method can be used to do simple custom assertions without implementing an Expectation and an assertion trait.

§Examples
use asserting::prelude::*;

fn is_odd(value: &i32) -> bool {
    value & 1 == 1
}

assert_that!(37).satisfies(is_odd);

let failures = verify_that!(22).satisfies(is_odd).display_failures();

assert_that!(failures).contains_exactly([
    "assertion failed: expected 22 to satisfy the given predicate, but returned false\n"
]);

To assert a predicate with a custom failure message instead of the generic one, use the method satisfies_with_message.

Source

pub fn satisfies_with_message<P>( self, message: impl Into<String>, predicate: P, ) -> Self
where P: Fn(&S) -> bool,

Asserts whether the given predicate is meet.

This method takes a predicate function and calls it as an expectation. In case the predicate function returns false, it does fail with the provided failure message and according to the current failing strategy of this Spec.

This method can be used to do simple custom assertions without implementing an Expectation and an assertion trait.

§Examples
use asserting::prelude::*;

fn is_odd(value: &i32) -> bool {
    value & 1 == 1
}

assert_that!(37).satisfies_with_message("expected my number to be odd", is_odd);

let failures = verify_that!(22)
        .satisfies_with_message("expected my number to be odd", is_odd)
        .display_failures();

assert_that!(failures).contains_exactly([
    "assertion failed: expected my number to be odd\n"
]);

To assert a predicate with a generic failure message instead of providing one use the method satisfies.

Source§

impl<S> Spec<'_, S, CollectFailures>

Source

pub fn soft_panic(&self)

Turns assertions into “soft assertions”.

It executes all specified assertions on a Spec and if at least one assertion fails, it panics. The panic message contains the messages of all assertions that have failed.

This method is only available on Specs with the CollectFailures-FailingStrategy. That is any Spec contructed by the macros verify_that! and verify_that_code! or by the functions verify_that() and verify_that_code().

On a Spec with the PanicOnFail-FailingStrategy it would not work as the very first failing assertion panics immediately, and later assertions never get executed.

§Examples

Running the following two assertions in “soft” mode:

use asserting::prelude::*;

verify_that!("the answer to all important questions is 42")
    .contains("unimportant")
    .has_at_most_length(41)
    .soft_panic();

executes both assertions and prints the messages of both failing assertions in the panic message:

assertion failed: expected subject to contain "unimportant"
   but was: "the answer to all important questions is 42"
  expected: "unimportant"

assertion failed: expected subject to have at most a length of 41
   but was: 43
  expected: <= 41

To highlight differences in failure messages of soft assertions use the with_configured_diff_format() method, like so:

use asserting::prelude::*;

verify_that!("the answer to all important questions is 42")
    .with_configured_diff_format()
    .contains("important")
    .has_at_most_length(43)
    .soft_panic();
Source§

impl<'a, I, R> Spec<'a, I, R>

Source

pub fn each_item<T, A, B>(self, assert: A) -> Spec<'a, (), R>
where I: IntoIterator<Item = T>, for<'c> A: Fn(Spec<'c, T, CollectFailures>) -> Spec<'c, B, CollectFailures>,

Iterates over the items of a collection or iterator and executes the given assertions for each of those items.

It iterates over all items of the collection or iterator and collects the failure messages for those items where the assertion fails. In other words, it does not stop iterating when the assertion for one item fails.

The failure messages contain the position of the item within the collection or iterator. The position is 1 based. So a failure message for the first item contains “1. item”, the second “2. item”, etc.

§Example

The following assertion:

use asserting::prelude::*;

let numbers = [2, 4, 6, 8, 10];

assert_that!(numbers).each_item(|e|
    e.is_greater_than(2)
        .is_at_most(7)
);

will print:

assertion failed: expected numbers 1. item to be greater than 2
   but was: 2
  expected: > 2

assertion failed: expected numbers 4. item to be at most 7
   but was: 8
  expected: <= 7

assertion failed: expected numbers 5. item to be at most 7
   but was: 10
  expected: <= 7

Trait Implementations§

Source§

impl<R> AssertBoolean for Spec<'_, bool, R>
where R: FailingStrategy,

Source§

fn is_true(self) -> Self

Verifies that the subject is true. Read more
Source§

fn is_false(self) -> Self

Verifies that the subject is false. Read more
Source§

impl<'a, T, R> AssertBorrowedOptionValue<'a, T, R> for Spec<'a, &'a Option<T>, R>
where R: FailingStrategy,

Source§

fn some(self) -> Spec<'a, &'a T, R>

Maps the subject to the option’s value if it has some. Otherwise, this assertion fails. Read more
Source§

impl<'a, T, E, R> AssertBorrowedResultValue<'a, T, E, R> for Spec<'a, &'a Result<T, E>, R>
where T: Debug, E: Debug,

Source§

fn ok(self) -> Spec<'a, &'a T, R>

Maps the subject to the result’s ok value. Read more
Source§

fn err(self) -> Spec<'a, &'a E, R>

Maps the subject to the result’s err value. Read more
Source§

impl<R> AssertChar for Spec<'_, &char, R>
where R: FailingStrategy,

Source§

fn is_lowercase(self) -> Self

Verify that a character is lowercase. Read more
Source§

fn is_uppercase(self) -> Self

Verify that a character is uppercase. Read more
Source§

fn is_ascii(self) -> Self

Verify that a character is an ASCII character. Read more
Source§

fn is_alphabetic(self) -> Self

Verify that a character is an alphabetic character. Read more
Source§

fn is_alphanumeric(self) -> Self

Verify that a character is an alphabetic character or a digit. Read more
Source§

fn is_control_char(self) -> Self

Verify that a character is a control character. Read more
Source§

fn is_digit(self, radix: u32) -> Self

Verify that a character is a digit within the given radix. Read more
Source§

fn is_whitespace(self) -> Self

Verify that a character is whitespace. Read more
Source§

impl<R> AssertChar for Spec<'_, char, R>
where R: FailingStrategy,

Source§

fn is_lowercase(self) -> Self

Verify that a character is lowercase. Read more
Source§

fn is_uppercase(self) -> Self

Verify that a character is uppercase. Read more
Source§

fn is_ascii(self) -> Self

Verify that a character is an ASCII character. Read more
Source§

fn is_alphabetic(self) -> Self

Verify that a character is an alphabetic character. Read more
Source§

fn is_alphanumeric(self) -> Self

Verify that a character is an alphabetic character or a digit. Read more
Source§

fn is_control_char(self) -> Self

Verify that a character is a control character. Read more
Source§

fn is_digit(self, radix: u32) -> Self

Verify that a character is a digit within the given radix. Read more
Source§

fn is_whitespace(self) -> Self

Verify that a character is whitespace. Read more
Source§

impl<'a, S, R> AssertCodePanics<'a, R> for Spec<'a, Code<S>, R>
where S: FnOnce(), R: FailingStrategy,

Source§

fn does_not_panic(self) -> Spec<'a, (), R>

Available on crate feature panic only.
Verifies that the actual code under test does not panic. Read more
Source§

fn panics(self) -> Spec<'a, (), R>

Available on crate feature panic only.
Verifies that the actual code under test panics with any message. Read more
Source§

fn panics_with_message(self, message: impl Into<String>) -> Spec<'a, (), R>

Available on crate feature panic only.
Verifies that the actual code under test panics with the given message. Read more
Source§

impl<S, R> AssertDecimalNumber for Spec<'_, S, R>

Source§

fn has_scale_of(self, expected_scale: i64) -> Self

Verifies the scale of a decimal number. Read more
Source§

fn has_precision_of(self, expected_precision: u64) -> Self

Verifies the precision of a decimal number. Read more
Source§

fn is_integer(self) -> Self

Verifies that a decimal number has zero fractional digits (is equivalent to an integer). Read more
Source§

impl<S, R> AssertEmptiness for Spec<'_, S, R>

Source§

fn is_empty(self) -> Self

Verifies that the subject is empty. Read more
Source§

fn is_not_empty(self) -> Self

Verifies that the subject is not empty. Read more
Source§

impl<S, E, R> AssertEquality<E> for Spec<'_, S, R>
where S: PartialEq<E> + Debug, E: Debug, R: FailingStrategy,

Source§

fn is_equal_to(self, expected: E) -> Self

Verifies that the subject is equal to some other value. Read more
Source§

fn is_not_equal_to(self, expected: E) -> Self

Verifies that subject is not equal to some other value. Read more
Source§

impl<'a, S, R> AssertErrorHasSource<'a, R> for Spec<'a, S, R>
where S: Error, R: FailingStrategy,

Source§

fn has_no_source(self) -> Self

Verifies that an error has no source. Read more
Source§

fn has_source(self) -> Self

Verifies that an error has some source. Read more
Source§

fn has_source_message( self, expected_source_message: impl Into<String>, ) -> Spec<'a, Option<String>, R>

Verifies that an error has some source which converted to a string equals the expected message. Read more
Source§

impl<S, R> AssertHasCharCount<usize> for Spec<'_, S, R>

Source§

fn has_char_count(self, expected_char_count: usize) -> Self

Verifies that the subject contains the expected number of characters. Read more
Source§

fn has_char_count_in_range<U>(self, expected_range: U) -> Self
where U: RangeBounds<usize> + Debug,

Verifies that the subject contains a number of characters that is in the expected range. Read more
Source§

fn has_char_count_less_than(self, expected_char_count: usize) -> Self

Verifies that the subject contains less than the expected number of characters. Read more
Source§

fn has_char_count_greater_than(self, expected_char_count: usize) -> Self

Verifies that the subject contains more than the expected number of characters. Read more
Source§

fn has_at_most_char_count(self, expected_char_count: usize) -> Self

Verifies that the subject contains at least the expected number of characters. Read more
Source§

fn has_at_least_char_count(self, expected_char_count: usize) -> Self

Verifies that the subject contains at least the expected number of characters. Read more
Source§

impl<S, E, R> AssertHasDebugMessage<E> for Spec<'_, S, R>
where S: Debug, E: AsRef<str>, R: FailingStrategy,

Source§

fn has_debug_message(self, expected: E) -> Self

Verifies that a subject formatted for debugging results in the expected string. Read more
Source§

fn does_not_have_debug_message(self, expected: E) -> Self

Verifies that a subject formatted for debugging does not result in the expected string. Read more
Source§

impl<S, E, R> AssertHasDisplayMessage<E> for Spec<'_, S, R>
where S: Display, E: AsRef<str>, R: FailingStrategy,

Source§

fn has_display_message(self, expected: E) -> Self

Verifies that a subject formatted for display results in the expected string. Read more
Source§

fn does_not_have_display_message(self, expected: E) -> Self

Verifies that a subject formatted for display does not result in the expected string. Read more
Source§

impl<T, E, X, R> AssertHasError<X> for Spec<'_, &Result<T, E>, R>
where T: Debug, E: PartialEq<X> + Debug, X: Debug, R: FailingStrategy,

Source§

fn has_error(self, expected: X) -> Self

Verifies that the subject holds an error value that is equal to the expected one. Read more
Source§

impl<T, E, X, R> AssertHasError<X> for Spec<'_, Result<T, E>, R>
where T: Debug, E: PartialEq<X> + Debug, X: Debug, R: FailingStrategy,

Source§

fn has_error(self, expected: X) -> Self

Verifies that the subject holds an error value that is equal to the expected one. Read more
Source§

impl<'a, T, E, X, R> AssertHasErrorMessage<'a, X, R> for Spec<'a, &Result<T, E>, R>
where T: Debug, E: Display, X: Debug, String: PartialEq<X>, R: FailingStrategy,

Source§

fn has_error_message(self, expected: X) -> Spec<'a, String, R>

Verifies that the subject is an error value with the expected message. Read more
Source§

impl<'a, T, E, X, R> AssertHasErrorMessage<'a, X, R> for Spec<'a, Result<T, E>, R>
where T: Debug, E: Display, X: Debug, String: PartialEq<X>, R: FailingStrategy,

Source§

fn has_error_message(self, expected: X) -> Spec<'a, String, R>

Verifies that the subject is an error value with the expected message. Read more
Source§

impl<S, R> AssertHasLength<usize> for Spec<'_, S, R>

Source§

fn has_length(self, expected_length: usize) -> Self

Verifies that the subject has the expected length. Read more
Source§

fn has_length_in_range<U>(self, expected_range: U) -> Self
where U: RangeBounds<usize> + Debug,

Verifies that the subject has a length in the expected range. Read more
Source§

fn has_length_less_than(self, expected_length: usize) -> Self

Verifies that the subject has a length that is less than the expected length. Read more
Source§

fn has_length_greater_than(self, expected_length: usize) -> Self

Verifies that the subject has a length that is greater than the expected length. Read more
Source§

fn has_at_most_length(self, expected_length: usize) -> Self

Verifies that the subject has a length that is at most the expected length. Read more
Source§

fn has_at_least_length(self, expected_length: usize) -> Self

Verifies that the subject has a length that is at least the expected length. Read more
Source§

impl<S, E, R> AssertHasValue<E> for Spec<'_, &Option<S>, R>
where S: PartialEq<E> + Debug, E: Debug, R: FailingStrategy,

Source§

fn has_value(self, expected: E) -> Self

Verifies that the subject holds a value that is equal to the expected one. Read more
Source§

impl<S, E, R> AssertHasValue<E> for Spec<'_, Option<S>, R>
where S: PartialEq<E> + Debug, E: Debug, R: FailingStrategy,

Source§

fn has_value(self, expected: E) -> Self

Verifies that the subject holds a value that is equal to the expected one. Read more
Source§

impl<T, E, X, R> AssertHasValue<X> for Spec<'_, &Result<T, E>, R>
where T: PartialEq<X> + Debug, E: Debug, X: Debug, R: FailingStrategy,

Source§

fn has_value(self, expected: X) -> Self

Verifies that the subject holds a value that is equal to the expected one. Read more
Source§

impl<T, E, X, R> AssertHasValue<X> for Spec<'_, Result<T, E>, R>
where T: PartialEq<X> + Debug, E: Debug, X: Debug, R: FailingStrategy,

Source§

fn has_value(self, expected: X) -> Self

Verifies that the subject holds a value that is equal to the expected one. Read more
Source§

impl<S, E, R> AssertInRange<E> for Spec<'_, S, R>
where S: PartialOrd<E> + Debug, E: PartialOrd<S> + Debug, R: FailingStrategy,

Source§

fn is_in_range<U>(self, range: U) -> Self
where U: RangeBounds<E> + Debug,

Verifies that the subject is within the expected range. Read more
Source§

fn is_not_in_range<U>(self, range: U) -> Self
where U: RangeBounds<E> + Debug,

Verifies that the subject is not within the expected range. Read more
Source§

impl<S, R> AssertInfinity for Spec<'_, S, R>

Source§

fn is_infinite(self) -> Self

Verifies that the subject is an infinite number. Read more
Source§

fn is_finite(self) -> Self

Verifies that the subject is a finite number. Read more
Source§

impl<R> AssertIsCloseToWithDefaultMargin<f32> for Spec<'_, f32, R>
where R: FailingStrategy,

Source§

fn is_close_to(self, expected: f32) -> Self

Available on crate feature float-cmp only.
Verifies that the actual value is approximately equal to the expected value. Read more
Source§

fn is_not_close_to(self, expected: f32) -> Self

Available on crate feature float-cmp only.
Verifies that the actual value is not approximately equal to the expected value. Read more
Source§

impl<R> AssertIsCloseToWithDefaultMargin<f64> for Spec<'_, f64, R>
where R: FailingStrategy,

Source§

fn is_close_to(self, expected: f64) -> Self

Available on crate feature float-cmp only.
Verifies that the actual value is approximately equal to the expected value. Read more
Source§

fn is_not_close_to(self, expected: f64) -> Self

Available on crate feature float-cmp only.
Verifies that the actual value is not approximately equal to the expected value. Read more
Source§

impl<R> AssertIsCloseToWithinMargin<f32, F32Margin> for Spec<'_, f32, R>
where R: FailingStrategy,

Source§

fn is_close_to_with_margin( self, expected: f32, margin: impl Into<F32Margin>, ) -> Self

Available on crate feature float-cmp only.
Verifies that the actual value is approximately equal to the expected value. Read more
Source§

fn is_not_close_to_with_margin( self, expected: f32, margin: impl Into<F32Margin>, ) -> Self

Available on crate feature float-cmp only.
Verifies that the actual value not approximately equals to the expected value. Read more
Source§

impl<R> AssertIsCloseToWithinMargin<f64, F64Margin> for Spec<'_, f64, R>
where R: FailingStrategy,

Source§

fn is_close_to_with_margin( self, expected: f64, margin: impl Into<F64Margin>, ) -> Self

Available on crate feature float-cmp only.
Verifies that the actual value is approximately equal to the expected value. Read more
Source§

fn is_not_close_to_with_margin( self, expected: f64, margin: impl Into<F64Margin>, ) -> Self

Available on crate feature float-cmp only.
Verifies that the actual value not approximately equals to the expected value. Read more
Source§

impl<'a, S, T, E, R> AssertIteratorContains<'a, Vec<T>, E, R> for Spec<'a, S, R>
where S: IntoIterator<Item = T>, T: PartialEq<E> + Debug, E: Debug, R: FailingStrategy,

Source§

fn contains(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains at least one element that is equal to the expected value. Read more
Source§

fn does_not_contain(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator does not contain an element that is equal to the expected value. Read more
Source§

impl<'a, S, T, E, R> AssertIteratorContainsInAnyOrder<'a, Vec<T>, E, R> for Spec<'a, S, R>
where S: IntoIterator<Item = T>, T: PartialEq<<E as IntoIterator>::Item> + Debug, E: IntoIterator, <E as IntoIterator>::Item: Debug, R: FailingStrategy,

Source§

fn contains_exactly_in_any_order(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains exactly the given values and nothing else in any order. Read more
Source§

fn contains_any_of(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains at least one of the specified values. Read more
Source§

fn does_not_contain_any_of(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator does not contain any of the specified values. Read more
Source§

fn contains_all_of(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains the given values in any order. Read more
Source§

fn contains_only(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains only the given values and nothing else in any order and ignoring duplicates. Read more
Source§

fn contains_only_once(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains only the given values in any order and each of them only once. Read more
Source§

impl<'a, S, T, E, R> AssertIteratorContainsInOrder<'a, Vec<T>, E, R> for Spec<'a, S, R>

Source§

fn contains_exactly(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains exactly the given values and nothing else in the given order. Read more
Source§

fn contains_sequence(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains the given sequence of values in the given order and without extra values between the sequence values. Read more
Source§

fn contains_all_in_order(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains all the given values and in the given order, possibly with other values between them. Read more
Source§

fn starts_with(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains the given values as the first elements in order. Read more
Source§

fn ends_with(self, expected: E) -> Spec<'a, Vec<T>, R>

Verifies that the actual collection/iterator contains the given values as the last elements in order. Read more
Source§

impl<S, E, R> AssertMapContainsKey<E> for Spec<'_, S, R>

Source§

fn contains_key(self, expected_key: E) -> Self

Verify that the actual map contains a mapping for the given key. Read more
Source§

fn does_not_contain_key(self, expected_key: E) -> Self

Verify that the actual map does not contain any mapping for the given key. Read more
Source§

fn contains_keys(self, expected_keys: impl IntoIterator<Item = E>) -> Self

Verify that the actual map contains a mapping for each of the given keys. Read more
Source§

fn does_not_contain_keys( self, expected_keys: impl IntoIterator<Item = E>, ) -> Self

Verify that the actual map does not contain any mapping for one of the given keys. Read more
Source§

fn contains_exactly_keys( self, expected_keys: impl IntoIterator<Item = E>, ) -> Self

Verifies that the actual map contains a mapping for each of the expected keys but no more. Read more
Source§

impl<S, E, R> AssertMapContainsValue<E> for Spec<'_, S, R>

Source§

fn contains_value(self, expected_value: E) -> Self

Verify that the actual map contains at least one mapping where the value is equal to the expected one. Read more
Source§

fn does_not_contain_value(self, expected_value: E) -> Self

Verify that the actual map does not contain any mapping where the value is equal to the expected one. Read more
Source§

fn contains_values(self, expected_values: impl IntoIterator<Item = E>) -> Self

Verify that the actual map contains at least one mapping for each of the given values, where the mapping contains one of the expected values. Read more
Source§

fn does_not_contain_values( self, expected_values: impl IntoIterator<Item = E>, ) -> Self

Verify that the actual map does not contain any mapping where the value is one of the given values. Read more
Source§

impl<S, R> AssertNotANumber for Spec<'_, S, R>

Source§

fn is_not_a_number(self) -> Self

Verifies that the subject is not a number. Read more
Source§

fn is_a_number(self) -> Self

Verifies that the subject is a number. Read more
Source§

impl<S, R> AssertNumericIdentity for Spec<'_, S, R>

Source§

fn is_zero(self) -> Self

Verifies whether the subject is the additive identity (zero). Read more
Source§

fn is_one(self) -> Self

Verifies whether the subject is the multiplicative identity (one). Read more
Source§

impl<S, R> AssertOption for Spec<'_, &Option<S>, R>
where S: Debug, R: FailingStrategy,

Source§

fn is_some(self) -> Self

Verifies that the subject has some value. Read more
Source§

fn is_none(self) -> Self

Verifies that the subject has no value. Read more
Source§

impl<S, R> AssertOption for Spec<'_, Option<S>, R>
where S: Debug, R: FailingStrategy,

Source§

fn is_some(self) -> Self

Verifies that the subject has some value. Read more
Source§

fn is_none(self) -> Self

Verifies that the subject has no value. Read more
Source§

impl<'a, T, R> AssertOptionValue<'a, T, R> for Spec<'a, Option<T>, R>
where R: FailingStrategy,

Source§

fn some(self) -> Spec<'a, T, R>

Maps the subject to the option’s value if it has some. Otherwise, this assertion fails. Read more
Source§

impl<S, E, R> AssertOrder<E> for Spec<'_, S, R>
where S: PartialOrd<E> + Debug, E: Debug, R: FailingStrategy,

Source§

fn is_less_than(self, expected: E) -> Self

Verifies that the subject is less than some expected value. Read more
Source§

fn is_greater_than(self, expected: E) -> Self

Verifies that the subject is greater than some expected value. Read more
Source§

fn is_at_most(self, expected: E) -> Self

Verifies that the subject is less than or equal to some expected value. Read more
Source§

fn is_at_least(self, expected: E) -> Self

Verifies that the subject is greater than or equal to some expected value. Read more
Source§

fn is_before(self, expected: E) -> Self

Verifies that the subject is before some expected value. Read more
Source§

fn is_after(self, expected: E) -> Self

Verifies that the subject is after some expected value. Read more
Source§

fn is_between(self, min: E, max: E) -> Self

Verifies that the subject is between a min value and a max value. Read more
Source§

impl<T, E, R> AssertResult for Spec<'_, &Result<T, E>, R>
where T: Debug, E: Debug, R: FailingStrategy,

Source§

fn is_ok(self) -> Self

Verifies that the subject has an ok value. Read more
Source§

fn is_err(self) -> Self

Verifies that the subject has an err value. Read more
Source§

impl<T, E, R> AssertResult for Spec<'_, Result<T, E>, R>
where T: Debug, E: Debug, R: FailingStrategy,

Source§

fn is_ok(self) -> Self

Verifies that the subject has an ok value. Read more
Source§

fn is_err(self) -> Self

Verifies that the subject has an err value. Read more
Source§

impl<'a, T, E, R> AssertResultValue<'a, T, E, R> for Spec<'a, Result<T, E>, R>
where T: Debug, E: Debug,

Source§

fn ok(self) -> Spec<'a, T, R>

Maps the subject to the result’s ok value. Read more
Source§

fn err(self) -> Spec<'a, E, R>

Maps the subject to the result’s err value. Read more
Source§

impl<S, R> AssertSignum for Spec<'_, S, R>

Source§

fn is_negative(self) -> Self

Verifies that the subject is a negative number. Read more
Source§

fn is_not_negative(self) -> Self

Verifies that the subject is a non-negative number. Read more
Source§

fn is_positive(self) -> Self

Verifies that the subject is a positive number. Read more
Source§

fn is_not_positive(self) -> Self

Verifies that the subject is a non-positive number. Read more
Source§

impl<'a, S, R> AssertStringContainsAnyOf<&'a [char]> for Spec<'a, S, R>
where S: 'a + AsRef<str> + Debug, R: FailingStrategy,

Source§

fn contains_any_of(self, expected: &'a [char]) -> Self

Verifies that a string contains any char from a collection of characters. Read more
Source§

fn does_not_contain_any_of(self, expected: &'a [char]) -> Self

Verifies that a string does not contain any char from a collection of characters. Read more
Source§

impl<'a, S, R, const N: usize> AssertStringContainsAnyOf<&'a [char; N]> for Spec<'a, S, R>
where S: 'a + AsRef<str> + Debug, R: FailingStrategy,

Source§

fn contains_any_of(self, expected: &'a [char; N]) -> Self

Verifies that a string contains any char from a collection of characters. Read more
Source§

fn does_not_contain_any_of(self, expected: &'a [char; N]) -> Self

Verifies that a string does not contain any char from a collection of characters. Read more
Source§

impl<'a, S, R, const N: usize> AssertStringContainsAnyOf<[char; N]> for Spec<'a, S, R>
where S: 'a + AsRef<str> + Debug, R: FailingStrategy,

Source§

fn contains_any_of(self, expected: [char; N]) -> Self

Verifies that a string contains any char from a collection of characters. Read more
Source§

fn does_not_contain_any_of(self, expected: [char; N]) -> Self

Verifies that a string does not contain any char from a collection of characters. Read more
Source§

impl<S, R> AssertStringMatches for Spec<'_, S, R>
where S: AsRef<str> + Debug, R: FailingStrategy,

Source§

fn matches(self, regex_pattern: &str) -> Self

Available on crate feature regex only.
Verifies that a string matches a regex pattern. Read more
Source§

fn does_not_match(self, regex_pattern: &str) -> Self

Available on crate feature regex only.
Verifies that a string does not match a regex pattern. Read more
Source§

impl<'a, S, R> AssertStringPattern<&'a str> for Spec<'a, S, R>
where S: 'a + AsRef<str> + Debug, R: FailingStrategy,

Source§

fn contains(self, pattern: &'a str) -> Self

Verifies that a string contains a substring or character. Read more
Source§

fn does_not_contain(self, pattern: &'a str) -> Self

Verifies that a string does not contain a substring or character. Read more
Source§

fn starts_with(self, pattern: &str) -> Self

Verifies that a string starts with a substring or character. Read more
Source§

fn does_not_start_with(self, pattern: &'a str) -> Self

Verifies that a string does not start with a substring or character. Read more
Source§

fn ends_with(self, pattern: &str) -> Self

Verifies that a string ends with a substring or character. Read more
Source§

fn does_not_end_with(self, pattern: &'a str) -> Self

Verifies that a string does not end with a substring or character. Read more
Source§

impl<'a, S, R> AssertStringPattern<String> for Spec<'a, S, R>
where S: 'a + AsRef<str> + Debug, R: FailingStrategy,

Source§

fn contains(self, pattern: String) -> Self

Verifies that a string contains a substring or character. Read more
Source§

fn does_not_contain(self, pattern: String) -> Self

Verifies that a string does not contain a substring or character. Read more
Source§

fn starts_with(self, pattern: String) -> Self

Verifies that a string starts with a substring or character. Read more
Source§

fn does_not_start_with(self, pattern: String) -> Self

Verifies that a string does not start with a substring or character. Read more
Source§

fn ends_with(self, pattern: String) -> Self

Verifies that a string ends with a substring or character. Read more
Source§

fn does_not_end_with(self, pattern: String) -> Self

Verifies that a string does not end with a substring or character. Read more
Source§

impl<'a, S, R> AssertStringPattern<char> for Spec<'a, S, R>
where S: 'a + AsRef<str> + Debug, R: FailingStrategy,

Source§

fn contains(self, expected: char) -> Self

Verifies that a string contains a substring or character. Read more
Source§

fn does_not_contain(self, pattern: char) -> Self

Verifies that a string does not contain a substring or character. Read more
Source§

fn starts_with(self, expected: char) -> Self

Verifies that a string starts with a substring or character. Read more
Source§

fn does_not_start_with(self, pattern: char) -> Self

Verifies that a string does not start with a substring or character. Read more
Source§

fn ends_with(self, pattern: char) -> Self

Verifies that a string ends with a substring or character. Read more
Source§

fn does_not_end_with(self, pattern: char) -> Self

Verifies that a string does not end with a substring or character. Read more

Auto Trait Implementations§

§

impl<'a, S, R> Freeze for Spec<'a, S, R>
where S: Freeze, R: Freeze,

§

impl<'a, S, R> RefUnwindSafe for Spec<'a, S, R>

§

impl<'a, S, R> Send for Spec<'a, S, R>
where S: Send, R: Send,

§

impl<'a, S, R> Sync for Spec<'a, S, R>
where S: Sync, R: Sync,

§

impl<'a, S, R> Unpin for Spec<'a, S, R>
where S: Unpin, R: Unpin,

§

impl<'a, S, R> UnwindSafe for Spec<'a, S, R>
where S: UnwindSafe, R: 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.