Skip to content

Commit

Permalink
fix: correct behavior for \n stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Apr 15, 2024
1 parent b4035a4 commit 5c60870
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn process_in_stream(in_stream: impl Read) -> Result<bool, Error> {

match char_result {
Some('y') | Some('Y') => Ok(true),
Some('n') | Some('N') | None => Ok(false),
Some('n') | Some('N') | Some('\n') | None => Ok(false),
Some('q') | Some('Q') => Err(Error::new(
io::ErrorKind::Interrupted,
"User requested to quit",
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ fn test_filetypes(
}

#[rstest]
fn test_prompt_read(#[values("y", "Y", "n", "N", "q", "Q", "k")] key: &str) {
fn test_prompt_read(#[values("y", "Y", "n", "N", "", "\n", "q", "Q", "k")] key: &str) {
let input = Cursor::new(key);
let result = rip2::util::process_in_stream(input);
match key {
"y" | "Y" => assert!(result.unwrap()),
"n" | "N" | "" => assert!(!result.unwrap()),
"n" | "N" | "" | "\n" => assert!(!result.unwrap()),
"q" | "Q" => {
let err = result.unwrap_err();
assert_eq!(err.kind(), ErrorKind::Interrupted);
Expand Down

0 comments on commit 5c60870

Please sign in to comment.