2019-07-10 10:39:10 +00:00
|
|
|
use tui::backend::TestBackend;
|
|
|
|
use tui::buffer::Buffer;
|
|
|
|
use tui::layout::Constraint;
|
2019-12-15 20:38:18 +00:00
|
|
|
use tui::widgets::{Block, Borders, Row, Table};
|
2019-07-10 10:39:10 +00:00
|
|
|
use tui::Terminal;
|
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn widgets_table_column_spacing_can_be_changed() {
|
2020-05-21 18:17:55 +00:00
|
|
|
let test_case = |column_spacing, expected| {
|
2019-07-10 10:39:10 +00:00
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
terminal
|
2020-06-15 20:57:23 +00:00
|
|
|
.draw(|f| {
|
2019-07-10 10:39:10 +00:00
|
|
|
let size = f.size();
|
2019-12-15 20:38:18 +00:00
|
|
|
let table = Table::new(
|
2019-07-10 10:39:10 +00:00
|
|
|
["Head1", "Head2", "Head3"].iter(),
|
|
|
|
vec![
|
|
|
|
Row::Data(["Row11", "Row12", "Row13"].iter()),
|
|
|
|
Row::Data(["Row21", "Row22", "Row23"].iter()),
|
|
|
|
Row::Data(["Row31", "Row32", "Row33"].iter()),
|
|
|
|
Row::Data(["Row41", "Row42", "Row43"].iter()),
|
|
|
|
]
|
|
|
|
.into_iter(),
|
|
|
|
)
|
|
|
|
.block(Block::default().borders(Borders::ALL))
|
|
|
|
.widths(&[
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
])
|
2019-12-15 20:38:18 +00:00
|
|
|
.column_spacing(column_spacing);
|
|
|
|
f.render_widget(table, size);
|
2019-07-10 10:39:10 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2020-05-21 18:17:55 +00:00
|
|
|
terminal.backend().assert_buffer(&expected);
|
2019-07-10 10:39:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// no space between columns
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
0,
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1Head2Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11Row12Row13 │",
|
|
|
|
"│Row21Row22Row23 │",
|
|
|
|
"│Row31Row32Row33 │",
|
|
|
|
"│Row41Row42Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// one space between columns
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
1,
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// enough space to just not hide the third column
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
6,
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// enough space to hide part of the third column
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
7,
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head│",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row1│",
|
|
|
|
"│Row21 Row22 Row2│",
|
|
|
|
"│Row31 Row32 Row3│",
|
|
|
|
"│Row41 Row42 Row4│",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn widgets_table_columns_widths_can_use_fixed_length_constraints() {
|
2020-05-21 18:17:55 +00:00
|
|
|
let test_case = |widths, expected| {
|
2019-07-10 10:39:10 +00:00
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
terminal
|
2020-06-15 20:57:23 +00:00
|
|
|
.draw(|f| {
|
2019-07-10 10:39:10 +00:00
|
|
|
let size = f.size();
|
2019-12-15 20:38:18 +00:00
|
|
|
let table = Table::new(
|
2019-07-10 10:39:10 +00:00
|
|
|
["Head1", "Head2", "Head3"].iter(),
|
|
|
|
vec![
|
|
|
|
Row::Data(["Row11", "Row12", "Row13"].iter()),
|
|
|
|
Row::Data(["Row21", "Row22", "Row23"].iter()),
|
|
|
|
Row::Data(["Row31", "Row32", "Row33"].iter()),
|
|
|
|
Row::Data(["Row41", "Row42", "Row43"].iter()),
|
|
|
|
]
|
|
|
|
.into_iter(),
|
|
|
|
)
|
|
|
|
.block(Block::default().borders(Borders::ALL))
|
2019-12-15 20:38:18 +00:00
|
|
|
.widths(widths);
|
|
|
|
f.render_widget(table, size);
|
2019-07-10 10:39:10 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2020-05-21 18:17:55 +00:00
|
|
|
terminal.backend().assert_buffer(&expected);
|
2019-07-10 10:39:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// columns of zero width show nothing
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2019-07-10 10:39:10 +00:00
|
|
|
Constraint::Length(0),
|
|
|
|
Constraint::Length(0),
|
2020-05-21 18:17:55 +00:00
|
|
|
Constraint::Length(0),
|
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// columns of 1 width trim
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2019-07-10 10:39:10 +00:00
|
|
|
Constraint::Length(1),
|
|
|
|
Constraint::Length(1),
|
2020-05-21 18:17:55 +00:00
|
|
|
Constraint::Length(1),
|
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│H H H │",
|
|
|
|
"│ │",
|
|
|
|
"│R R R │",
|
|
|
|
"│R R R │",
|
|
|
|
"│R R R │",
|
|
|
|
"│R R R │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// columns of large width just before pushing a column off
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2019-07-10 10:39:10 +00:00
|
|
|
Constraint::Length(8),
|
|
|
|
Constraint::Length(8),
|
2020-05-21 18:17:55 +00:00
|
|
|
Constraint::Length(8),
|
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn widgets_table_columns_widths_can_use_percentage_constraints() {
|
2020-05-21 18:17:55 +00:00
|
|
|
let test_case = |widths, expected| {
|
2019-07-10 10:39:10 +00:00
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
terminal
|
2020-06-15 20:57:23 +00:00
|
|
|
.draw(|f| {
|
2019-07-10 10:39:10 +00:00
|
|
|
let size = f.size();
|
2019-12-15 20:38:18 +00:00
|
|
|
let table = Table::new(
|
2019-07-10 10:39:10 +00:00
|
|
|
["Head1", "Head2", "Head3"].iter(),
|
|
|
|
vec![
|
|
|
|
Row::Data(["Row11", "Row12", "Row13"].iter()),
|
|
|
|
Row::Data(["Row21", "Row22", "Row23"].iter()),
|
|
|
|
Row::Data(["Row31", "Row32", "Row33"].iter()),
|
|
|
|
Row::Data(["Row41", "Row42", "Row43"].iter()),
|
|
|
|
]
|
|
|
|
.into_iter(),
|
|
|
|
)
|
|
|
|
.block(Block::default().borders(Borders::ALL))
|
|
|
|
.widths(widths)
|
2019-12-15 20:38:18 +00:00
|
|
|
.column_spacing(0);
|
|
|
|
f.render_widget(table, size);
|
2019-07-10 10:39:10 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2020-05-21 18:17:55 +00:00
|
|
|
terminal.backend().assert_buffer(&expected);
|
2019-07-10 10:39:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// columns of zero width show nothing
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2019-07-10 10:39:10 +00:00
|
|
|
Constraint::Percentage(0),
|
|
|
|
Constraint::Percentage(0),
|
2020-05-21 18:17:55 +00:00
|
|
|
Constraint::Percentage(0),
|
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// columns of not enough width trims the data
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2020-11-14 15:45:36 +00:00
|
|
|
Constraint::Percentage(11),
|
|
|
|
Constraint::Percentage(11),
|
|
|
|
Constraint::Percentage(11),
|
2020-05-21 18:17:55 +00:00
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│HeaHeaHea │",
|
|
|
|
"│ │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// columns of large width just before pushing a column off
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2020-11-14 15:45:36 +00:00
|
|
|
Constraint::Percentage(33),
|
|
|
|
Constraint::Percentage(33),
|
|
|
|
Constraint::Percentage(33),
|
2020-05-21 18:17:55 +00:00
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// percentages summing to 100 should give equal widths
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[Constraint::Percentage(50), Constraint::Percentage(50)],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
2020-11-14 15:45:36 +00:00
|
|
|
"│Head1 Head2 │",
|
2019-07-10 10:39:10 +00:00
|
|
|
"│ │",
|
2020-11-14 15:45:36 +00:00
|
|
|
"│Row11 Row12 │",
|
|
|
|
"│Row21 Row22 │",
|
|
|
|
"│Row31 Row32 │",
|
|
|
|
"│Row41 Row42 │",
|
2019-07-10 10:39:10 +00:00
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn widgets_table_columns_widths_can_use_mixed_constraints() {
|
2020-05-21 18:17:55 +00:00
|
|
|
let test_case = |widths, expected| {
|
2019-07-10 10:39:10 +00:00
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
terminal
|
2020-06-15 20:57:23 +00:00
|
|
|
.draw(|f| {
|
2019-07-10 10:39:10 +00:00
|
|
|
let size = f.size();
|
2019-12-15 20:38:18 +00:00
|
|
|
let table = Table::new(
|
2019-07-10 10:39:10 +00:00
|
|
|
["Head1", "Head2", "Head3"].iter(),
|
|
|
|
vec![
|
|
|
|
Row::Data(["Row11", "Row12", "Row13"].iter()),
|
|
|
|
Row::Data(["Row21", "Row22", "Row23"].iter()),
|
|
|
|
Row::Data(["Row31", "Row32", "Row33"].iter()),
|
|
|
|
Row::Data(["Row41", "Row42", "Row43"].iter()),
|
|
|
|
]
|
|
|
|
.into_iter(),
|
|
|
|
)
|
|
|
|
.block(Block::default().borders(Borders::ALL))
|
2019-12-15 20:38:18 +00:00
|
|
|
.widths(widths);
|
|
|
|
f.render_widget(table, size);
|
2019-07-10 10:39:10 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2020-05-21 18:17:55 +00:00
|
|
|
terminal.backend().assert_buffer(&expected);
|
2019-07-10 10:39:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// columns of zero width show nothing
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2019-07-10 10:39:10 +00:00
|
|
|
Constraint::Percentage(0),
|
|
|
|
Constraint::Length(0),
|
2020-05-21 18:17:55 +00:00
|
|
|
Constraint::Percentage(0),
|
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// columns of not enough width trims the data
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2020-11-14 15:45:36 +00:00
|
|
|
Constraint::Percentage(11),
|
2019-07-10 10:39:10 +00:00
|
|
|
Constraint::Length(20),
|
2020-11-14 15:45:36 +00:00
|
|
|
Constraint::Percentage(11),
|
2020-05-21 18:17:55 +00:00
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Hea Head2 Hea│",
|
|
|
|
"│ │",
|
|
|
|
"│Row Row12 Row│",
|
|
|
|
"│Row Row22 Row│",
|
|
|
|
"│Row Row32 Row│",
|
|
|
|
"│Row Row42 Row│",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// columns of large width just before pushing a column off
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2020-11-14 15:45:36 +00:00
|
|
|
Constraint::Percentage(33),
|
2019-07-10 10:39:10 +00:00
|
|
|
Constraint::Length(10),
|
2020-11-14 15:45:36 +00:00
|
|
|
Constraint::Percentage(33),
|
2020-05-21 18:17:55 +00:00
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// columns of large size (>100% total) hide the last column
|
2020-05-21 18:17:55 +00:00
|
|
|
test_case(
|
|
|
|
&[
|
2019-07-10 10:39:10 +00:00
|
|
|
Constraint::Percentage(60),
|
|
|
|
Constraint::Length(10),
|
2020-05-21 18:17:55 +00:00
|
|
|
Constraint::Percentage(60),
|
|
|
|
],
|
2019-07-10 10:39:10 +00:00
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 │",
|
|
|
|
"│Row21 Row22 │",
|
|
|
|
"│Row31 Row32 │",
|
|
|
|
"│Row41 Row42 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
2020-05-21 18:17:55 +00:00
|
|
|
]),
|
2019-07-10 10:39:10 +00:00
|
|
|
);
|
|
|
|
}
|
2020-11-14 15:45:36 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn widgets_table_columns_widths_can_use_ratio_constraints() {
|
|
|
|
let test_case = |widths, expected| {
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
|
|
|
let size = f.size();
|
|
|
|
let table = Table::new(
|
|
|
|
["Head1", "Head2", "Head3"].iter(),
|
|
|
|
vec![
|
|
|
|
Row::Data(["Row11", "Row12", "Row13"].iter()),
|
|
|
|
Row::Data(["Row21", "Row22", "Row23"].iter()),
|
|
|
|
Row::Data(["Row31", "Row32", "Row33"].iter()),
|
|
|
|
Row::Data(["Row41", "Row42", "Row43"].iter()),
|
|
|
|
]
|
|
|
|
.into_iter(),
|
|
|
|
)
|
|
|
|
.block(Block::default().borders(Borders::ALL))
|
|
|
|
.widths(widths)
|
|
|
|
.column_spacing(0);
|
|
|
|
f.render_widget(table, size);
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
};
|
|
|
|
|
|
|
|
// columns of zero width show nothing
|
|
|
|
test_case(
|
|
|
|
&[
|
|
|
|
Constraint::Ratio(0, 1),
|
|
|
|
Constraint::Ratio(0, 1),
|
|
|
|
Constraint::Ratio(0, 1),
|
|
|
|
],
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
// columns of not enough width trims the data
|
|
|
|
test_case(
|
|
|
|
&[
|
|
|
|
Constraint::Ratio(1, 9),
|
|
|
|
Constraint::Ratio(1, 9),
|
|
|
|
Constraint::Ratio(1, 9),
|
|
|
|
],
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│HeaHeaHea │",
|
|
|
|
"│ │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
// columns of large width just before pushing a column off
|
|
|
|
test_case(
|
|
|
|
&[
|
|
|
|
Constraint::Ratio(1, 3),
|
|
|
|
Constraint::Ratio(1, 3),
|
|
|
|
Constraint::Ratio(1, 3),
|
|
|
|
],
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
// percentages summing to 100 should give equal widths
|
|
|
|
test_case(
|
|
|
|
&[Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)],
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 │",
|
|
|
|
"│Row21 Row22 │",
|
|
|
|
"│Row31 Row32 │",
|
|
|
|
"│Row41 Row42 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|