pub(crate) mod tokens {
pub(crate) const SUCCESS: &str = "#0f766e";
pub(crate) const INFO: &str = "#2563eb";
pub(crate) const WARN_DEEP: &str = "#d97706";
pub(crate) const DANGER: &str = "#dc2626";
pub(crate) const INK: &str = "#0f172a";
pub(crate) const NEUTRAL: &str = "#475569";
pub(crate) const MUTED: &str = "#94a3b8";
}
pub(crate) fn score_color(score: u8) -> &'static str {
match score {
75..=100 => tokens::SUCCESS,
40..=74 => tokens::WARN_DEEP,
_ => tokens::DANGER,
}
}
pub(crate) fn status_color(status: &str) -> &'static str {
match status {
"good" => tokens::SUCCESS,
"warn" => tokens::WARN_DEEP,
"bad" => tokens::DANGER,
_ => tokens::INFO,
}
}
pub(crate) fn severity_color(severity: crate::wcag::Severity) -> &'static str {
use crate::wcag::Severity::*;
match severity {
Critical | High => tokens::DANGER,
Medium => tokens::WARN_DEEP,
_ => tokens::INFO,
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::wcag::Severity;
#[test]
fn severity_color_low_is_info_blue_not_gray() {
assert_eq!(severity_color(Severity::Low), tokens::INFO);
}
#[test]
fn severity_color_matches_documented_four_color_law() {
assert_eq!(severity_color(Severity::Critical), tokens::DANGER);
assert_eq!(severity_color(Severity::High), tokens::DANGER);
assert_eq!(severity_color(Severity::Medium), tokens::WARN_DEEP);
assert_eq!(severity_color(Severity::Low), tokens::INFO);
}
}