mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-14 00:47:14 +00:00
f7af8a3863
Order imports by std, external, crate and group them by crate
42 lines
1.7 KiB
Rust
42 lines
1.7 KiB
Rust
use ratatui::{
|
|
backend::TestBackend,
|
|
buffer::Buffer,
|
|
widgets::{BarChart, Block, Borders},
|
|
Terminal,
|
|
};
|
|
|
|
#[test]
|
|
fn widgets_barchart_not_full_below_max_value() {
|
|
let test_case = |expected| {
|
|
let backend = TestBackend::new(30, 10);
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
|
.draw(|f| {
|
|
let size = f.size();
|
|
let barchart = BarChart::default()
|
|
.block(Block::default().borders(Borders::ALL))
|
|
.data(&[("empty", 0), ("half", 50), ("almost", 99), ("full", 100)])
|
|
.max(100)
|
|
.bar_width(7)
|
|
.bar_gap(0);
|
|
f.render_widget(barchart, size);
|
|
})
|
|
.unwrap();
|
|
terminal.backend().assert_buffer(&expected);
|
|
};
|
|
|
|
// check that bars fill up correctly up to max value
|
|
test_case(Buffer::with_lines(vec![
|
|
"┌────────────────────────────┐",
|
|
"│ ▇▇▇▇▇▇▇███████│",
|
|
"│ ██████████████│",
|
|
"│ ██████████████│",
|
|
"│ ▄▄▄▄▄▄▄██████████████│",
|
|
"│ █████████████████████│",
|
|
"│ █████████████████████│",
|
|
"│ ██50█████99█████100██│",
|
|
"│empty half almost full │",
|
|
"└────────────────────────────┘",
|
|
]));
|
|
}
|