Skip to content

Commit

Permalink
Fix broken tests caused by path seperator differences
Browse files Browse the repository at this point in the history
  • Loading branch information
YizhePKU committed Oct 21, 2024
1 parent af0d4e6 commit c9ff13a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ fn prints_prompt() -> std::io::Result<()> {
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;

let text = extract_text(terminal.inner());
#[cfg(not(windows))]
assert_eq!(&text[0][..13], "~/reedline〉");
#[cfg(windows)]
assert_eq!(&text[0][..13], "~\\reedline〉");

Ok(())
}
Expand All @@ -27,7 +30,6 @@ fn echos_input() -> std::io::Result<()> {

assert_eq!(&text[0][13..25], "Hello World!");
assert_eq!(&text[1][0..26], "We processed: Hello World!");
assert_eq!(&text[2][0..13], "~/reedline〉");

Ok(())
}
Expand All @@ -47,7 +49,6 @@ fn backspace() -> std::io::Result<()> {
let text = extract_text(terminal.inner());
assert_eq!(&text[0][13..25], "Hello Bread!");
assert_eq!(&text[1][0..26], "We processed: Hello Bread!");
assert_eq!(&text[2][0..13], "~/reedline〉");

Ok(())
}
Expand All @@ -68,7 +69,7 @@ fn history() -> std::io::Result<()> {
pty.writer().write_all(b"\x1b[A")?;
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;
let text = extract_text(terminal.inner());
assert_eq!(&text[4][..21], "~/reedline〉Goodbye!");
assert_eq!(&text[4][13..21], "Goodbye!");

// press Enter to execute it
pty.writer().write_all(b"\r")?;
Expand All @@ -80,19 +81,19 @@ fn history() -> std::io::Result<()> {
pty.writer().write_all(b"\x1b[A\x1b[A")?;
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;
let text = extract_text(terminal.inner());
assert_eq!(&text[6][..25], "~/reedline〉Hello World!");
assert_eq!(&text[6][13..25], "Hello World!");

// arrow down twice
pty.writer().write_all(b"\x1b[B\x1b[B")?;
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;
let text = extract_text(terminal.inner());
assert_eq!(&text[6][..25], "~/reedline〉 ");
assert_eq!(&text[6][13..25], " ");

// type "Hel" then arrow up
pty.writer().write_all(b"Hel\x1b[A")?;
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;
let text = extract_text(terminal.inner());
assert_eq!(&text[6][..25], "~/reedline〉Hello World!");
assert_eq!(&text[6][13..25], "Hello World!");

// TODO: not sure how reverse search works in Reedline

Expand All @@ -119,7 +120,7 @@ fn word_movement() -> std::io::Result<()> {
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;

let text = extract_text(terminal.inner());
assert_eq!(&text[0][..26], "~/reedline〉foo bazar baz");
assert_eq!(&text[0][13..26], "foo bazar baz");
assert_eq!(&text[1][..27], "We processed: foo bazar baz");

Ok(())
Expand All @@ -139,7 +140,7 @@ fn clear_screen() -> std::io::Result<()> {
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;

let text = extract_text(terminal.inner());
assert_eq!(&text[0][..25], "~/reedline〉Hello again!");
assert_eq!(&text[0][13..25], "Hello again!");

Ok(())
}
Expand All @@ -157,25 +158,25 @@ fn emacs_keybinds() -> std::io::Result<()> {
pty.writer().write_all(b"\x1a")?;
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;
let text = extract_text(terminal.inner());
assert_eq!(&text[0][..25], "~/reedline〉Hello ");
assert_eq!(&text[0][13..25], "Hello ");

// redo with Ctrl-g
pty.writer().write_all(b"\x07")?;
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;
let text = extract_text(terminal.inner());
assert_eq!(&text[0][..25], "~/reedline〉Hello World!");
assert_eq!(&text[0][13..25], "Hello World!");

// delete "World" with alt+left, alt+backspace
pty.writer().write_all(b"\x1b[1;3D\x1b\x7f")?;
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;
let text = extract_text(terminal.inner());
assert_eq!(&text[0][..25], "~/reedline〉Hello ! ");
assert_eq!(&text[0][13..25], "Hello ! ");

// make "Hello" ALL CAPS with alt+b, alt+u
pty.writer().write_all(b"\x1bb\x1bu")?;
terminal.read_from_pty(&mut pty, Some(Duration::from_millis(50)))?;
let text = extract_text(terminal.inner());
assert_eq!(&text[0][..25], "~/reedline〉HELLO ! ");
assert_eq!(&text[0][13..25], "HELLO ! ");

Ok(())
}

0 comments on commit c9ff13a

Please sign in to comment.