pub fn status_label(status: &str) -> &'static str {
match status {
"disabled" => "Disabled",
"satisfied" => "Satisfied",
"adjusted" | "adjusting" => "Adjusting",
"blocked" => "Blocked",
"pending" | "" => "Pending",
"duplicate" => "Duplicate",
"error" => "Error",
"incomplete" => "Incomplete",
"invalid-selection" => "Invalid selection",
"unsupported-selection" | "unimplemented" => "Unimplemented",
"pending-component" => "Pending component",
"fixed" => "Locked",
"noop" => "No change",
"apply-failed" => "Failed",
_ => "Pending",
}
}
pub fn status_color_rgb(status: &str) -> [u8; 3] {
match status {
"disabled" => [0x8e, 0x8e, 0x93],
"satisfied" => [0x30, 0xd1, 0x58],
"blocked" | "duplicate" | "error" | "invalid-selection" | "apply-failed" => {
[0xff, 0x3b, 0x30]
}
"unsupported-selection" | "unimplemented" => [0xff, 0x9f, 0x0a],
_ => [0xff, 0xd6, 0x0a],
}
}
pub fn status_color_hex(status: &str) -> String {
let [r, g, b] = status_color_rgb(status);
format!("#{r:02x}{g:02x}{b:02x}")
}
pub fn status_severity(status: &str) -> u8 {
match status {
"disabled" => 0,
"satisfied" => 1,
"blocked" | "duplicate" | "error" | "apply-failed" => 3,
_ => 2,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn vocabulary_labels_match_requirements() {
assert_eq!(status_label("disabled"), "Disabled");
assert_eq!(status_label("satisfied"), "Satisfied");
assert_eq!(status_label("adjusted"), "Adjusting");
assert_eq!(status_label("adjusting"), "Adjusting");
assert_eq!(status_label("blocked"), "Blocked");
assert_eq!(status_label("pending"), "Pending");
assert_eq!(status_label("duplicate"), "Duplicate");
assert_eq!(status_label("error"), "Error");
assert_eq!(status_label("incomplete"), "Incomplete");
assert_eq!(status_label("invalid-selection"), "Invalid selection");
assert_eq!(status_label("unsupported-selection"), "Unimplemented");
assert_eq!(status_label("unimplemented"), "Unimplemented");
assert_eq!(status_label("pending-component"), "Pending component");
assert_eq!(status_label("fixed"), "Locked");
assert_eq!(status_label("noop"), "No change");
assert_eq!(status_label("apply-failed"), "Failed");
assert_eq!(status_label(""), "Pending");
assert_eq!(status_label("???"), "Pending");
}
#[test]
fn colors_match_the_captured_palette() {
assert_eq!(status_color_hex("disabled"), "#8e8e93");
assert_eq!(status_color_hex("satisfied"), "#30d158");
assert_eq!(status_color_hex("adjusted"), "#ffd60a");
assert_eq!(status_color_hex("blocked"), "#ff3b30");
assert_eq!(status_color_hex("duplicate"), "#ff3b30");
assert_eq!(status_color_hex("error"), "#ff3b30");
assert_eq!(status_color_hex("apply-failed"), "#ff3b30");
assert_eq!(status_color_hex("pending"), "#ffd60a");
assert_eq!(status_color_hex("fixed"), "#ffd60a");
assert_eq!(status_color_hex(""), "#ffd60a");
assert_eq!(status_color_rgb("satisfied"), [0x30, 0xd1, 0x58]);
}
#[test]
fn severity_orders_worst_first() {
assert!(status_severity("error") > status_severity("pending"));
assert!(status_severity("blocked") > status_severity("satisfied"));
assert!(status_severity("satisfied") > status_severity("disabled"));
assert_eq!(status_severity("adjusted"), status_severity("incomplete"));
}
}