refactor(tests): reduce repetition

This commit is contained in:
Aram Drevekenin 2020-09-18 17:14:29 +02:00
parent c539c49263
commit 924300c8f1
6 changed files with 140 additions and 1204 deletions

View File

@ -1,8 +1,9 @@
use ::nix::pty::Winsize; use ::nix::pty::Winsize;
use ::insta::assert_snapshot; use ::insta::assert_snapshot;
use crate::{start, TerminalOutput}; use crate::start;
use crate::tests::fakes::{FakeInputOutput}; use crate::tests::fakes::{FakeInputOutput};
use crate::tests::utils::get_output_frame_snapshots;
fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput { fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone()) FakeInputOutput::new(fake_win_size.clone())
@ -30,31 +31,8 @@ pub fn resize_down_with_pane_above() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -80,31 +58,8 @@ pub fn resize_down_with_pane_below() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -134,31 +89,8 @@ pub fn resize_down_with_panes_above_and_below() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -187,31 +119,8 @@ pub fn resize_down_with_multiple_panes_above() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }

View File

@ -1,8 +1,9 @@
use ::nix::pty::Winsize; use ::nix::pty::Winsize;
use ::insta::assert_snapshot; use ::insta::assert_snapshot;
use crate::{start, TerminalOutput}; use crate::start;
use crate::tests::fakes::{FakeInputOutput}; use crate::tests::fakes::{FakeInputOutput};
use crate::tests::utils::get_output_frame_snapshots;
fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput { fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone()) 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -75,31 +53,8 @@ pub fn resize_left_with_pane_to_the_right() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -175,31 +107,8 @@ pub fn resize_left_with_multiple_panes_to_the_left() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }

View File

@ -1,8 +1,9 @@
use ::nix::pty::Winsize; use ::nix::pty::Winsize;
use ::insta::assert_snapshot; use ::insta::assert_snapshot;
use crate::{start, TerminalOutput}; use crate::start;
use crate::tests::fakes::{FakeInputOutput}; use crate::tests::fakes::{FakeInputOutput};
use crate::tests::utils::get_output_frame_snapshots;
fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput { fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone()) 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -75,31 +53,8 @@ pub fn resize_right_with_pane_to_the_right() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -175,31 +107,8 @@ pub fn resize_right_with_multiple_panes_to_the_left() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }

View File

@ -1,8 +1,9 @@
use ::nix::pty::Winsize; use ::nix::pty::Winsize;
use ::insta::assert_snapshot; use ::insta::assert_snapshot;
use crate::{start, TerminalOutput}; use crate::start;
use crate::tests::fakes::{FakeInputOutput}; use crate::tests::fakes::{FakeInputOutput};
use crate::tests::utils::get_output_frame_snapshots;
fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput { fn get_fake_os_input (fake_win_size: &Winsize) -> FakeInputOutput {
FakeInputOutput::new(fake_win_size.clone()) FakeInputOutput::new(fake_win_size.clone())
@ -29,31 +30,8 @@ pub fn resize_up_with_pane_above() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -79,31 +57,8 @@ pub fn resize_up_with_pane_below() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -133,31 +88,8 @@ pub fn resize_up_with_panes_above_and_below() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }
@ -185,31 +117,8 @@ pub fn resize_up_with_multiple_panes_above() {
start(Box::new(fake_input_output.clone())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); 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())); start(Box::new(fake_input_output.clone()));
let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap(); let output_frames = fake_input_output.stdout_writer.output_frames.lock().unwrap();
let mut vte_parser = vte::Parser::new(); let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
let main_pid = 0; for snapshot in snapshots {
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');
}
}
assert_snapshot!(snapshot); assert_snapshot!(snapshot);
} }
} }

View File

@ -2,3 +2,4 @@ pub mod integration;
pub mod possible_inputs; pub mod possible_inputs;
pub mod tty_inputs; pub mod tty_inputs;
pub mod fakes; pub mod fakes;
pub mod utils;

35
src/tests/utils.rs Normal file
View File

@ -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
}