Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce redundant escape codes #99

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
# CRLF and LF).

README.md text eol=lf

# This is raw output from the program, don't do any conversions on it
tests/expected-output-basic.txt -text
35 changes: 35 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,39 @@ fn first_run_prompt_accept() -> Result<(), RexpectError> {

Ok(())
}

#[test]
fn minimum_escape_codes() -> Result<(), RexpectError> {
// The app should ouptut the minimum amount of escape codes, and not any redundant ones

let mut cmd = get_cmd_no_first_run_prompt();
let tmp = tempdir().expect("error creating temporary folder");

// create some folders
for folder_name in vec!["foo", "bar"] {
let p = tmp.path().join(folder_name);
std::fs::create_dir(p).unwrap();
}

cmd.current_dir(tmp.path())
// note: have to set PWD for this to work...
.env("PWD", tmp.path().as_os_str());

let mut proc = run_app_with_cmd(cmd);
// 0x1b == 0o33 == 27 escape
proc.send("\x1b")?;
proc.writer.flush()?;

let output = proc.exp_eof()?;
let expected_output = include_str!("expected-output-basic.txt");

let tmp_path_str = format!("{}", tmp.path().display());
// The path of the temporary folder will vary, but everything else should be the same as in the
// example output
assert_eq!(
output.replace(&tmp_path_str, "/tmp/xxxxxxxxxx"),
expected_output,
);
Ok(())
}
}
1 change: 1 addition & 0 deletions tests/expected-output-basic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[?25l/tmp/xxxxxxxxxx/tmp/xxxxxxxxxxtere 1.5.1 - Type something to search, press '?' to view help or Esc to exit.gap search from start - smart case - sort:name - 2 / 3search: ..bar foo[?25h[?1049l/tmp/xxxxxxxxxx