diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-25 04:16:00 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-25 04:16:44 +0300 |
| commit | ddb3e04f92ebc924dd8355df6510781caf498a02 (patch) | |
| tree | da79533c2375bd76417b8237f5daf0dc78cd0511 /src/pane | |
| parent | fba05502cdf235eedc057c3857fdc95e8fbd781d (diff) | |
test: add libghostty upgrade contract coverage
Diffstat (limited to 'src/pane')
| -rw-r--r-- | src/pane/terminal.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pane/terminal.rs b/src/pane/terminal.rs index c688dcc9..c8f29b4c 100644 --- a/src/pane/terminal.rs +++ b/src/pane/terminal.rs @@ -972,6 +972,13 @@ mod tests { } } + fn write_wrapped_contract_lines(terminal: &mut crate::ghostty::Terminal, count: usize) { + for i in 0..count { + terminal.write(format!("WRAP-{i:03}-abcdefghijklmnopqrstuvwxyz\r\n").as_bytes()); + } + terminal.write(b"END"); + } + #[test] fn host_terminal_theme_restore_probe_skips_when_no_transient_override() { let (tx, _rx) = mpsc::channel(4); @@ -1363,6 +1370,36 @@ mod tests { } #[test] + fn resize_reflow_keeps_scrolled_viewport_and_bottom_detection_sane() { + let (tx, _rx) = mpsc::channel(4); + let mut terminal = crate::ghostty::Terminal::new(12, 4, 10_000).unwrap(); + write_wrapped_contract_lines(&mut terminal, 40); + let pane = GhosttyPaneTerminal::new(terminal, tx).unwrap(); + + let bottom_snapshot = pane.detection_text(); + assert!(bottom_snapshot.contains("END")); + + let initial = pane.scroll_metrics().expect("initial scroll metrics"); + assert!(initial.max_offset_from_bottom > 0); + pane.set_scroll_offset_from_bottom(initial.max_offset_from_bottom / 2); + assert!(!pane.visible_text().trim().is_empty()); + + for (rows, cols) in [(4, 10), (4, 7), (6, 18), (3, 9), (5, 12)] { + pane.resize(rows, cols); + + let metrics = pane.scroll_metrics().expect("scroll metrics after resize"); + assert_eq!(metrics.viewport_rows, rows as usize); + assert!(metrics.offset_from_bottom <= metrics.max_offset_from_bottom); + assert!(metrics.max_offset_from_bottom > 0); + assert!(!pane.visible_text().trim().is_empty()); + assert!( + pane.detection_text().contains("END"), + "bottom detection should remain independent from the scrolled viewport after resize" + ); + } + } + + #[test] fn synchronized_output_suppresses_intermediate_render_requests_until_batch_ends() { let (tx, _rx) = mpsc::channel(4); let terminal = crate::ghostty::Terminal::new(80, 24, 0).unwrap(); |
