#[derive(Debug, Clone)]
pub enum TextMatch {
Exact(String),
StartsWith(String),
Contains(String),
}
impl TextMatch {
pub fn matches(&self, actual: &str) -> bool {
match self {
TextMatch::Exact(expected) => actual == expected,
TextMatch::StartsWith(prefix) => actual.starts_with(prefix),
TextMatch::Contains(substring) => actual.contains(substring),
}
}
pub fn assert(&self, actual: &str, context: &str) {
match self {
TextMatch::Exact(expected) => {
assert_eq!(
actual, expected,
"{context}: Expected text to be '{expected}', but got '{actual}'"
);
}
TextMatch::StartsWith(prefix) => {
assert!(
actual.starts_with(prefix),
"{context}: Expected text to start with '{prefix}', but got '{actual}'"
);
}
TextMatch::Contains(substring) => {
assert!(
actual.contains(substring),
"{context}: Expected text to contain '{substring}', but got '{actual}'"
);
}
}
}
}