Skip to content

Commit dc72516

Browse files
committed
test(render/chart_histogram): cover render_histogram's own empty-series guard (only reachable by calling it directly, since render_payload short-circuits empty bodies upstream) leaving the buffer blank, and boost_to_visible passing an all-zero count slice straight through when the zero peak leaves nothing to lift
1 parent fbbb28a commit dc72516

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎src/render/chart_histogram.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,34 @@ mod tests {
291291
render_to_buffer_with_spec(&payload(vec![1, 2, 3, 4, 5]), Some(&spec), &registry, 1, 1);
292292
}
293293

294+
#[test]
295+
fn render_histogram_draws_nothing_for_an_empty_series() {
296+
// `render_payload` short-circuits empty bodies upstream, so the renderer's own
297+
// `data.values.is_empty()` guard is only reachable by calling `render_histogram`
298+
// directly — exercise it and confirm the buffer is left blank.
299+
use ratatui::{Terminal, backend::TestBackend};
300+
301+
let backend = TestBackend::new(20, 6);
302+
let mut terminal = Terminal::new(backend).unwrap();
303+
terminal
304+
.draw(|frame| {
305+
render_histogram(
306+
frame,
307+
frame.area(),
308+
&NumberSeriesData { values: vec![] },
309+
&RenderOptions::default(),
310+
&Theme::default(),
311+
);
312+
})
313+
.unwrap();
314+
let buf = terminal.backend().buffer().clone();
315+
let content: String = (0..6).map(|y| line_text(&buf, y)).collect();
316+
assert!(
317+
content.trim().is_empty(),
318+
"an empty series should leave the buffer blank: {content:?}"
319+
);
320+
}
321+
294322
#[test]
295323
fn single_value_collapses_to_first_bucket() {
296324
let counts = bucket_counts(&[42, 42, 42, 42], 5);
@@ -481,6 +509,12 @@ mod tests {
481509
assert_eq!(boost_to_visible(vec![1, 5, 1], 0), vec![1, 5, 1]);
482510
}
483511

512+
#[test]
513+
fn boost_to_visible_no_op_when_every_count_is_zero() {
514+
// All-zero counts → peak is zero → nothing to lift, the slice passes straight through.
515+
assert_eq!(boost_to_visible(vec![0, 0, 0], 4), vec![0, 0, 0]);
516+
}
517+
484518
#[test]
485519
fn bar_width_fills_available_area() {
486520
assert_eq!(compute_bar_width(50, 10), 5);

0 commit comments

Comments
 (0)