use crate::Cell;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum CellAlign {
#[default]
Left,
Center,
Right,
}
impl CellAlign {
pub fn default_for(cell: &Cell) -> CellAlign {
match cell {
Cell::Int(_) | Cell::Float(_) => CellAlign::Right,
Cell::Bool(_) => CellAlign::Center,
_ => CellAlign::Left,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn numeric_defaults_right() {
assert_eq!(CellAlign::default_for(&Cell::Int(1)), CellAlign::Right);
assert_eq!(CellAlign::default_for(&Cell::Float(1.5)), CellAlign::Right);
}
#[test]
fn bool_defaults_center() {
assert_eq!(CellAlign::default_for(&Cell::Bool(true)), CellAlign::Center);
}
#[test]
fn text_and_empty_default_left() {
assert_eq!(CellAlign::default_for(&Cell::from("x")), CellAlign::Left);
assert_eq!(CellAlign::default_for(&Cell::Empty), CellAlign::Left);
assert_eq!(CellAlign::default(), CellAlign::Left);
}
}