#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BorderChars {
pub tl: char,
pub t: char,
pub tr: char,
pub l: char,
pub r: char,
pub bl: char,
pub b: char,
pub br: char,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum BorderType {
Solid,
Corners,
Barplot,
#[doc(hidden)]
Ascii,
}
impl BorderType {
#[must_use]
pub const fn chars(self) -> BorderChars {
match self {
Self::Solid => BorderChars {
tl: '┌',
t: '─',
tr: '┐',
l: '│',
r: '│',
bl: '└',
b: '─',
br: '┘',
},
Self::Corners => BorderChars {
tl: '┌',
t: ' ',
tr: '┐',
l: ' ',
r: ' ',
bl: '└',
b: ' ',
br: '┘',
},
Self::Barplot => BorderChars {
tl: '┌',
t: ' ',
tr: '┐',
l: '┤',
r: ' ',
bl: '└',
b: ' ',
br: '┘',
},
Self::Ascii => BorderChars {
tl: '+',
t: '-',
tr: '+',
l: '|',
r: '|',
bl: '+',
b: '-',
br: '+',
},
}
}
}
#[must_use]
pub const fn border_types() -> &'static [BorderType] {
&[BorderType::Barplot, BorderType::Corners, BorderType::Solid]
}
#[cfg(test)]
mod tests {
use super::{BorderType, border_types};
#[test]
fn solid_border_chars_match_reference() {
let chars = BorderType::Solid.chars();
assert_eq!(chars.tl, '┌');
assert_eq!(chars.t, '─');
assert_eq!(chars.tr, '┐');
assert_eq!(chars.l, '│');
assert_eq!(chars.r, '│');
assert_eq!(chars.bl, '└');
assert_eq!(chars.b, '─');
assert_eq!(chars.br, '┘');
}
#[test]
fn corners_border_chars_match_reference() {
let chars = BorderType::Corners.chars();
assert_eq!(chars.tl, '┌');
assert_eq!(chars.t, ' ');
assert_eq!(chars.tr, '┐');
assert_eq!(chars.l, ' ');
assert_eq!(chars.r, ' ');
assert_eq!(chars.bl, '└');
assert_eq!(chars.b, ' ');
assert_eq!(chars.br, '┘');
}
#[test]
fn barplot_border_chars_match_reference() {
let chars = BorderType::Barplot.chars();
assert_eq!(chars.tl, '┌');
assert_eq!(chars.t, ' ');
assert_eq!(chars.tr, '┐');
assert_eq!(chars.l, '┤');
assert_eq!(chars.r, ' ');
assert_eq!(chars.bl, '└');
assert_eq!(chars.b, ' ');
assert_eq!(chars.br, '┘');
}
#[test]
fn border_types_lists_public_variants() {
assert_eq!(
border_types(),
&[BorderType::Barplot, BorderType::Corners, BorderType::Solid]
);
}
#[test]
fn ascii_border_chars_match_reference() {
let chars = BorderType::Ascii.chars();
assert_eq!(chars.tl, '+');
assert_eq!(chars.t, '-');
assert_eq!(chars.tr, '+');
assert_eq!(chars.l, '|');
assert_eq!(chars.r, '|');
assert_eq!(chars.bl, '+');
assert_eq!(chars.b, '-');
assert_eq!(chars.br, '+');
}
}