Skip to content

Commit 545d511

Browse files
committed
test(render/animated_splitflap): cover apply_flap's guard and continue arms — bailing out on a zero-sized area, taking the elapsed_ms >= settle_at continue so a fully settled cell keeps its original glyph past the animation window, and the else { continue } arm resolving out-of-range cells to no cell instead of panicking when the area overflows the buffer
1 parent dc72516 commit 545d511

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎src/render/animated_splitflap.rs‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,60 @@ mod tests {
363363
let registry = Registry::with_builtins();
364364
let _ = render_to_buffer_with_spec(&payload, Some(&spec), &registry, 40, 10);
365365
}
366+
367+
#[test]
368+
fn apply_flap_skips_a_zero_sized_area() {
369+
let backend = TestBackend::new(4, 2);
370+
let mut terminal = Terminal::new(backend).unwrap();
371+
terminal
372+
.draw(|frame| {
373+
let zero = Rect {
374+
x: 0,
375+
y: 0,
376+
width: 0,
377+
height: 0,
378+
};
379+
apply_flap(frame, zero, 0, 1_000, &Theme::default());
380+
})
381+
.unwrap();
382+
let buf = terminal.backend().buffer().clone();
383+
assert!((0..2).all(|y| line_text(&buf, y).trim().is_empty()));
384+
}
385+
386+
#[test]
387+
fn apply_flap_leaves_settled_cells_untouched_past_the_window() {
388+
let backend = TestBackend::new(3, 1);
389+
let mut terminal = Terminal::new(backend).unwrap();
390+
terminal
391+
.draw(|frame| {
392+
let area = frame.area();
393+
frame.render_widget(Paragraph::new("AB "), area);
394+
// elapsed == total: every cell has already settled, so each one takes the
395+
// `elapsed_ms >= settle_at` continue and keeps its original glyph.
396+
apply_flap(frame, area, 1_000, 1_000, &Theme::default());
397+
})
398+
.unwrap();
399+
let buf = terminal.backend().buffer().clone();
400+
assert_eq!(buf.cell((0, 0)).unwrap().symbol(), "A");
401+
assert_eq!(buf.cell((1, 0)).unwrap().symbol(), "B");
402+
}
403+
404+
#[test]
405+
fn apply_flap_ignores_cells_outside_the_buffer() {
406+
let backend = TestBackend::new(3, 1);
407+
let mut terminal = Terminal::new(backend).unwrap();
408+
terminal
409+
.draw(|frame| {
410+
// Area deliberately larger than the 3x1 buffer: the out-of-range cells
411+
// resolve to no cell and take the `else { continue }` arm without panicking.
412+
let oversized = Rect {
413+
x: 0,
414+
y: 0,
415+
width: 12,
416+
height: 4,
417+
};
418+
apply_flap(frame, oversized, 0, 1_000, &Theme::default());
419+
})
420+
.unwrap();
421+
}
366422
}

0 commit comments

Comments
 (0)