Skip to content

Commit 90f5abc

Browse files
committed
test(render/list_links): cover render_links's zero-dimension area early return, write_row's no-op arm when set_stringn draws zero cells, and the OSC 8 suppression paths skipping the hyperlink wrap in both write_row and wrap_osc8
1 parent eb4eba3 commit 90f5abc

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

‎src/render/list_links.rs‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,77 @@ mod tests {
407407
});
408408
assert!(!osc8_suppressed());
409409
}
410+
411+
#[test]
412+
fn render_links_short_circuits_on_zero_dimension_area() {
413+
use ratatui::{Terminal, backend::TestBackend};
414+
415+
let data = LinkedTextBlockData {
416+
items: vec![line("alpha", Some("https://example.com"))],
417+
};
418+
let opts = RenderOptions::default();
419+
let theme = Theme::default();
420+
let mut terminal = Terminal::new(TestBackend::new(10, 2)).unwrap();
421+
terminal
422+
.draw(|f| {
423+
// A zero-width and a zero-height area both hit the early return —
424+
// neither writes a cell.
425+
render_links(&mut *f, Rect::new(0, 0, 0, 2), &data, &opts, &theme);
426+
render_links(&mut *f, Rect::new(0, 0, 10, 0), &data, &opts, &theme);
427+
})
428+
.unwrap();
429+
let buf = terminal.backend().buffer().clone();
430+
assert!(cells_concat(&buf, 0).trim().is_empty());
431+
}
432+
433+
#[test]
434+
fn write_row_is_a_no_op_when_nothing_is_drawn() {
435+
// `max_width = 0` makes `set_stringn` draw zero cells, so `drawn == 0`.
436+
let mut buf = Buffer::empty(Rect::new(0, 0, 10, 1));
437+
write_row(
438+
&mut buf,
439+
0,
440+
0,
441+
0,
442+
&line("hello", Some("https://example.com")),
443+
Style::default(),
444+
);
445+
assert!(cells_concat(&buf, 0).trim().is_empty());
446+
}
447+
448+
#[test]
449+
fn write_row_skips_osc8_wrap_under_suppression() {
450+
let mut buf = Buffer::empty(Rect::new(0, 0, 20, 1));
451+
without_osc8(|| {
452+
write_row(
453+
&mut buf,
454+
0,
455+
0,
456+
20,
457+
&line("hello", Some("https://example.com")),
458+
Style::default(),
459+
);
460+
});
461+
let row = cells_concat(&buf, 0);
462+
assert!(row.contains("hello"), "plain text still renders: {row:?}");
463+
assert!(
464+
!row.contains("\x1b]8;;"),
465+
"OSC 8 wrap must be suppressed: {row:?}",
466+
);
467+
}
468+
469+
#[test]
470+
fn wrap_osc8_is_a_no_op_under_suppression() {
471+
let mut buf = Buffer::empty(Rect::new(0, 0, 20, 1));
472+
buf.set_string(0, 0, "hello", Style::default());
473+
without_osc8(|| {
474+
wrap_osc8(&mut buf, 0, 0, 5, "https://example.com", Style::default());
475+
});
476+
let row = cells_concat(&buf, 0);
477+
assert!(
478+
!row.contains("\x1b]8;;"),
479+
"wrap_osc8 must skip wrapping under suppression: {row:?}",
480+
);
481+
assert!(row.contains("hello"));
482+
}
410483
}

0 commit comments

Comments
 (0)