pub fn none() -> __internal::NoneMatcher {
__internal::NoneMatcher
}
pub mod __internal {
use crate::description::Description;
use crate::matcher::{Describable, Matcher, MatcherResult};
use core::fmt::Debug;
#[doc(hidden)]
pub struct NoneMatcher;
impl<T: Debug> Matcher<Option<T>> for NoneMatcher {
fn matches(&self, actual: &Option<T>) -> MatcherResult {
(actual.is_none()).into()
}
}
impl Describable for NoneMatcher {
fn describe(&self, matcher_result: MatcherResult) -> Description {
match matcher_result {
MatcherResult::Match => "is none".into(),
MatcherResult::NoMatch => "is some(_)".into(),
}
}
}
}
#[cfg(test)]
mod tests {
use super::none;
use crate::matcher::{Matcher, MatcherResult};
use crate::prelude::*;
#[test]
fn none_matches_option_with_none() -> TestResult<()> {
let matcher = none();
let result = matcher.matches(&None::<i32>);
verify_that!(result, eq(MatcherResult::Match))
}
#[test]
fn none_does_not_match_option_with_value() -> TestResult<()> {
let matcher = none();
let result = matcher.matches(&Some(0));
verify_that!(result, eq(MatcherResult::NoMatch))
}
}