use shep_core::status::ProcStatus;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Role {
Meadow,
Butter,
Bark,
Ink3,
}
pub(crate) const fn role_of(status: ProcStatus) -> Role {
match status {
ProcStatus::Online => Role::Meadow,
ProcStatus::Starting | ProcStatus::WaitingRestart => Role::Butter,
ProcStatus::Errored => Role::Bark,
ProcStatus::Stopping | ProcStatus::Stopped => Role::Ink3,
}
}
pub(crate) const fn face(status: ProcStatus) -> &'static str {
match status {
ProcStatus::Online => "(o.o)",
ProcStatus::Starting => "(o~o)",
ProcStatus::WaitingRestart => "(>_<)",
ProcStatus::Stopping | ProcStatus::Stopped => "(-.-)",
ProcStatus::Errored => "(x.x)",
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_status_has_a_five_column_face() {
for status in [
ProcStatus::Online,
ProcStatus::Starting,
ProcStatus::WaitingRestart,
ProcStatus::Stopping,
ProcStatus::Stopped,
ProcStatus::Errored,
] {
let face = face(status);
assert_eq!(
face.chars().count(),
5,
"{status} face {face:?} must be 5 columns; the table budget assumes it"
);
assert!(
face.is_ascii(),
"{status} face {face:?} must be ASCII: an emoji is \
double-width, inconsistently so, and cannot take a colour"
);
}
}
#[test]
fn the_roles_match_what_lookout_already_showed() {
assert_eq!(role_of(ProcStatus::Online), Role::Meadow);
assert_eq!(role_of(ProcStatus::Starting), Role::Butter);
assert_eq!(role_of(ProcStatus::WaitingRestart), Role::Butter);
assert_eq!(role_of(ProcStatus::Errored), Role::Bark);
assert_eq!(role_of(ProcStatus::Stopping), Role::Ink3);
assert_eq!(role_of(ProcStatus::Stopped), Role::Ink3);
}
#[test]
fn the_faces_are_distinct_from_one_another() {
let faces = [
face(ProcStatus::Online),
face(ProcStatus::Starting),
face(ProcStatus::WaitingRestart),
face(ProcStatus::Stopped),
face(ProcStatus::Errored),
];
let mut seen = faces.to_vec();
seen.sort_unstable();
seen.dedup();
assert_eq!(
seen.len(),
faces.len(),
"each state needs its own face: {faces:?}"
);
}
}