use revue::utils::table::*;
#[test]
fn test_align_left() {
assert_eq!(align_left("hi", 5), "hi ");
assert_eq!(align_left("hello", 5), "hello");
assert_eq!(align_left("hello world", 5), "hello");
}
#[test]
fn test_align_right() {
assert_eq!(align_right("hi", 5), " hi");
assert_eq!(align_right("hello", 5), "hello");
}
#[test]
fn test_align_center() {
assert_eq!(align_center("hi", 6), " hi ");
assert_eq!(align_center("hi", 5), " hi ");
}
#[test]
fn test_table_header() {
let table = Table::new()
.col_left("NAME", 10)
.col_right("VALUE", 8)
.spacing(1);
assert_eq!(table.header(), "NAME VALUE");
}
#[test]
fn test_table_row() {
let table = Table::new()
.col_left("NAME", 10)
.col_right("VALUE", 8)
.spacing(1);
assert_eq!(table.row(&["test", "123"]), "test 123");
}
#[test]
fn test_table_with_prefix() {
let table = Table::new()
.prefix(" ")
.col_left("A", 4)
.col_right("B", 4)
.spacing(1);
assert_eq!(table.header(), " A B");
assert_eq!(table.row(&["x", "y"]), " x y");
}
#[test]
fn test_table_total_width() {
let table = Table::new()
.prefix(">>")
.col_left("A", 5)
.col_right("B", 5)
.spacing(2);
assert_eq!(table.total_width(), 14);
}
#[test]
fn test_column_offset() {
let table = Table::new()
.prefix(" ")
.col_left("A", 4)
.col_right("B", 6)
.col_right("C", 8)
.spacing(1);
assert_eq!(table.column_offset(0), 2); assert_eq!(table.column_offset(1), 7); assert_eq!(table.column_offset(2), 14); }
#[test]
fn test_multiple_rows() {
let table = Table::new()
.col_left("HOST", 8)
.col_right("PING", 6)
.spacing(1);
let header = table.header();
let row1 = table.row(&["server1", "3ms"]);
let row2 = table.row(&["server2", "15ms"]);
assert_eq!(header, "HOST PING");
assert_eq!(row1, "server1 3ms");
assert_eq!(row2, "server2 15ms");
}
#[test]
fn test_table_row_with_missing_values() {
let table = Table::new()
.col_left("NAME", 10)
.col_right("VALUE", 8)
.spacing(1);
assert_eq!(table.row(&[]), " ");
assert_eq!(table.row(&["only_one"]), "only_one ");
assert_eq!(table.row(&["one", "two", "three"]), "one two");
}
#[test]
fn test_table_row_empty_values() {
let table = Table::new().col_left("A", 4).col_right("B", 4).spacing(1);
assert_eq!(table.row(&[]), " ");
}
#[test]
fn test_align_default() {
assert_eq!(Align::default(), Align::Left);
}
#[test]
fn test_align_clone() {
let align1 = Align::Center;
let align2 = align1.clone();
assert_eq!(align1, align2);
}
#[test]
fn test_align_copy() {
let a1 = Align::Right;
let a2 = a1;
assert_eq!(a1, Align::Right);
assert_eq!(a2, Align::Right);
}
#[test]
fn test_align_partial_eq() {
assert_eq!(Align::Left, Align::Left);
assert_eq!(Align::Center, Align::Center);
assert_eq!(Align::Right, Align::Right);
assert_ne!(Align::Left, Align::Right);
}
#[test]
fn test_align_debug() {
let debug_str = format!("{:?}", Align::Center);
assert!(debug_str.contains("Center"));
}
#[test]
fn test_column_clone_basic() {
let col1 = Column::new("Test", 10, Align::Left);
let col2 = col1.clone();
assert_eq!(col1.header, col2.header);
assert_eq!(col1.width, col2.width);
assert_eq!(col1.align, col2.align);
}
#[test]
fn test_column_clone_with_header() {
let col1 = Column::new("Original", 15, Align::Center);
let col2 = col1.clone();
assert_eq!(col2.header, "Original");
}
#[test]
fn test_column_clone_with_width() {
let col1 = Column::new("Test", 20, Align::Right);
let col2 = col1.clone();
assert_eq!(col2.width, 20);
}
#[test]
fn test_column_clone_with_align() {
let col1 = Column::new("Test", 10, Align::Center);
let col2 = col1.clone();
assert_eq!(col2.align, Align::Center);
}
#[test]
fn test_column_clone_all_alignments() {
let col_left = Column::new("L", 5, Align::Left).clone();
let col_center = Column::new("C", 5, Align::Center).clone();
let col_right = Column::new("R", 5, Align::Right).clone();
assert_eq!(col_left.align, Align::Left);
assert_eq!(col_center.align, Align::Center);
assert_eq!(col_right.align, Align::Right);
}
#[test]
fn test_column_debug() {
let col = Column::new("Debug", 10, Align::Left);
let debug_str = format!("{:?}", col);
assert!(debug_str.contains("Debug"));
}
#[test]
fn test_table_clone_basic() {
let table1 = Table::new().col_left("A", 5).col_right("B", 5).spacing(1);
let table2 = table1.clone();
assert_eq!(table1.column_count(), table2.column_count());
assert_eq!(table1.total_width(), table2.total_width());
}
#[test]
fn test_column_new_with_str() {
let col = Column::new("Header", 10, Align::Left);
assert_eq!(col.header, "Header");
assert_eq!(col.width, 10);
assert_eq!(col.align, Align::Left);
}
#[test]
fn test_column_new_with_string() {
let col = Column::new(String::from("Owned"), 15, Align::Center);
assert_eq!(col.header, "Owned");
assert_eq!(col.width, 15);
assert_eq!(col.align, Align::Center);
}
#[test]
fn test_column_new_zero_width() {
let col = Column::new("Test", 0, Align::Right);
assert_eq!(col.width, 0);
}
#[test]
fn test_column_new_large_width() {
let col = Column::new("Wide", 1000, Align::Left);
assert_eq!(col.width, 1000);
}
#[test]
fn test_column_new_all_alignments() {
let col_left = Column::new("L", 5, Align::Left);
let col_center = Column::new("C", 5, Align::Center);
let col_right = Column::new("R", 5, Align::Right);
assert_eq!(col_left.align, Align::Left);
assert_eq!(col_center.align, Align::Center);
assert_eq!(col_right.align, Align::Right);
}
#[test]
fn test_column_format_short_text() {
let col = Column::new("Test", 10, Align::Left);
assert_eq!(col.format("hi"), "hi ");
}
#[test]
fn test_column_format_exact_width() {
let col = Column::new("Test", 5, Align::Left);
assert_eq!(col.format("hello"), "hello");
}
#[test]
fn test_column_format_long_text() {
let col = Column::new("Test", 5, Align::Left);
assert_eq!(col.format("hello world"), "hello");
}
#[test]
fn test_column_format_right_align() {
let col = Column::new("Test", 10, Align::Right);
assert_eq!(col.format("hi"), " hi");
}
#[test]
fn test_column_format_center_align() {
let col = Column::new("Test", 10, Align::Center);
assert_eq!(col.format("hi"), " hi ");
}
#[test]
fn test_column_format_header_left() {
let col = Column::new("Name", 10, Align::Left);
assert_eq!(col.format_header(), "Name ");
}
#[test]
fn test_column_format_header_right() {
let col = Column::new("Value", 10, Align::Right);
assert_eq!(col.format_header(), " Value");
}
#[test]
fn test_column_format_header_center() {
let col = Column::new("Title", 10, Align::Center);
assert_eq!(col.format_header(), " Title ");
}
#[test]
fn test_column_format_header_truncated() {
let col = Column::new("Very Long Header", 5, Align::Left);
assert_eq!(col.format_header(), "Very ");
}
#[test]
fn test_table_new_empty() {
let table = Table::new();
assert_eq!(table.column_count(), 0);
}
#[test]
fn test_table_col_left() {
let table = Table::new().col_left("A", 5);
assert_eq!(table.column_count(), 1);
}
#[test]
fn test_table_col_right() {
let table = Table::new().col_right("B", 5);
assert_eq!(table.column_count(), 1);
}
#[test]
fn test_table_col_center() {
let table = Table::new().col_center("C", 5);
assert_eq!(table.column_count(), 1);
}
#[test]
fn test_table_col_multiple() {
let table = Table::new()
.col("A", 5, Align::Left)
.col("B", 5, Align::Right);
assert_eq!(table.column_count(), 2);
}
#[test]
fn test_table_col_with_string() {
let table = Table::new().col(String::from("Owned"), 10, Align::Left);
assert_eq!(table.column_count(), 1);
}
#[test]
fn test_table_column_count_empty() {
let table = Table::new();
assert_eq!(table.column_count(), 0);
}
#[test]
fn test_table_column_count_single() {
let table = Table::new().col("A", 5, Align::Left);
assert_eq!(table.column_count(), 1);
}
#[test]
fn test_table_column_count_many() {
let table = Table::new()
.col("A", 1, Align::Left)
.col("B", 1, Align::Left)
.col("C", 1, Align::Left)
.col("D", 1, Align::Left)
.col("E", 1, Align::Left);
assert_eq!(table.column_count(), 5);
}
#[test]
fn test_table_get_column_first() {
let table = Table::new().col("First", 10, Align::Left);
let col = table.get_column(0);
assert!(col.is_some());
assert_eq!(col.unwrap().header, "First");
}
#[test]
fn test_table_get_column_middle() {
let table = Table::new()
.col("A", 5, Align::Left)
.col("Middle", 10, Align::Center)
.col("B", 5, Align::Left);
let col = table.get_column(1);
assert!(col.is_some());
assert_eq!(col.unwrap().header, "Middle");
}
#[test]
fn test_table_get_column_out_of_bounds() {
let table = Table::new().col("A", 5, Align::Left);
assert!(table.get_column(10).is_none());
}
#[test]
fn test_table_get_column_empty_table() {
let table = Table::new();
assert!(table.get_column(0).is_none());
}
#[test]
fn test_table_column_offset_first_no_prefix() {
let table = Table::new().col_left("A", 5);
assert_eq!(table.column_offset(0), 0);
}
#[test]
fn test_table_column_offset_first_with_prefix() {
let table = Table::new().prefix(">>").col_left("A", 5);
assert_eq!(table.column_offset(0), 2);
}
#[test]
fn test_table_column_offset_second() {
let table = Table::new().col_left("A", 5).col_left("B", 5).spacing(1);
assert_eq!(table.column_offset(1), 6);
}
#[test]
fn test_table_column_offset_out_of_bounds() {
let table = Table::new().col_left("A", 5);
let offset = table.column_offset(10);
assert!(offset >= 5);
}
#[test]
fn test_table_column_offset_with_prefix_and_spacing() {
let table = Table::new()
.prefix(" ")
.col_left("A", 4)
.col_left("B", 6)
.col_left("C", 8)
.spacing(2);
assert_eq!(table.column_offset(0), 2); assert_eq!(table.column_offset(1), 8); assert_eq!(table.column_offset(2), 16); }
#[test]
fn test_align_text_empty_string() {
assert_eq!(align_text("", 5, Align::Left), " ");
}
#[test]
fn test_align_text_zero_width() {
assert_eq!(align_text("test", 0, Align::Left), "");
}
#[test]
fn test_align_text_unicode_wide_chars() {
let result = align_text("ab", 4, Align::Left);
assert_eq!(result.len(), 4);
}
#[test]
fn test_align_text_truncates_long_text() {
let result = align_text("hello world", 5, Align::Left);
assert_eq!(result, "hello");
}
#[test]
fn test_align_text_exact_fit() {
assert_eq!(align_text("hello", 5, Align::Left), "hello");
}
#[test]
fn test_align_left_empty() {
assert_eq!(align_left("", 5), " ");
}
#[test]
fn test_align_right_empty() {
assert_eq!(align_right("", 5), " ");
}
#[test]
fn test_align_center_empty() {
assert_eq!(align_center("", 5), " ");
}
#[test]
fn test_align_left_unicode() {
assert_eq!(align_left("テスト", 10), "テスト ");
}
#[test]
fn test_align_right_unicode() {
assert_eq!(align_right("テスト", 10), " テスト");
}
#[test]
fn test_align_center_unicode() {
assert_eq!(align_center("テ", 5), " テ ");
}
#[test]
fn test_table_row_owned_basic() {
let table = Table::new().col_left("A", 5).col_right("B", 5);
let result = table.row_owned(&vec![String::from("x"), String::from("y")]);
assert_eq!(result, "x y");
}
#[test]
fn test_table_row_owned_empty() {
let table = Table::new().col_left("A", 5);
let result = table.row_owned(&vec![]);
assert_eq!(result, " ");
}
#[test]
fn test_table_row_owned_extra_values() {
let table = Table::new().col_left("A", 5);
let result = table.row_owned(&vec![
String::from("x"),
String::from("y"),
String::from("z"),
]);
assert_eq!(result, "x ");
}
#[test]
fn test_table_total_width_with_prefix() {
let table = Table::new()
.prefix(">>>")
.col_left("A", 5)
.col_left("B", 5)
.spacing(2);
assert_eq!(table.total_width(), 15);
}
#[test]
fn test_table_total_width_no_spacing_single_col() {
let table = Table::new().col_left("A", 10);
assert_eq!(table.total_width(), 10);
}
#[test]
fn test_table_with_all_alignment_types() {
let table = Table::new()
.col_left("Left", 10)
.col_center("Center", 10)
.col_right("Right", 10)
.spacing(1);
assert_eq!(table.column_count(), 3);
assert_eq!(table.total_width(), 32); }
#[test]
fn test_column_with_unicode_header() {
let col = Column::new("🎉 Celebrate", 15, Align::Left);
assert_eq!(col.header, "🎉 Celebrate");
}
#[test]
fn test_table_row_with_unicode_values() {
let table = Table::new()
.col("Name", 10, Align::Left)
.col("Value", 10, Align::Right);
let result = table.row(&["テスト", "値"]);
assert!(!result.is_empty());
}