aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2020-09-18 17:14:29 +0200
committerAram Drevekenin <aram@poor.dev>2020-09-18 17:14:29 +0200
commit924300c8f1ac806f16597ea519805aed4f99cc35 (patch)
tree8a3c5bbb0862b0f68f14f5eeaa1d3cca791b0d9c /src
parentrefactor(screen): clean up and remove duplications (diff)
downloadsl0ppij-924300c8f1ac806f16597ea519805aed4f99cc35.tar.gz
sl0ppij-924300c8f1ac806f16597ea519805aed4f99cc35.tar.xz
sl0ppij-924300c8f1ac806f16597ea519805aed4f99cc35.zip
refactor(tests): reduce repetition
Diffstat (limited to 'src')
-rw-r--r--src/tests/integration/resize_down.rs327
-rw-r--r--src/tests/integration/resize_left.rs327
-rw-r--r--src/tests/integration/resize_right.rs327
-rw-r--r--src/tests/integration/resize_up.rs327
-rw-r--r--src/tests/mod.rs1
-rw-r--r--src/tests/utils.rs35
6 files changed, 140 insertions, 1204 deletions
diff --git a/src/tests/integration/resize_down.rs b/src/tests/integration/resize_down.rs
index 20fc3955..e2c2ac5d 100644
--- a/src/tests/integration/resize_down.rs
+++ b/src/tests/integration/resize_down.rs
@@ -1,8 +1,9 @@
use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
-use crate::{start, TerminalOutput};
+use crate::start;
use crate::tests::fakes::{FakeInputOutput};
+use crate::tests::utils::get_output_frame_snapshots;
fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
@@ -30,31 +31,8 @@ pub fn resize_down_with_pane_above() {
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 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');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -80,31 +58,8 @@ pub fn resize_down_with_pane_below() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -134,31 +89,8 @@ pub fn resize_down_with_panes_above_and_below() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -187,31 +119,8 @@ pub fn resize_down_with_multiple_panes_above() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -240,31 +149,8 @@ pub fn resize_down_with_panes_above_aligned_left_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -293,31 +179,8 @@ pub fn resize_down_with_panes_below_aligned_left_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -346,31 +209,8 @@ pub fn resize_down_with_panes_above_aligned_right_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -400,31 +240,8 @@ pub fn resize_down_with_panes_below_aligned_right_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -453,31 +270,8 @@ pub fn resize_down_with_panes_above_aligned_left_and_right_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -506,31 +300,8 @@ pub fn resize_down_with_panes_below_aligned_left_and_right_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -560,31 +331,8 @@ pub fn resize_down_with_panes_above_aligned_left_and_right_with_panes_to_the_lef
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -615,31 +363,8 @@ pub fn resize_down_with_panes_below_aligned_left_and_right_with_to_the_left_and_
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
diff --git a/src/tests/integration/resize_left.rs b/src/tests/integration/resize_left.rs
index 7a8c747a..bff82e3e 100644
--- a/src/tests/integration/resize_left.rs
+++ b/src/tests/integration/resize_left.rs
@@ -1,8 +1,9 @@
use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
-use crate::{start, TerminalOutput};
+use crate::start;
use crate::tests::fakes::{FakeInputOutput};
+use crate::tests::utils::get_output_frame_snapshots;
fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
@@ -27,31 +28,8 @@ pub fn resize_left_with_pane_to_the_left() {
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 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');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -75,31 +53,8 @@ pub fn resize_left_with_pane_to_the_right() {
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 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');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -124,31 +79,8 @@ pub fn resize_left_with_panes_to_the_left_and_right() {
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 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');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -175,31 +107,8 @@ pub fn resize_left_with_multiple_panes_to_the_left() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -226,31 +135,8 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -277,31 +163,8 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -328,31 +191,8 @@ pub fn resize_left_with_panes_to_the_left_aligned_bottom_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -380,31 +220,8 @@ pub fn resize_left_with_panes_to_the_right_aligned_bottom_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -433,31 +250,8 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_and_bottom_with_current_pa
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -486,31 +280,8 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_and_bottom_with_current_p
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -540,31 +311,8 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_and_bottom_with_panes_abov
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -595,31 +343,8 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_and_bottom_with_panes_abo
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
diff --git a/src/tests/integration/resize_right.rs b/src/tests/integration/resize_right.rs
index 6643a98a..a8dbf5b3 100644
--- a/src/tests/integration/resize_right.rs
+++ b/src/tests/integration/resize_right.rs
@@ -1,8 +1,9 @@
use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
-use crate::{start, TerminalOutput};
+use crate::start;
use crate::tests::fakes::{FakeInputOutput};
+use crate::tests::utils::get_output_frame_snapshots;
fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
@@ -27,31 +28,8 @@ pub fn resize_right_with_pane_to_the_left() {
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 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');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -75,31 +53,8 @@ pub fn resize_right_with_pane_to_the_right() {
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 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');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -124,31 +79,8 @@ pub fn resize_right_with_panes_to_the_left_and_right() {
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 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');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -175,31 +107,8 @@ pub fn resize_right_with_multiple_panes_to_the_left() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -226,31 +135,8 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -277,31 +163,8 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -328,31 +191,8 @@ pub fn resize_right_with_panes_to_the_left_aligned_bottom_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -380,31 +220,8 @@ pub fn resize_right_with_panes_to_the_right_aligned_bottom_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -433,31 +250,8 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_and_bottom_with_current_p
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -486,31 +280,8 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_and_bottom_with_current_
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -540,31 +311,8 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_and_bottom_with_panes_abo
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -595,31 +343,8 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_and_bottom_with_panes_ab
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
diff --git a/src/tests/integration/resize_up.rs b/src/tests/integration/resize_up.rs
index 05bfa98b..35bca0b5 100644
--- a/src/tests/integration/resize_up.rs
+++ b/src/tests/integration/resize_up.rs
@@ -1,8 +1,9 @@
use ::nix::pty::Winsize;
use ::insta::assert_snapshot;
-use crate::{start, TerminalOutput};
+use crate::start;
use crate::tests::fakes::{FakeInputOutput};
+use crate::tests::utils::get_output_frame_snapshots;
fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone())
@@ -29,31 +30,8 @@ pub fn resize_up_with_pane_above() {
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 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');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -79,31 +57,8 @@ pub fn resize_up_with_pane_below() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -133,31 +88,8 @@ pub fn resize_up_with_panes_above_and_below() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -185,31 +117,8 @@ pub fn resize_up_with_multiple_panes_above() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -236,31 +145,8 @@ pub fn resize_up_with_panes_above_aligned_left_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -289,31 +175,8 @@ pub fn resize_up_with_panes_below_aligned_left_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -342,31 +205,8 @@ pub fn resize_up_with_panes_above_aligned_right_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -396,31 +236,8 @@ pub fn resize_up_with_panes_below_aligned_right_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -449,31 +266,8 @@ pub fn resize_up_with_panes_above_aligned_left_and_right_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -502,31 +296,8 @@ pub fn resize_up_with_panes_below_aligned_left_and_right_with_current_pane() {
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -556,31 +327,8 @@ pub fn resize_up_with_panes_above_aligned_left_and_right_with_panes_to_the_left_
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
@@ -611,31 +359,8 @@ pub fn resize_up_with_panes_below_aligned_left_and_right_with_to_the_left_and_ri
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 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_x, cursor_y) = terminal_output.cursor_coordinates();
- 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 == cursor_y - 1 && character_index == cursor_x {
- snapshot.push('█');
- } else {
- snapshot.push(terminal_character.character);
- }
- }
- if line_index != output_lines.len() - 1 {
- snapshot.push('\n');
- }
- }
+ let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
+ for snapshot in snapshots {
assert_snapshot!(snapshot);
}
}
diff --git a/src/tests/mod.rs b/src/tests/mod.rs
index 4be5f54f..e27bc749 100644
--- a/src/tests/mod.rs
+++ b/src/tests/mod.rs
@@ -2,3 +2,4 @@ pub mod integration;
pub mod possible_inputs;
pub mod tty_inputs;
pub mod fakes;
+pub mod utils;
diff --git a/src/tests/utils.rs b/src/tests/utils.rs
new file mode 100644
index 00000000..a27717f9
--- /dev/null
+++ b/src/tests/utils.rs
@@ -0,0 +1,35 @@
+use ::nix::pty::Winsize;
+use crate::TerminalOutput;
+
+pub fn get_output_frame_snapshots(output_frames: &[Vec<u8>], win_size: &Winsize) -> Vec<String> {
+ let mut vte_parser = vte::Parser::new();
+ let main_pid = 0;
+ let x = 0;
+ let y = 0;
+ let mut terminal_output = TerminalOutput::new(main_pid, *win_size, x, y);
+
+ let mut snapshots = vec![];
+ 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_x, cursor_y) = terminal_output.cursor_coordinates();
+ 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 == cursor_y - 1 && character_index == cursor_x {
+ snapshot.push('█');
+ } else {
+ snapshot.push(terminal_character.character);
+ }
+ }
+ if line_index != output_lines.len() - 1 {
+ snapshot.push('\n');
+ }
+ }
+ snapshots.push(snapshot);
+ }
+ snapshots
+}
+