|
|
|
@ -45,3 +45,169 @@ fn widgets_block_renders() {
|
|
|
|
|
}
|
|
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn widgets_block_renders_on_small_areas() {
|
|
|
|
|
let test_case = |block, area: Rect, expected| {
|
|
|
|
|
let backend = TestBackend::new(area.width, area.height);
|
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
terminal
|
|
|
|
|
.draw(|f| {
|
|
|
|
|
f.render_widget(block, area);
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let one_cell_test_cases = [
|
|
|
|
|
(Borders::NONE, "T"),
|
|
|
|
|
(Borders::LEFT, "│"),
|
|
|
|
|
(Borders::TOP, "T"),
|
|
|
|
|
(Borders::RIGHT, "│"),
|
|
|
|
|
(Borders::BOTTOM, "T"),
|
|
|
|
|
(Borders::ALL, "┌"),
|
|
|
|
|
];
|
|
|
|
|
for (borders, symbol) in one_cell_test_cases.iter().cloned() {
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default().title("Test").borders(borders),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
|
|
|
|
},
|
|
|
|
|
Buffer::empty(Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default().title("Test").borders(borders),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 1,
|
|
|
|
|
height: 0,
|
|
|
|
|
},
|
|
|
|
|
Buffer::empty(Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 1,
|
|
|
|
|
height: 0,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default().title("Test").borders(borders),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::empty(Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 1,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default().title("Test").borders(borders),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 1,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::with_lines(vec![symbol]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default().title("Test").borders(Borders::LEFT),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 4,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::with_lines(vec!["│Tes"]),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default().title("Test").borders(Borders::RIGHT),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 4,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::with_lines(vec!["Tes│"]),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default().title("Test").borders(Borders::RIGHT),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 4,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::with_lines(vec!["Tes│"]),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default()
|
|
|
|
|
.title("Test")
|
|
|
|
|
.borders(Borders::LEFT | Borders::RIGHT),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 4,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::with_lines(vec!["│Te│"]),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default().title("Test").borders(Borders::TOP),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 4,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::with_lines(vec!["Test"]),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default().title("Test").borders(Borders::TOP),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 5,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::with_lines(vec!["Test─"]),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default()
|
|
|
|
|
.title("Test")
|
|
|
|
|
.borders(Borders::LEFT | Borders::TOP),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 5,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::with_lines(vec!["┌Test"]),
|
|
|
|
|
);
|
|
|
|
|
test_case(
|
|
|
|
|
Block::default()
|
|
|
|
|
.title("Test")
|
|
|
|
|
.borders(Borders::LEFT | Borders::TOP),
|
|
|
|
|
Rect {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 6,
|
|
|
|
|
height: 1,
|
|
|
|
|
},
|
|
|
|
|
Buffer::with_lines(vec!["┌Test─"]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|