use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CheckSeverity {
Error,
Warning,
Info,
}
impl CheckSeverity {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Error => "error",
Self::Warning => "warning",
Self::Info => "info",
}
}
}
impl fmt::Display for CheckSeverity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn severities_are_stable_lowercase_strings() {
assert_eq!(CheckSeverity::Error.as_str(), "error");
assert_eq!(CheckSeverity::Warning.as_str(), "warning");
assert_eq!(CheckSeverity::Info.as_str(), "info");
assert_eq!(CheckSeverity::Error.to_string(), "error");
}
#[test]
fn severities_are_distinct() {
let all = [
CheckSeverity::Error,
CheckSeverity::Warning,
CheckSeverity::Info,
];
let names: Vec<&str> = all.iter().map(|s| s.as_str()).collect();
let mut unique = names.clone();
unique.sort();
unique.dedup();
assert_eq!(unique.len(), all.len());
}
}