1use crate::Cell;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
7pub enum CellAlign {
8 #[default]
10 Left,
11 Center,
13 Right,
15}
16
17impl CellAlign {
18 pub fn default_for(cell: &Cell) -> CellAlign {
21 match cell {
22 Cell::Int(_) | Cell::Float(_) => CellAlign::Right,
23 Cell::Bool(_) => CellAlign::Center,
24 _ => CellAlign::Left,
25 }
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn numeric_defaults_right() {
35 assert_eq!(CellAlign::default_for(&Cell::Int(1)), CellAlign::Right);
36 assert_eq!(CellAlign::default_for(&Cell::Float(1.5)), CellAlign::Right);
37 }
38
39 #[test]
40 fn bool_defaults_center() {
41 assert_eq!(CellAlign::default_for(&Cell::Bool(true)), CellAlign::Center);
42 }
43
44 #[test]
45 fn text_and_empty_default_left() {
46 assert_eq!(CellAlign::default_for(&Cell::from("x")), CellAlign::Left);
47 assert_eq!(CellAlign::default_for(&Cell::Empty), CellAlign::Left);
48 assert_eq!(CellAlign::default(), CellAlign::Left);
49 }
50}