use std::fmt;
use crate::core::Matcher;
use crate::matchers::collections::{BeEmptyMatcher, HaveLenMatcher, Len};
use super::{ExpectationFormat, MismatchFormat};
pub fn have_len<'a, Actual>(len: usize) -> Matcher<'a, Actual, Actual>
where
Actual: fmt::Debug + Len + 'a,
{
Matcher::new(
HaveLenMatcher::new(len),
MismatchFormat::new("to have length", "to not have length"),
)
}
pub fn be_empty<'a, Actual>() -> Matcher<'a, Actual, Actual>
where
Actual: fmt::Debug + Len + 'a,
{
Matcher::new(
BeEmptyMatcher::new(),
ExpectationFormat::new("to be empty", "to not be empty"),
)
}
#[cfg(test)]
mod tests {
use super::{be_empty, have_len};
use crate::expect;
#[test]
fn succeeds_when_has_len() {
expect!(&vec!["foo"]).to(have_len(1));
}
#[test]
fn succeeds_when_not_has_len() {
expect!(&vec!["foo"]).to_not(have_len(100));
}
#[test]
#[should_panic]
fn fails_when_has_len() {
expect!(&vec!["foo"]).to_not(have_len(1));
}
#[test]
#[should_panic]
fn fails_when_not_has_len() {
expect!(&vec!["foo"]).to(have_len(100));
}
#[test]
fn succeeds_when_is_empty() {
expect!(&Vec::<&'static str>::new()).to(be_empty());
}
#[test]
fn succeeds_when_not_empty() {
expect!(&vec!["foo"]).to_not(be_empty());
}
#[test]
#[should_panic]
fn fails_when_is_empty() {
expect!(&Vec::<&'static str>::new()).to_not(be_empty());
}
#[test]
#[should_panic]
fn fails_when_not_empty() {
expect!(&vec!["foo"]).to(be_empty());
}
}