pub mod tokens {
pub const SUCCESS: &str = "#0f766e";
pub const INFO: &str = "#2563eb";
pub const WARN_DEEP: &str = "#d97706";
pub const DANGER: &str = "#dc2626";
pub const INK: &str = "#0f172a";
pub const NEUTRAL: &str = "#475569";
pub const MUTED: &str = "#94a3b8";
#[allow(dead_code)]
pub const BORDER: &str = "#e2e8f0";
#[allow(dead_code)]
pub const SURFACE: &str = "#f8fafc";
}
pub fn score_color(score: u8) -> &'static str {
match score {
75..=100 => tokens::SUCCESS,
40..=74 => tokens::WARN_DEEP,
_ => tokens::DANGER,
}
}
pub fn status_color(status: &str) -> &'static str {
match status {
"good" => tokens::SUCCESS,
"warn" => tokens::WARN_DEEP,
"bad" => tokens::DANGER,
_ => tokens::INFO,
}
}
pub 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);
}
}