From 3088cbea6895dede6611d6e2fe27b45421e173fa Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 12 Dec 2023 15:29:17 -0700 Subject: [PATCH] Uncomment vim search tests --- crates/vim2/src/normal/search.rs | 260 +++++++++++++++---------------- 1 file changed, 130 insertions(+), 130 deletions(-) diff --git a/crates/vim2/src/normal/search.rs b/crates/vim2/src/normal/search.rs index 3873c5b78b646aca83dfd825a9fec760d5f2ea7f..7b5f4d3e59a3362c807922ae12ffaba98fdfd8eb 100644 --- a/crates/vim2/src/normal/search.rs +++ b/crates/vim2/src/normal/search.rs @@ -345,133 +345,133 @@ fn parse_replace_all(query: &str) -> Replacement { replacement } -// #[cfg(test)] -// mod test { -// use editor::DisplayPoint; -// use search::BufferSearchBar; - -// use crate::{state::Mode, test::VimTestContext}; - -// #[gpui::test] -// async fn test_move_to_next(cx: &mut gpui::TestAppContext) { -// let mut cx = VimTestContext::new(cx, true).await; -// cx.set_state("ˇhi\nhigh\nhi\n", Mode::Normal); - -// cx.simulate_keystrokes(["*"]); -// cx.run_until_parked(); -// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); - -// cx.simulate_keystrokes(["*"]); -// cx.run_until_parked(); -// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); - -// cx.simulate_keystrokes(["#"]); -// cx.run_until_parked(); -// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); - -// cx.simulate_keystrokes(["#"]); -// cx.run_until_parked(); -// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); - -// cx.simulate_keystrokes(["2", "*"]); -// cx.run_until_parked(); -// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); - -// cx.simulate_keystrokes(["g", "*"]); -// cx.run_until_parked(); -// cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); - -// cx.simulate_keystrokes(["n"]); -// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); - -// cx.simulate_keystrokes(["g", "#"]); -// cx.run_until_parked(); -// cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); -// } - -// #[gpui::test] -// async fn test_search(cx: &mut gpui::TestAppContext) { -// let mut cx = VimTestContext::new(cx, true).await; - -// cx.set_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); -// cx.simulate_keystrokes(["/", "c", "c"]); - -// let search_bar = cx.workspace(|workspace, cx| { -// workspace -// .active_pane() -// .read(cx) -// .toolbar() -// .read(cx) -// .item_of_type::() -// .expect("Buffer search bar should be deployed") -// }); - -// cx.update_view(search_bar, |bar, cx| { -// assert_eq!(bar.query(cx), "cc"); -// }); - -// cx.run_until_parked(); - -// cx.update_editor(|editor, cx| { -// let highlights = editor.all_text_background_highlights(cx); -// assert_eq!(3, highlights.len()); -// assert_eq!( -// DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2), -// highlights[0].0 -// ) -// }); - -// cx.simulate_keystrokes(["enter"]); -// cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); - -// // n to go to next/N to go to previous -// cx.simulate_keystrokes(["n"]); -// cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); -// cx.simulate_keystrokes(["shift-n"]); -// cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); - -// // ? to go to previous -// cx.simulate_keystrokes(["?", "enter"]); -// cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); -// cx.simulate_keystrokes(["?", "enter"]); -// cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); - -// // / to go to next -// cx.simulate_keystrokes(["/", "enter"]); -// cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); - -// // ?{search} to search backwards -// cx.simulate_keystrokes(["?", "b", "enter"]); -// cx.assert_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); - -// // works with counts -// cx.simulate_keystrokes(["4", "/", "c"]); -// cx.simulate_keystrokes(["enter"]); -// cx.assert_state("aa\nbb\ncc\ncˇc\ncc\n", Mode::Normal); - -// // check that searching resumes from cursor, not previous match -// cx.set_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); -// cx.simulate_keystrokes(["/", "d"]); -// cx.simulate_keystrokes(["enter"]); -// cx.assert_state("aa\nbb\nˇdd\ncc\nbb\n", Mode::Normal); -// cx.update_editor(|editor, cx| editor.move_to_beginning(&Default::default(), cx)); -// cx.assert_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); -// cx.simulate_keystrokes(["/", "b"]); -// cx.simulate_keystrokes(["enter"]); -// cx.assert_state("aa\nˇbb\ndd\ncc\nbb\n", Mode::Normal); -// } - -// #[gpui::test] -// async fn test_non_vim_search(cx: &mut gpui::TestAppContext) { -// let mut cx = VimTestContext::new(cx, false).await; -// cx.set_state("ˇone one one one", Mode::Normal); -// cx.simulate_keystrokes(["cmd-f"]); -// cx.run_until_parked(); - -// cx.assert_editor_state("«oneˇ» one one one"); -// cx.simulate_keystrokes(["enter"]); -// cx.assert_editor_state("one «oneˇ» one one"); -// cx.simulate_keystrokes(["shift-enter"]); -// cx.assert_editor_state("«oneˇ» one one one"); -// } -// } +#[cfg(test)] +mod test { + use editor::DisplayPoint; + use search::BufferSearchBar; + + use crate::{state::Mode, test::VimTestContext}; + + #[gpui::test] + async fn test_move_to_next(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + cx.set_state("ˇhi\nhigh\nhi\n", Mode::Normal); + + cx.simulate_keystrokes(["*"]); + cx.run_until_parked(); + cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); + + cx.simulate_keystrokes(["*"]); + cx.run_until_parked(); + cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); + + cx.simulate_keystrokes(["#"]); + cx.run_until_parked(); + cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); + + cx.simulate_keystrokes(["#"]); + cx.run_until_parked(); + cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); + + cx.simulate_keystrokes(["2", "*"]); + cx.run_until_parked(); + cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); + + cx.simulate_keystrokes(["g", "*"]); + cx.run_until_parked(); + cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); + + cx.simulate_keystrokes(["n"]); + cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); + + cx.simulate_keystrokes(["g", "#"]); + cx.run_until_parked(); + cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); + } + + #[gpui::test] + async fn test_search(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + + cx.set_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); + cx.simulate_keystrokes(["/", "c", "c"]); + + let search_bar = cx.workspace(|workspace, cx| { + workspace + .active_pane() + .read(cx) + .toolbar() + .read(cx) + .item_of_type::() + .expect("Buffer search bar should be deployed") + }); + + cx.update_view(search_bar, |bar, cx| { + assert_eq!(bar.query(cx), "cc"); + }); + + cx.run_until_parked(); + + cx.update_editor(|editor, cx| { + let highlights = editor.all_text_background_highlights(cx); + assert_eq!(3, highlights.len()); + assert_eq!( + DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2), + highlights[0].0 + ) + }); + + cx.simulate_keystrokes(["enter"]); + cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); + + // n to go to next/N to go to previous + cx.simulate_keystrokes(["n"]); + cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); + cx.simulate_keystrokes(["shift-n"]); + cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); + + // ? to go to previous + cx.simulate_keystrokes(["?", "enter"]); + cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); + cx.simulate_keystrokes(["?", "enter"]); + cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); + + // / to go to next + cx.simulate_keystrokes(["/", "enter"]); + cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); + + // ?{search} to search backwards + cx.simulate_keystrokes(["?", "b", "enter"]); + cx.assert_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); + + // works with counts + cx.simulate_keystrokes(["4", "/", "c"]); + cx.simulate_keystrokes(["enter"]); + cx.assert_state("aa\nbb\ncc\ncˇc\ncc\n", Mode::Normal); + + // check that searching resumes from cursor, not previous match + cx.set_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); + cx.simulate_keystrokes(["/", "d"]); + cx.simulate_keystrokes(["enter"]); + cx.assert_state("aa\nbb\nˇdd\ncc\nbb\n", Mode::Normal); + cx.update_editor(|editor, cx| editor.move_to_beginning(&Default::default(), cx)); + cx.assert_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); + cx.simulate_keystrokes(["/", "b"]); + cx.simulate_keystrokes(["enter"]); + cx.assert_state("aa\nˇbb\ndd\ncc\nbb\n", Mode::Normal); + } + + #[gpui::test] + async fn test_non_vim_search(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, false).await; + cx.set_state("ˇone one one one", Mode::Normal); + cx.simulate_keystrokes(["cmd-f"]); + cx.run_until_parked(); + + cx.assert_editor_state("«oneˇ» one one one"); + cx.simulate_keystrokes(["enter"]); + cx.assert_editor_state("one «oneˇ» one one"); + cx.simulate_keystrokes(["shift-enter"]); + cx.assert_editor_state("«oneˇ» one one one"); + } +}