asserting/predicate/
mod.rs

1//! Implementation of the predicate assertion.
2
3use crate::expectations::Predicate;
4use crate::spec::{DiffFormat, Expectation, Expression, Invertible};
5use crate::std::{format, string::String};
6
7impl<S, P> Expectation<S> for Predicate<P>
8where
9    P: Fn(&S) -> bool,
10{
11    fn test(&mut self, subject: &S) -> bool {
12        (self.predicate)(subject)
13    }
14
15    fn message(
16        &self,
17        expression: &Expression<'_>,
18        _actual: &S,
19        inverted: bool,
20        _format: &DiffFormat,
21    ) -> String {
22        self.message.clone().unwrap_or_else(|| {
23            format!("expected {expression} to satisfy the given predicate, but returned {inverted}")
24        })
25    }
26}
27
28impl<P> Invertible for Predicate<P> {}
29
30#[cfg(test)]
31mod tests;