From c2355fd6845c7a16838d241fc74819d6c8a84af3 Mon Sep 17 00:00:00 2001 From: Gerrit Viljoen Date: Sun, 17 May 2020 12:51:00 +0200 Subject: [PATCH] save game --- src/test.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test.rs b/src/test.rs index fd39131..3bddec4 100644 --- a/src/test.rs +++ b/src/test.rs @@ -642,3 +642,34 @@ fn color_codes_in_header() { assert_eq!(expected, config.format(input)); } + +#[test] +fn color_codes_pad_right() { + let config = AsciiTable::default(); + let input = vec![ + vec!["Hello".color(Color::Blue).bg_color(Color::Yellow).bold()], + vec!["H".color(Color::Blue).bg_color(Color::Yellow).bold()] + ]; + let expected = "┌───────┐\n\ + │ \u{1b}[38;5;4m\u{1b}[48;5;3;1mHello\u{1b}[0m │\n\ + │ \u{1b}[38;5;4m\u{1b}[48;5;3;1mH \u{1b}[0m │\n\ + └───────┘\n"; + + assert_eq!(expected, config.format(input)); +} + +#[test] +fn color_codes_pad_left() { + let mut config = AsciiTable::default(); + config.columns.insert(0, Column {header: String::new(), align: Right, ..Column::default()}); + let input = vec![ + vec!["Hello".color(Color::Blue).bg_color(Color::Yellow).bold()], + vec!["H".color(Color::Blue).bg_color(Color::Yellow).bold()] + ]; + let expected = "┌───────┐\n\ + │ \u{1b}[38;5;4m\u{1b}[48;5;3;1mHello\u{1b}[0m │\n\ + │ \u{1b}[38;5;4m\u{1b}[48;5;3;1m H\u{1b}[0m │\n\ + └───────┘\n"; + + assert_eq!(expected, config.format(input)); +}