From f42c13da8e1674a8b06d47c6df653b8e4e2d8acc Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Fri, 4 Sep 2020 17:17:37 +0200 Subject: [PATCH] test(layout): horizontal split --- src/main.rs | 4 +- src/tests/integration.rs | 44 +++++++++++++++++++ ...ation__split_terminals_horizontally-2.snap | 24 ++++++++++ ...ation__split_terminals_horizontally-3.snap | 24 ++++++++++ ...ation__split_terminals_horizontally-4.snap | 24 ++++++++++ ...gration__split_terminals_horizontally.snap | 24 ++++++++++ ...gration__split_terminals_vertically-2.snap | 2 +- ...gration__split_terminals_vertically-3.snap | 4 +- ...gration__split_terminals_vertically-4.snap | 2 +- 9 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-2.snap create mode 100644 src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-3.snap create mode 100644 src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-4.snap create mode 100644 src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally.snap diff --git a/src/main.rs b/src/main.rs index 712becca..7356c47f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -866,7 +866,7 @@ impl Screen { if terminal.x_coords + terminal.display_cols < self.full_screen_ws.ws_col { let boundary_x_coords = terminal.x_coords + terminal.display_cols; let mut vte_output_boundaries = String::new(); - for row in terminal.y_coords..=terminal.y_coords + terminal.display_rows { + for row in terminal.y_coords..terminal.y_coords + terminal.display_rows { vte_output_boundaries.push_str(&format!("\u{1b}[{};{}H\u{1b}[m", row + 1, boundary_x_coords + 1)); // goto row/col vte_output_boundaries.push_str(&self.vertical_separator.to_string()); } @@ -875,7 +875,7 @@ impl Screen { if terminal.y_coords + terminal.display_rows < self.full_screen_ws.ws_row { let boundary_y_coords = terminal.y_coords + terminal.display_rows; let mut vte_output_boundaries = String::new(); - for col in terminal.x_coords..=terminal.x_coords + terminal.display_cols { + for col in terminal.x_coords..terminal.x_coords + terminal.display_cols { vte_output_boundaries.push_str(&format!("\u{1b}[{};{}H\u{1b}[m", boundary_y_coords + 1, col + 1)); // goto row/col vte_output_boundaries.push_str(&self.horizontal_separator.to_string()); } diff --git a/src/tests/integration.rs b/src/tests/integration.rs index 0c721c8a..828db5ed 100644 --- a/src/tests/integration.rs +++ b/src/tests/integration.rs @@ -99,3 +99,47 @@ pub fn split_terminals_vertically() { assert_snapshot!(snapshot); } } + +#[test] +pub fn split_terminals_horizontally() { + // TODO: this test is a little flaky - there's some sort of race condition that makes the + // second terminal in the split appear blank sometimes - fix this + let mut fake_input_output = get_fake_os_input(); + fake_input_output.add_terminal_input(&[8, 17]); // split-horizontally and quit (ctrl-n + ctrl-q) + start(Box::new(fake_input_output.clone())); + + let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); + let mut vte_parser = vte::Parser::new(); + let main_pid = 0; + let x = 0; + let y = 0; + let fake_win_size = Winsize { // TODO: combine with above + ws_col: 121, + ws_row: 20, + ws_xpixel: 0, + ws_ypixel: 0, + }; + let mut terminal_output = TerminalOutput::new(main_pid, fake_win_size, x, y); + + for frame in output_frames.iter() { + for byte in frame.iter() { + vte_parser.advance(&mut terminal_output, *byte); + } + let output_lines = terminal_output.read_buffer_as_lines(); + let cursor_position_in_last_line = terminal_output.cursor_position_in_last_line(); + let mut snapshot = String::new(); + for (line_index, line) in output_lines.iter().enumerate() { + for (character_index, terminal_character) in line.iter().enumerate() { + if line_index == output_lines.len() - 1 && character_index == cursor_position_in_last_line { + snapshot.push('█'); + } else { + snapshot.push(terminal_character.character); + } + } + if line_index != output_lines.len() - 1 { + snapshot.push('\n'); + } + } + assert_snapshot!(snapshot); + } +} diff --git a/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-2.snap b/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-2.snap new file mode 100644 index 00000000..f613fbd3 --- /dev/null +++ b/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-2.snap @@ -0,0 +1,24 @@ +--- +source: src/tests/integration.rs +expression: snapshot +--- + + + + + + + + +Welcome to fish, the friendly interactive shell +⋊> ~/c/mosaic on main ⨯ 10:47:03 +───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── + + + + + + + + + diff --git a/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-3.snap b/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-3.snap new file mode 100644 index 00000000..304e16a6 --- /dev/null +++ b/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-3.snap @@ -0,0 +1,24 @@ +--- +source: src/tests/integration.rs +expression: snapshot +--- + + + + + + + + +Welcome to fish, the friendly interactive shell +⋊> ~/c/mosaic on main ⨯ 10:47:03 +───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── + + + + + + + +Welcome to fish, the friendly interactive shell +⋊> ~/c/mosaic on main ⨯ █ 10:47:03 diff --git a/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-4.snap b/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-4.snap new file mode 100644 index 00000000..026ecbc3 --- /dev/null +++ b/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally-4.snap @@ -0,0 +1,24 @@ +--- +source: src/tests/integration.rs +expression: snapshot +--- + + + + + + + +Welcome to fish, the friendly interactive shell +⋊> ~/c/mosaic on main ⨯ 10:47:03 +───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── + + + + + + + +Welcome to fish, the friendly interactive shell +⋊> ~/c/mosaic on main ⨯ 10:47:03 +Bye from Mosaic! diff --git a/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally.snap b/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally.snap new file mode 100644 index 00000000..ed307b43 --- /dev/null +++ b/src/tests/snapshots/mosaic__tests__integration__split_terminals_horizontally.snap @@ -0,0 +1,24 @@ +--- +source: src/tests/integration.rs +expression: snapshot +--- + + + + + + + + + + + + + + + + + + +Welcome to fish, the friendly interactive shell +⋊> ~/c/mosaic on main ⨯ █ 10:47:03 diff --git a/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-2.snap b/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-2.snap index 19da7fce..20d74b27 100644 --- a/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-2.snap +++ b/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-2.snap @@ -17,8 +17,8 @@ expression: snapshot │ │ │ + │ Welcome to fish, the friendly interactive shell │ │ │ ⋊> ~/c/mosaic on main ⨯ │ - │ diff --git a/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-3.snap b/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-3.snap index 31437f47..a110ee36 100644 --- a/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-3.snap +++ b/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-3.snap @@ -17,8 +17,8 @@ expression: snapshot │ │ │ + │ Welcome to fish, the friendly interactive shell │ │ │Welcome to fish, the friendly interactive shell -⋊> ~/c/mosaic on main ⨯ │⋊> ~/c/mosaic on main ⨯ 19:40:00 - │ +⋊> ~/c/mosaic on main ⨯ │⋊> ~/c/mosaic on main ⨯ █ 19:40:00 diff --git a/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-4.snap b/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-4.snap index 2bdb9726..a0e55f1a 100644 --- a/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-4.snap +++ b/src/tests/snapshots/mosaic__tests__integration__split_terminals_vertically-4.snap @@ -16,9 +16,9 @@ expression: snapshot │ │ │ + │ Welcome to fish, the friendly interactive shell │ │ │Welcome to fish, the friendly interactive shell ⋊> ~/c/mosaic on main ⨯ │⋊> ~/c/mosaic on main ⨯ 19:40:00 - │ Bye from Mosaic!