use crate::{implementation, private, Asserter};
use std::fmt::Debug;
pub trait OptionAssertion<OptionValue>: private::Sealed {
#[track_caller]
#[allow(clippy::wrong_self_convention)]
fn is_some(self) -> SomeAsserter<OptionValue>
where
OptionValue: Debug;
#[track_caller]
#[allow(clippy::wrong_self_convention)]
fn is_none(self)
where
OptionValue: Debug;
}
impl<OptionValue> OptionAssertion<OptionValue> for Asserter<Option<OptionValue>> {
fn is_some(self) -> SomeAsserter<OptionValue>
where
OptionValue: Debug,
{
implementation::assert_no_expected(self.value.is_some(), &self.value, "to be Some");
#[allow(clippy::unwrap_used)]
let value = self.value.unwrap();
SomeAsserter { value }
}
fn is_none(self)
where
OptionValue: Debug,
{
implementation::assert_no_expected(self.value.is_none(), &self.value, "to be None");
}
}
pub struct SomeAsserter<SomeValue> {
value: SomeValue,
}
impl<SomeValue> SomeAsserter<SomeValue> {
#[track_caller]
#[must_use = "Transforming the asserted value does not assert anything"]
pub fn and_value(self) -> Asserter<SomeValue> {
Asserter { value: self.value }
}
}