use std::fmt;
use crate::core::style::{ALL_OK_HEADER, AT_LESAT_ONE_OK_HEADER};
use crate::core::Matcher;
use crate::matchers::collections::EveryMatcher;
use super::{HeaderFormat, SomeFailuresFormat};
pub fn every<'a, PosOut, NegOut, IntoIter>(
matcher: impl Fn() -> Matcher<'a, IntoIter::Item, PosOut, NegOut> + 'a,
) -> Matcher<'a, IntoIter, Vec<PosOut>, Vec<NegOut>>
where
IntoIter: fmt::Debug + IntoIterator + 'a,
PosOut: 'a,
NegOut: 'a,
{
Matcher::transform(
EveryMatcher::new(matcher),
HeaderFormat::new(
SomeFailuresFormat::new(),
ALL_OK_HEADER,
AT_LESAT_ONE_OK_HEADER,
),
)
}
#[cfg(test)]
mod tests {
use super::every;
use crate::{be_some, expect};
#[test]
fn succeeds_when_every_element_succeeds() {
expect!(vec![Some("foo"), Some("bar")]).to(every(be_some));
}
#[test]
fn succeeds_when_not_every_element_succeeds() {
expect!(vec![Some("foo"), None]).to_not(every(be_some));
}
#[test]
#[should_panic]
fn fails_when_every_element_succeeds() {
expect!(vec![Some("foo"), Some("bar")]).to_not(every(be_some));
}
#[test]
#[should_panic]
fn fails_when_not_every_element_succeeds() {
expect!(vec![Some("foo"), None]).to(every(be_some));
}
}