Skip to content

Commit ac6a0ec

Browse files
Copilotjgarzik
andcommitted
Add integration test for vi long line wrapping
Added test_pty_vi_long_line_wrapping to verify that vi correctly wraps long lines across multiple display rows instead of truncating them. Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
1 parent aec377e commit ac6a0ec

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

editors/tests/pty/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,38 @@ fn test_pty_vi_set_number() {
212212
let contents = std::fs::read_to_string(&file_path).unwrap();
213213
assert_eq!(contents, "line1\nline2\nline3\n");
214214
}
215+
216+
/// Test: Long lines should wrap to multiple display rows.
217+
/// This test verifies that vi wraps long lines for display (POSIX requirement)
218+
/// rather than truncating them.
219+
#[test]
220+
fn test_pty_vi_long_line_wrapping() {
221+
let td = tempdir().unwrap();
222+
let file_path = td.path().join("test_wrap.txt");
223+
224+
// Create a single very long line (200+ characters)
225+
let long_line = (1..=100).map(|n| n.to_string()).collect::<Vec<_>>().join("");
226+
std::fs::write(&file_path, format!("{}\n", long_line)).unwrap();
227+
228+
// Use narrow terminal (40 cols) to force wrapping
229+
let mut vi = ViPtySession::new(&file_path, 25, 40);
230+
vi.sleep_ms(500);
231+
232+
// Move cursor to the end of the line
233+
vi.keys("$");
234+
vi.sleep_ms(100);
235+
236+
// If wrapping works, we should be able to navigate without panic
237+
vi.keys("0"); // Go to start
238+
vi.sleep_ms(100);
239+
vi.keys("$"); // Go to end
240+
vi.sleep_ms(100);
241+
242+
// Quit without saving
243+
vi.keys(":q!\r");
244+
vi.wait();
245+
246+
// File should be unchanged
247+
let contents = std::fs::read_to_string(&file_path).unwrap();
248+
assert_eq!(contents, format!("{}\n", long_line));
249+
}

0 commit comments

Comments
 (0)