Skip to content

Commit 7f16c4c

Browse files
committed
test(render/media_image): cover draw_thumbnail's zero-sized area guard returning Ok before any image load, so a degenerate zero-width or zero-height layout slot can't surface a spurious [image: …] error — only reachable by calling draw_thumbnail directly, since the public render path never hands a renderer a zero-sized area
1 parent b46b452 commit 7f16c4c

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

‎src/render/media_image.rs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,52 @@ mod tests {
367367
assert!(err.contains("image decode"));
368368
}
369369

370+
#[test]
371+
fn draw_thumbnail_skips_zero_sized_area() {
372+
// Defence-in-depth guard: a zero-width or zero-height cell returns `Ok` before any
373+
// image load, so a degenerate layout slot can't surface a spurious `[image: …]` error.
374+
// Only reachable by calling `draw_thumbnail` directly — the public render path never
375+
// hands a renderer a zero-sized area.
376+
let backend = TestBackend::new(8, 4);
377+
let mut terminal = Terminal::new(backend).unwrap();
378+
terminal
379+
.draw(|frame| {
380+
let zero_width = Rect {
381+
x: 0,
382+
y: 0,
383+
width: 0,
384+
height: 4,
385+
};
386+
let zero_height = Rect {
387+
x: 0,
388+
y: 0,
389+
width: 8,
390+
height: 0,
391+
};
392+
assert!(
393+
draw_thumbnail(
394+
frame,
395+
zero_width,
396+
"/does/not/exist.png",
397+
None,
398+
&Theme::default(),
399+
)
400+
.is_ok()
401+
);
402+
assert!(
403+
draw_thumbnail(
404+
frame,
405+
zero_height,
406+
"/does/not/exist.png",
407+
Some("cover"),
408+
&Theme::default(),
409+
)
410+
.is_ok()
411+
);
412+
})
413+
.unwrap();
414+
}
415+
370416
#[test]
371417
fn padding_shrinks_area_uniformly() {
372418
let area = Rect {

0 commit comments

Comments
 (0)