#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RowLevel {
Head,
Row,
Foot,
Mid,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Box {
pub top_left: char,
pub top: char,
pub top_divider: char,
pub top_right: char,
pub head_left: char,
pub head_vertical: char,
pub head_right: char,
pub head_row_left: char,
pub head_row_horizontal: char,
pub head_row_cross: char,
pub head_row_right: char,
pub mid_left: char,
pub mid_vertical: char,
pub mid_right: char,
pub row_left: char,
pub row_horizontal: char,
pub row_cross: char,
pub row_right: char,
pub foot_row_left: char,
pub foot_row_horizontal: char,
pub foot_row_cross: char,
pub foot_row_right: char,
pub foot_left: char,
pub foot_vertical: char,
pub foot_right: char,
pub bottom_left: char,
pub bottom: char,
pub bottom_divider: char,
pub bottom_right: char,
pub ascii: bool,
}
pub const ASCII: Box = Box {
top_left: '+',
top: '-',
top_divider: '-',
top_right: '+',
head_left: '|',
head_vertical: '|',
head_right: '|',
head_row_left: '|',
head_row_horizontal: '-',
head_row_cross: '+',
head_row_right: '|',
mid_left: '|',
mid_vertical: '|',
mid_right: '|',
row_left: '|',
row_horizontal: '-',
row_cross: '+',
row_right: '|',
foot_row_left: '|',
foot_row_horizontal: '-',
foot_row_cross: '+',
foot_row_right: '|',
foot_left: '|',
foot_vertical: '|',
foot_right: '|',
bottom_left: '+',
bottom: '-',
bottom_divider: '-',
bottom_right: '+',
ascii: true,
};
pub const ASCII2: Box = Box {
top_left: '+',
top: '-',
top_divider: '+',
top_right: '+',
head_left: '|',
head_vertical: '|',
head_right: '|',
head_row_left: '+',
head_row_horizontal: '-',
head_row_cross: '+',
head_row_right: '+',
mid_left: '|',
mid_vertical: '|',
mid_right: '|',
row_left: '+',
row_horizontal: '-',
row_cross: '+',
row_right: '+',
foot_row_left: '+',
foot_row_horizontal: '-',
foot_row_cross: '+',
foot_row_right: '+',
foot_left: '|',
foot_vertical: '|',
foot_right: '|',
bottom_left: '+',
bottom: '-',
bottom_divider: '+',
bottom_right: '+',
ascii: true,
};
pub const ASCII_DOUBLE_HEAD: Box = Box {
top_left: '+',
top: '-',
top_divider: '+',
top_right: '+',
head_left: '|',
head_vertical: '|',
head_right: '|',
head_row_left: '+',
head_row_horizontal: '=',
head_row_cross: '+',
head_row_right: '+',
mid_left: '|',
mid_vertical: '|',
mid_right: '|',
row_left: '+',
row_horizontal: '-',
row_cross: '+',
row_right: '+',
foot_row_left: '+',
foot_row_horizontal: '-',
foot_row_cross: '+',
foot_row_right: '+',
foot_left: '|',
foot_vertical: '|',
foot_right: '|',
bottom_left: '+',
bottom: '-',
bottom_divider: '+',
bottom_right: '+',
ascii: true,
};
pub const SQUARE: Box = Box {
top_left: '┌',
top: '─',
top_divider: '┬',
top_right: '┐',
head_left: '│',
head_vertical: '│',
head_right: '│',
head_row_left: '├',
head_row_horizontal: '─',
head_row_cross: '┼',
head_row_right: '┤',
mid_left: '│',
mid_vertical: '│',
mid_right: '│',
row_left: '├',
row_horizontal: '─',
row_cross: '┼',
row_right: '┤',
foot_row_left: '├',
foot_row_horizontal: '─',
foot_row_cross: '┼',
foot_row_right: '┤',
foot_left: '│',
foot_vertical: '│',
foot_right: '│',
bottom_left: '└',
bottom: '─',
bottom_divider: '┴',
bottom_right: '┘',
ascii: false,
};
pub const SQUARE_DOUBLE_HEAD: Box = Box {
top_left: '┌',
top: '─',
top_divider: '┬',
top_right: '┐',
head_left: '│',
head_vertical: '│',
head_right: '│',
head_row_left: '╞',
head_row_horizontal: '═',
head_row_cross: '╪',
head_row_right: '╡',
mid_left: '│',
mid_vertical: '│',
mid_right: '│',
row_left: '├',
row_horizontal: '─',
row_cross: '┼',
row_right: '┤',
foot_row_left: '├',
foot_row_horizontal: '─',
foot_row_cross: '┼',
foot_row_right: '┤',
foot_left: '│',
foot_vertical: '│',
foot_right: '│',
bottom_left: '└',
bottom: '─',
bottom_divider: '┴',
bottom_right: '┘',
ascii: false,
};
pub const MINIMAL: Box = Box {
top_left: ' ',
top: ' ',
top_divider: '╷',
top_right: ' ',
head_left: ' ',
head_vertical: '│',
head_right: ' ',
head_row_left: '╶',
head_row_horizontal: '─',
head_row_cross: '┼',
head_row_right: '╴',
mid_left: ' ',
mid_vertical: '│',
mid_right: ' ',
row_left: '╶',
row_horizontal: '─',
row_cross: '┼',
row_right: '╴',
foot_row_left: '╶',
foot_row_horizontal: '─',
foot_row_cross: '┼',
foot_row_right: '╴',
foot_left: ' ',
foot_vertical: '│',
foot_right: ' ',
bottom_left: ' ',
bottom: ' ',
bottom_divider: '╵',
bottom_right: ' ',
ascii: false,
};
pub const MINIMAL_HEAVY_HEAD: Box = Box {
top_left: ' ',
top: ' ',
top_divider: '╷',
top_right: ' ',
head_left: ' ',
head_vertical: '│',
head_right: ' ',
head_row_left: '╺',
head_row_horizontal: '━',
head_row_cross: '┿',
head_row_right: '╸',
mid_left: ' ',
mid_vertical: '│',
mid_right: ' ',
row_left: '╶',
row_horizontal: '─',
row_cross: '┼',
row_right: '╴',
foot_row_left: '╶',
foot_row_horizontal: '─',
foot_row_cross: '┼',
foot_row_right: '╴',
foot_left: ' ',
foot_vertical: '│',
foot_right: ' ',
bottom_left: ' ',
bottom: ' ',
bottom_divider: '╵',
bottom_right: ' ',
ascii: false,
};
pub const MINIMAL_DOUBLE_HEAD: Box = Box {
top_left: ' ',
top: ' ',
top_divider: '╷',
top_right: ' ',
head_left: ' ',
head_vertical: '│',
head_right: ' ',
head_row_left: ' ',
head_row_horizontal: '═',
head_row_cross: '╪',
head_row_right: ' ',
mid_left: ' ',
mid_vertical: '│',
mid_right: ' ',
row_left: ' ',
row_horizontal: '─',
row_cross: '┼',
row_right: ' ',
foot_row_left: ' ',
foot_row_horizontal: '─',
foot_row_cross: '┼',
foot_row_right: ' ',
foot_left: ' ',
foot_vertical: '│',
foot_right: ' ',
bottom_left: ' ',
bottom: ' ',
bottom_divider: '╵',
bottom_right: ' ',
ascii: false,
};
pub const SIMPLE: Box = Box {
top_left: ' ',
top: ' ',
top_divider: ' ',
top_right: ' ',
head_left: ' ',
head_vertical: ' ',
head_right: ' ',
head_row_left: ' ',
head_row_horizontal: '─',
head_row_cross: '─',
head_row_right: ' ',
mid_left: ' ',
mid_vertical: ' ',
mid_right: ' ',
row_left: ' ',
row_horizontal: ' ',
row_cross: ' ',
row_right: ' ',
foot_row_left: ' ',
foot_row_horizontal: '─',
foot_row_cross: '─',
foot_row_right: ' ',
foot_left: ' ',
foot_vertical: ' ',
foot_right: ' ',
bottom_left: ' ',
bottom: ' ',
bottom_divider: ' ',
bottom_right: ' ',
ascii: false,
};
pub const SIMPLE_HEAD: Box = Box {
top_left: ' ',
top: ' ',
top_divider: ' ',
top_right: ' ',
head_left: ' ',
head_vertical: ' ',
head_right: ' ',
head_row_left: ' ',
head_row_horizontal: '─',
head_row_cross: '─',
head_row_right: ' ',
mid_left: ' ',
mid_vertical: ' ',
mid_right: ' ',
row_left: ' ',
row_horizontal: ' ',
row_cross: ' ',
row_right: ' ',
foot_row_left: ' ',
foot_row_horizontal: ' ',
foot_row_cross: ' ',
foot_row_right: ' ',
foot_left: ' ',
foot_vertical: ' ',
foot_right: ' ',
bottom_left: ' ',
bottom: ' ',
bottom_divider: ' ',
bottom_right: ' ',
ascii: false,
};
pub const SIMPLE_HEAVY: Box = Box {
top_left: ' ',
top: ' ',
top_divider: ' ',
top_right: ' ',
head_left: ' ',
head_vertical: ' ',
head_right: ' ',
head_row_left: ' ',
head_row_horizontal: '━',
head_row_cross: '━',
head_row_right: ' ',
mid_left: ' ',
mid_vertical: ' ',
mid_right: ' ',
row_left: ' ',
row_horizontal: ' ',
row_cross: ' ',
row_right: ' ',
foot_row_left: ' ',
foot_row_horizontal: '━',
foot_row_cross: '━',
foot_row_right: ' ',
foot_left: ' ',
foot_vertical: ' ',
foot_right: ' ',
bottom_left: ' ',
bottom: ' ',
bottom_divider: ' ',
bottom_right: ' ',
ascii: false,
};
pub const HORIZONTALS: Box = Box {
top_left: ' ',
top: '─',
top_divider: '─',
top_right: ' ',
head_left: ' ',
head_vertical: ' ',
head_right: ' ',
head_row_left: ' ',
head_row_horizontal: '─',
head_row_cross: '─',
head_row_right: ' ',
mid_left: ' ',
mid_vertical: ' ',
mid_right: ' ',
row_left: ' ',
row_horizontal: '─',
row_cross: '─',
row_right: ' ',
foot_row_left: ' ',
foot_row_horizontal: '─',
foot_row_cross: '─',
foot_row_right: ' ',
foot_left: ' ',
foot_vertical: ' ',
foot_right: ' ',
bottom_left: ' ',
bottom: '─',
bottom_divider: '─',
bottom_right: ' ',
ascii: false,
};
pub const ROUNDED: Box = Box {
top_left: '╭',
top: '─',
top_divider: '┬',
top_right: '╮',
head_left: '│',
head_vertical: '│',
head_right: '│',
head_row_left: '├',
head_row_horizontal: '─',
head_row_cross: '┼',
head_row_right: '┤',
mid_left: '│',
mid_vertical: '│',
mid_right: '│',
row_left: '├',
row_horizontal: '─',
row_cross: '┼',
row_right: '┤',
foot_row_left: '├',
foot_row_horizontal: '─',
foot_row_cross: '┼',
foot_row_right: '┤',
foot_left: '│',
foot_vertical: '│',
foot_right: '│',
bottom_left: '╰',
bottom: '─',
bottom_divider: '┴',
bottom_right: '╯',
ascii: false,
};
pub const HEAVY: Box = Box {
top_left: '┏',
top: '━',
top_divider: '┳',
top_right: '┓',
head_left: '┃',
head_vertical: '┃',
head_right: '┃',
head_row_left: '┣',
head_row_horizontal: '━',
head_row_cross: '╋',
head_row_right: '┫',
mid_left: '┃',
mid_vertical: '┃',
mid_right: '┃',
row_left: '┣',
row_horizontal: '━',
row_cross: '╋',
row_right: '┫',
foot_row_left: '┣',
foot_row_horizontal: '━',
foot_row_cross: '╋',
foot_row_right: '┫',
foot_left: '┃',
foot_vertical: '┃',
foot_right: '┃',
bottom_left: '┗',
bottom: '━',
bottom_divider: '┻',
bottom_right: '┛',
ascii: false,
};
pub const HEAVY_EDGE: Box = Box {
top_left: '┏',
top: '━',
top_divider: '┯',
top_right: '┓',
head_left: '┃',
head_vertical: '│',
head_right: '┃',
head_row_left: '┠',
head_row_horizontal: '─',
head_row_cross: '┼',
head_row_right: '┨',
mid_left: '┃',
mid_vertical: '│',
mid_right: '┃',
row_left: '┠',
row_horizontal: '─',
row_cross: '┼',
row_right: '┨',
foot_row_left: '┠',
foot_row_horizontal: '─',
foot_row_cross: '┼',
foot_row_right: '┨',
foot_left: '┃',
foot_vertical: '│',
foot_right: '┃',
bottom_left: '┗',
bottom: '━',
bottom_divider: '┷',
bottom_right: '┛',
ascii: false,
};
pub const HEAVY_HEAD: Box = Box {
top_left: '┏',
top: '━',
top_divider: '┳',
top_right: '┓',
head_left: '┃',
head_vertical: '┃',
head_right: '┃',
head_row_left: '┡',
head_row_horizontal: '━',
head_row_cross: '╇',
head_row_right: '┩',
mid_left: '│',
mid_vertical: '│',
mid_right: '│',
row_left: '├',
row_horizontal: '─',
row_cross: '┼',
row_right: '┤',
foot_row_left: '├',
foot_row_horizontal: '─',
foot_row_cross: '┼',
foot_row_right: '┤',
foot_left: '│',
foot_vertical: '│',
foot_right: '│',
bottom_left: '└',
bottom: '─',
bottom_divider: '┴',
bottom_right: '┘',
ascii: false,
};
pub const DOUBLE: Box = Box {
top_left: '╔',
top: '═',
top_divider: '╦',
top_right: '╗',
head_left: '║',
head_vertical: '║',
head_right: '║',
head_row_left: '╠',
head_row_horizontal: '═',
head_row_cross: '╬',
head_row_right: '╣',
mid_left: '║',
mid_vertical: '║',
mid_right: '║',
row_left: '╠',
row_horizontal: '═',
row_cross: '╬',
row_right: '╣',
foot_row_left: '╠',
foot_row_horizontal: '═',
foot_row_cross: '╬',
foot_row_right: '╣',
foot_left: '║',
foot_vertical: '║',
foot_right: '║',
bottom_left: '╚',
bottom: '═',
bottom_divider: '╩',
bottom_right: '╝',
ascii: false,
};
pub const DOUBLE_EDGE: Box = Box {
top_left: '╔',
top: '═',
top_divider: '╤',
top_right: '╗',
head_left: '║',
head_vertical: '│',
head_right: '║',
head_row_left: '╟',
head_row_horizontal: '─',
head_row_cross: '┼',
head_row_right: '╢',
mid_left: '║',
mid_vertical: '│',
mid_right: '║',
row_left: '╟',
row_horizontal: '─',
row_cross: '┼',
row_right: '╢',
foot_row_left: '╟',
foot_row_horizontal: '─',
foot_row_cross: '┼',
foot_row_right: '╢',
foot_left: '║',
foot_vertical: '│',
foot_right: '║',
bottom_left: '╚',
bottom: '═',
bottom_divider: '╧',
bottom_right: '╝',
ascii: false,
};
pub const MARKDOWN: Box = Box {
top_left: ' ',
top: ' ',
top_divider: ' ',
top_right: ' ',
head_left: '|',
head_vertical: '|',
head_right: '|',
head_row_left: '|',
head_row_horizontal: '-',
head_row_cross: '|',
head_row_right: '|',
mid_left: '|',
mid_vertical: '|',
mid_right: '|',
row_left: '|',
row_horizontal: '-',
row_cross: '|',
row_right: '|',
foot_row_left: '|',
foot_row_horizontal: '-',
foot_row_cross: '|',
foot_row_right: '|',
foot_left: '|',
foot_vertical: '|',
foot_right: '|',
bottom_left: ' ',
bottom: ' ',
bottom_divider: ' ',
bottom_right: ' ',
ascii: true,
};
impl Box {
pub fn substitute(&self, legacy_windows: bool, ascii_only: bool) -> Box {
let mut result = *self;
if legacy_windows {
result =
if *self == ROUNDED || *self == HEAVY || *self == HEAVY_EDGE || *self == HEAVY_HEAD
{
SQUARE
} else if *self == MINIMAL_HEAVY_HEAD {
MINIMAL
} else if *self == SIMPLE_HEAVY {
SIMPLE
} else {
result
};
}
if ascii_only && !result.ascii {
return ASCII;
}
result
}
pub fn get_plain_headed_box(&self) -> Box {
if *self == HEAVY_HEAD || *self == SQUARE_DOUBLE_HEAD {
SQUARE
} else if *self == MINIMAL_DOUBLE_HEAD || *self == MINIMAL_HEAVY_HEAD {
MINIMAL
} else if *self == ASCII_DOUBLE_HEAD {
ASCII2
} else {
*self
}
}
pub fn get_top(&self, widths: &[usize]) -> String {
let mut parts = String::new();
parts.push(self.top_left);
for (i, &width) in widths.iter().enumerate() {
for _ in 0..width {
parts.push(self.top);
}
if i < widths.len() - 1 {
parts.push(self.top_divider);
}
}
parts.push(self.top_right);
parts
}
pub fn get_row(&self, widths: &[usize], level: RowLevel, edge: bool) -> String {
let (left, horizontal, cross, right) = match level {
RowLevel::Head => (
self.head_row_left,
self.head_row_horizontal,
self.head_row_cross,
self.head_row_right,
),
RowLevel::Row => (
self.row_left,
self.row_horizontal,
self.row_cross,
self.row_right,
),
RowLevel::Foot => (
self.foot_row_left,
self.foot_row_horizontal,
self.foot_row_cross,
self.foot_row_right,
),
RowLevel::Mid => (self.mid_left, ' ', self.mid_vertical, self.mid_right),
};
let mut parts = String::new();
if edge {
parts.push(left);
}
for (i, &width) in widths.iter().enumerate() {
for _ in 0..width {
parts.push(horizontal);
}
if i < widths.len() - 1 {
parts.push(cross);
}
}
if edge {
parts.push(right);
}
parts
}
pub fn get_bottom(&self, widths: &[usize]) -> String {
let mut parts = String::new();
parts.push(self.bottom_left);
for (i, &width) in widths.iter().enumerate() {
for _ in 0..width {
parts.push(self.bottom);
}
if i < widths.len() - 1 {
parts.push(self.bottom_divider);
}
}
parts.push(self.bottom_right);
parts
}
pub fn top_edge(&self, width: usize) -> String {
self.get_top(&[width])
}
pub fn bottom_edge(&self, width: usize) -> String {
self.get_bottom(&[width])
}
}
#[deprecated(since = "0.2.0", note = "Use `Box` instead")]
pub type BoxChars = Box;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_box_top_edge() {
assert_eq!(ROUNDED.top_edge(3), "╭───╮");
assert_eq!(ROUNDED.bottom_edge(3), "╰───╯");
}
#[test]
fn test_ascii_box() {
assert_eq!(ASCII.top_edge(3), "+---+");
assert_eq!(ASCII.bottom_edge(3), "+---+");
}
#[test]
fn test_square_box() {
assert_eq!(SQUARE.top_edge(5), "┌─────┐");
assert_eq!(SQUARE.bottom_edge(5), "└─────┘");
}
#[test]
fn test_heavy_box() {
assert_eq!(HEAVY.top_edge(4), "┏━━━━┓");
assert_eq!(HEAVY.bottom_edge(4), "┗━━━━┛");
}
#[test]
fn test_double_box() {
assert_eq!(DOUBLE.top_edge(3), "╔═══╗");
assert_eq!(DOUBLE.bottom_edge(3), "╚═══╝");
}
#[test]
fn test_get_top_multiple_columns() {
assert_eq!(SQUARE.get_top(&[3, 5, 2]), "┌───┬─────┬──┐");
assert_eq!(ASCII.get_top(&[3, 5, 2]), "+------------+");
assert_eq!(ASCII2.get_top(&[3, 5, 2]), "+---+-----+--+");
assert_eq!(HEAVY.get_top(&[2, 2]), "┏━━┳━━┓");
}
#[test]
fn test_get_bottom_multiple_columns() {
assert_eq!(SQUARE.get_bottom(&[3, 5, 2]), "└───┴─────┴──┘");
assert_eq!(ASCII.get_bottom(&[3, 5, 2]), "+------------+");
assert_eq!(ASCII2.get_bottom(&[3, 5, 2]), "+---+-----+--+");
assert_eq!(DOUBLE.get_bottom(&[4, 4]), "╚════╩════╝");
}
#[test]
fn test_get_row_head() {
assert_eq!(SQUARE.get_row(&[3, 5], RowLevel::Head, true), "├───┼─────┤");
assert_eq!(HEAVY.get_row(&[3, 5], RowLevel::Head, true), "┣━━━╋━━━━━┫");
}
#[test]
fn test_get_row_regular() {
assert_eq!(SQUARE.get_row(&[4, 4], RowLevel::Row, true), "├────┼────┤");
assert_eq!(ASCII.get_row(&[3, 3], RowLevel::Row, true), "|---+---|");
}
#[test]
fn test_get_row_foot() {
assert_eq!(SQUARE.get_row(&[3, 3], RowLevel::Foot, true), "├───┼───┤");
}
#[test]
fn test_get_row_mid() {
assert_eq!(SQUARE.get_row(&[3, 3], RowLevel::Mid, true), "│ │ │");
assert_eq!(HEAVY.get_row(&[2, 2], RowLevel::Mid, true), "┃ ┃ ┃");
}
#[test]
fn test_get_row_no_edge() {
assert_eq!(SQUARE.get_row(&[3, 3], RowLevel::Row, false), "───┼───");
assert_eq!(ASCII.get_row(&[2, 2], RowLevel::Row, false), "--+--");
}
#[test]
fn test_substitute_legacy_windows() {
let result = ROUNDED.substitute(true, false);
assert_eq!(result, SQUARE);
let result = HEAVY.substitute(true, false);
assert_eq!(result, SQUARE);
let result = MINIMAL_HEAVY_HEAD.substitute(true, false);
assert_eq!(result, MINIMAL);
let result = SIMPLE_HEAVY.substitute(true, false);
assert_eq!(result, SIMPLE);
let result = SQUARE.substitute(true, false);
assert_eq!(result, SQUARE);
}
#[test]
fn test_substitute_ascii_only() {
let result = SQUARE.substitute(false, true);
assert_eq!(result, ASCII);
let result = ROUNDED.substitute(false, true);
assert_eq!(result, ASCII);
let result = ASCII.substitute(false, true);
assert_eq!(result, ASCII);
let result = ASCII2.substitute(false, true);
assert_eq!(result, ASCII2);
let result = MARKDOWN.substitute(false, true);
assert_eq!(result, MARKDOWN);
}
#[test]
fn test_substitute_both_flags() {
let result = ROUNDED.substitute(true, true);
assert_eq!(result, ASCII);
}
#[test]
fn test_substitute_custom_box() {
let custom = Box {
top_left: '*',
top: '*',
top_divider: '*',
top_right: '*',
head_left: '*',
head_vertical: '*',
head_right: '*',
head_row_left: '*',
head_row_horizontal: '*',
head_row_cross: '*',
head_row_right: '*',
mid_left: '*',
mid_vertical: '*',
mid_right: '*',
row_left: '*',
row_horizontal: '*',
row_cross: '*',
row_right: '*',
foot_row_left: '*',
foot_row_horizontal: '*',
foot_row_cross: '*',
foot_row_right: '*',
foot_left: '*',
foot_vertical: '*',
foot_right: '*',
bottom_left: '*',
bottom: '*',
bottom_divider: '*',
bottom_right: '*',
ascii: true,
};
let result = custom.substitute(false, false);
assert_eq!(result, custom);
let result = custom.substitute(true, false);
assert_eq!(result, custom);
let result = custom.substitute(false, true);
assert_eq!(result, custom);
let custom_unicode = Box {
ascii: false,
..custom
};
let result = custom_unicode.substitute(false, true);
assert_eq!(result, ASCII);
}
#[test]
fn test_get_plain_headed_box() {
assert_eq!(HEAVY_HEAD.get_plain_headed_box(), SQUARE);
assert_eq!(SQUARE_DOUBLE_HEAD.get_plain_headed_box(), SQUARE);
assert_eq!(MINIMAL_DOUBLE_HEAD.get_plain_headed_box(), MINIMAL);
assert_eq!(MINIMAL_HEAVY_HEAD.get_plain_headed_box(), MINIMAL);
assert_eq!(ASCII_DOUBLE_HEAD.get_plain_headed_box(), ASCII2);
assert_eq!(SQUARE.get_plain_headed_box(), SQUARE);
assert_eq!(ASCII.get_plain_headed_box(), ASCII);
assert_eq!(ROUNDED.get_plain_headed_box(), ROUNDED);
}
#[test]
fn test_get_plain_headed_box_custom() {
let custom = Box {
top_left: '#',
top: '#',
top_divider: '#',
top_right: '#',
head_left: '#',
head_vertical: '#',
head_right: '#',
head_row_left: '#',
head_row_horizontal: '#',
head_row_cross: '#',
head_row_right: '#',
mid_left: '#',
mid_vertical: '#',
mid_right: '#',
row_left: '#',
row_horizontal: '#',
row_cross: '#',
row_right: '#',
foot_row_left: '#',
foot_row_horizontal: '#',
foot_row_cross: '#',
foot_row_right: '#',
foot_left: '#',
foot_vertical: '#',
foot_right: '#',
bottom_left: '#',
bottom: '#',
bottom_divider: '#',
bottom_right: '#',
ascii: true,
};
assert_eq!(custom.get_plain_headed_box(), custom);
}
#[test]
fn test_all_boxes_defined() {
assert!(ASCII.ascii);
assert!(ASCII2.ascii);
assert!(ASCII_DOUBLE_HEAD.ascii);
assert!(!SQUARE.ascii);
assert!(!SQUARE_DOUBLE_HEAD.ascii);
assert!(!MINIMAL.ascii);
assert!(!MINIMAL_HEAVY_HEAD.ascii);
assert!(!MINIMAL_DOUBLE_HEAD.ascii);
assert!(!SIMPLE.ascii);
assert!(!SIMPLE_HEAD.ascii);
assert!(!SIMPLE_HEAVY.ascii);
assert!(!HORIZONTALS.ascii);
assert!(!ROUNDED.ascii);
assert!(!HEAVY.ascii);
assert!(!HEAVY_EDGE.ascii);
assert!(!HEAVY_HEAD.ascii);
assert!(!DOUBLE.ascii);
assert!(!DOUBLE_EDGE.ascii);
assert!(MARKDOWN.ascii);
}
#[test]
fn test_box_equality() {
assert_eq!(SQUARE, SQUARE);
assert_eq!(ROUNDED, ROUNDED);
assert_ne!(SQUARE, ROUNDED);
assert_ne!(ASCII, MARKDOWN);
}
#[test]
fn test_single_column() {
assert_eq!(SQUARE.get_top(&[5]), "┌─────┐");
assert_eq!(SQUARE.get_bottom(&[5]), "└─────┘");
assert_eq!(SQUARE.get_row(&[5], RowLevel::Row, true), "├─────┤");
}
#[test]
fn test_empty_widths() {
assert_eq!(SQUARE.get_top(&[]), "┌┐");
assert_eq!(SQUARE.get_bottom(&[]), "└┘");
assert_eq!(SQUARE.get_row(&[], RowLevel::Row, true), "├┤");
}
#[test]
fn test_zero_width_column() {
assert_eq!(SQUARE.get_top(&[0, 3, 0]), "┌┬───┬┐");
}
#[test]
fn test_markdown_box() {
assert_eq!(MARKDOWN.get_top(&[5]), " ");
assert_eq!(
MARKDOWN.get_row(&[5, 5], RowLevel::Head, true),
"|-----|-----|"
);
assert_eq!(MARKDOWN.get_bottom(&[5]), " ");
assert_eq!(MARKDOWN.get_top(&[5, 5]), " ");
}
#[test]
fn test_horizontals_box() {
assert_eq!(HORIZONTALS.get_top(&[5]), " ───── ");
assert_eq!(HORIZONTALS.get_bottom(&[5]), " ───── ");
}
#[test]
fn test_minimal_box() {
assert_eq!(MINIMAL.get_top(&[3]), " ");
assert_eq!(MINIMAL.get_bottom(&[3]), " ");
assert_eq!(MINIMAL.get_top(&[3, 3]), " ╷ ");
}
#[test]
fn test_simple_box() {
assert_eq!(SIMPLE.get_top(&[5]), " ");
assert_eq!(SIMPLE.get_row(&[5], RowLevel::Head, true), " ───── ");
}
#[test]
fn test_double_headed_boxes() {
assert_eq!(
SQUARE_DOUBLE_HEAD.get_row(&[3], RowLevel::Head, true),
"╞═══╡"
);
assert_eq!(
ASCII_DOUBLE_HEAD.get_row(&[3], RowLevel::Head, true),
"+===+"
);
}
#[test]
fn test_heavy_variations() {
assert_eq!(HEAVY_HEAD.get_top(&[3]), "┏━━━┓");
assert_eq!(HEAVY_HEAD.get_row(&[3], RowLevel::Row, true), "├───┤");
assert_eq!(HEAVY_EDGE.get_top(&[3, 3]), "┏━━━┯━━━┓");
assert_eq!(
HEAVY_EDGE.get_row(&[3, 3], RowLevel::Row, true),
"┠───┼───┨"
);
}
}