From c9ff13a01fc9638ccabdd3cb0dd270aa716d0e0b Mon Sep 17 00:00:00 2001 From: YizhePKU Date: Mon, 21 Oct 2024 15:13:00 +0800 Subject: [PATCH] Fix broken tests caused by path seperator differences --- tests/basic.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/basic.rs b/tests/basic.rs index f46b43f7..94302662 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -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(()) } @@ -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(()) } @@ -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(()) } @@ -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")?; @@ -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 @@ -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(()) @@ -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(()) } @@ -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(()) }