|
|
|
@ -6,7 +6,7 @@ use tui::Terminal;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn table_column_spacing() {
|
|
|
|
|
let render = |column_spacing| {
|
|
|
|
|
let test_case = |column_spacing, expected| {
|
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
|
@ -33,12 +33,12 @@ fn table_column_spacing() {
|
|
|
|
|
f.render_widget(table, size);
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
terminal.backend().buffer().clone()
|
|
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// no space between columns
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(0),
|
|
|
|
|
test_case(
|
|
|
|
|
0,
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Head1Head2Head3 │",
|
|
|
|
@ -50,12 +50,12 @@ fn table_column_spacing() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// one space between columns
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(1),
|
|
|
|
|
test_case(
|
|
|
|
|
1,
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
@ -67,12 +67,12 @@ fn table_column_spacing() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// enough space to just not hide the third column
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(6),
|
|
|
|
|
test_case(
|
|
|
|
|
6,
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
@ -84,12 +84,12 @@ fn table_column_spacing() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// enough space to hide part of the third column
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(7),
|
|
|
|
|
test_case(
|
|
|
|
|
7,
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Head1 Head2 Head│",
|
|
|
|
@ -101,13 +101,13 @@ fn table_column_spacing() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn table_widths() {
|
|
|
|
|
let render = |widths| {
|
|
|
|
|
let test_case = |widths, expected| {
|
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
|
@ -129,16 +129,16 @@ fn table_widths() {
|
|
|
|
|
f.render_widget(table, size);
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
terminal.backend().buffer().clone()
|
|
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// columns of zero width show nothing
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Length(0),
|
|
|
|
|
Constraint::Length(0),
|
|
|
|
|
Constraint::Length(0)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Length(0),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│ │",
|
|
|
|
@ -150,16 +150,16 @@ fn table_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// columns of 1 width trim
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Length(1),
|
|
|
|
|
Constraint::Length(1),
|
|
|
|
|
Constraint::Length(1)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Length(1),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│H H H │",
|
|
|
|
@ -171,16 +171,16 @@ fn table_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// columns of large width just before pushing a column off
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Length(8),
|
|
|
|
|
Constraint::Length(8),
|
|
|
|
|
Constraint::Length(8)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Length(8),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
@ -192,13 +192,13 @@ fn table_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn table_percentage_widths() {
|
|
|
|
|
let render = |widths| {
|
|
|
|
|
let test_case = |widths, expected| {
|
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
|
@ -221,16 +221,16 @@ fn table_percentage_widths() {
|
|
|
|
|
f.render_widget(table, size);
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
terminal.backend().buffer().clone()
|
|
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// columns of zero width show nothing
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
|
Constraint::Percentage(0)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│ │",
|
|
|
|
@ -242,16 +242,16 @@ fn table_percentage_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// columns of not enough width trims the data
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Percentage(10),
|
|
|
|
|
Constraint::Percentage(10),
|
|
|
|
|
Constraint::Percentage(10)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Percentage(10),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│HeaHeaHea │",
|
|
|
|
@ -263,16 +263,16 @@ fn table_percentage_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// columns of large width just before pushing a column off
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
|
Constraint::Percentage(30)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
@ -284,12 +284,12 @@ fn table_percentage_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// percentages summing to 100 should give equal widths
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[Constraint::Percentage(50), Constraint::Percentage(50)]),
|
|
|
|
|
test_case(
|
|
|
|
|
&[Constraint::Percentage(50), Constraint::Percentage(50)],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Head1 Head2 │",
|
|
|
|
@ -301,13 +301,13 @@ fn table_percentage_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn table_mixed_widths() {
|
|
|
|
|
let render = |widths| {
|
|
|
|
|
let test_case = |widths, expected| {
|
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
|
@ -329,16 +329,16 @@ fn table_mixed_widths() {
|
|
|
|
|
f.render_widget(table, size);
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
terminal.backend().buffer().clone()
|
|
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// columns of zero width show nothing
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
|
Constraint::Length(0),
|
|
|
|
|
Constraint::Percentage(0)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│ │",
|
|
|
|
@ -350,16 +350,16 @@ fn table_mixed_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// columns of not enough width trims the data
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Percentage(10),
|
|
|
|
|
Constraint::Length(20),
|
|
|
|
|
Constraint::Percentage(10)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Percentage(10),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Hea Head2 Hea│",
|
|
|
|
@ -371,16 +371,16 @@ fn table_mixed_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// columns of large width just before pushing a column off
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
|
Constraint::Length(10),
|
|
|
|
|
Constraint::Percentage(30)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
@ -392,16 +392,16 @@ fn table_mixed_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// columns of large size (>100% total) hide the last column
|
|
|
|
|
assert_eq!(
|
|
|
|
|
render(&[
|
|
|
|
|
test_case(
|
|
|
|
|
&[
|
|
|
|
|
Constraint::Percentage(60),
|
|
|
|
|
Constraint::Length(10),
|
|
|
|
|
Constraint::Percentage(60)
|
|
|
|
|
]),
|
|
|
|
|
Constraint::Percentage(60),
|
|
|
|
|
],
|
|
|
|
|
Buffer::with_lines(vec![
|
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
|
"│Head1 Head2 │",
|
|
|
|
@ -413,6 +413,6 @@ fn table_mixed_widths() {
|
|
|
|
|
"│ │",
|
|
|
|
|
"│ │",
|
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
|
])
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
}
|