use crate::{implementation, private, Asserter};
pub trait StringAssertion<StringLike>: private::Sealed
where
StringLike: AsRef<str>,
{
#[track_caller]
fn contains(self, string: impl AsRef<str>) -> Asserter<StringLike>;
#[cfg(feature = "regex")]
#[cfg_attr(docsrs, doc(cfg(feature = "regex")))]
#[track_caller]
#[allow(clippy::wrong_self_convention)]
fn matches(self, regex: ®ex::Regex) -> Asserter<StringLike>;
#[track_caller]
fn starts_with(self, string: impl AsRef<str>) -> Asserter<StringLike>;
}
impl<StringLike> StringAssertion<StringLike> for Asserter<StringLike>
where
StringLike: AsRef<str>,
{
fn contains(self, expected: impl AsRef<str>) -> Self {
let actual = self.value.as_ref();
implementation::assert(
actual.contains(expected.as_ref()),
actual,
"to contain",
expected.as_ref(),
);
self
}
#[cfg(feature = "regex")]
fn matches(self, regex: ®ex::Regex) -> Self {
let actual = self.value.as_ref();
implementation::assert(
regex.is_match(actual),
actual,
"to be matched by",
regex.to_string(),
);
self
}
fn starts_with(self, expected: impl AsRef<str>) -> Self {
let actual = self.value.as_ref();
implementation::assert(
actual.starts_with(expected.as_ref()),
actual,
"to start with",
expected.as_ref(),
);
self
}
}