Most tests now...

This commit is contained in:
Conrad Irwin 2023-12-11 15:25:30 -07:00
parent e37173fe97
commit 2d59492aac
3 changed files with 298 additions and 341 deletions

View file

@ -196,328 +196,301 @@ pub(crate) fn repeat(cx: &mut WindowContext, from_insert_mode: bool) {
.detach_and_log_err(cx); .detach_and_log_err(cx);
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use std::sync::Arc; use editor::test::editor_lsp_test_context::EditorLspTestContext;
use futures::StreamExt;
use indoc::indoc;
// use editor::test::editor_lsp_test_context::EditorLspTestContext; use gpui::InputHandler;
// use futures::StreamExt;
// use indoc::indoc;
// use gpui::{executor::Deterministic, View}; use crate::{
state::Mode,
test::{NeovimBackedTestContext, VimTestContext},
};
// use crate::{ #[gpui::test]
// state::Mode, async fn test_dot_repeat(cx: &mut gpui::TestAppContext) {
// test::{NeovimBackedTestContext, VimTestContext}, let mut cx = NeovimBackedTestContext::new(cx).await;
// };
// #[gpui::test] // "o"
// async fn test_dot_repeat(deterministic: Arc<Deterministic>, cx: &mut gpui::TestAppContext) { cx.set_shared_state("ˇhello").await;
// let mut cx = NeovimBackedTestContext::new(cx).await; cx.simulate_shared_keystrokes(["o", "w", "o", "r", "l", "d", "escape"])
.await;
cx.assert_shared_state("hello\nworlˇd").await;
cx.simulate_shared_keystrokes(["."]).await;
cx.assert_shared_state("hello\nworld\nworlˇd").await;
// // "o" // "d"
// cx.set_shared_state("ˇhello").await; cx.simulate_shared_keystrokes(["^", "d", "f", "o"]).await;
// cx.simulate_shared_keystrokes(["o", "w", "o", "r", "l", "d", "escape"]) cx.simulate_shared_keystrokes(["g", "g", "."]).await;
// .await; cx.assert_shared_state("ˇ\nworld\nrld").await;
// cx.assert_shared_state("hello\nworlˇd").await;
// cx.simulate_shared_keystrokes(["."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state("hello\nworld\nworlˇd").await;
// // "d" // "p" (note that it pastes the current clipboard)
// cx.simulate_shared_keystrokes(["^", "d", "f", "o"]).await; cx.simulate_shared_keystrokes(["j", "y", "y", "p"]).await;
// cx.simulate_shared_keystrokes(["g", "g", "."]).await; cx.simulate_shared_keystrokes(["shift-g", "y", "y", "."])
// deterministic.run_until_parked(); .await;
// cx.assert_shared_state("ˇ\nworld\nrld").await; cx.assert_shared_state("\nworld\nworld\nrld\nˇrld").await;
// // "p" (note that it pastes the current clipboard) // "~" (note that counts apply to the action taken, not . itself)
// cx.simulate_shared_keystrokes(["j", "y", "y", "p"]).await; cx.set_shared_state("ˇthe quick brown fox").await;
// cx.simulate_shared_keystrokes(["shift-g", "y", "y", "."]) cx.simulate_shared_keystrokes(["2", "~", "."]).await;
// .await; cx.set_shared_state("THE ˇquick brown fox").await;
// deterministic.run_until_parked(); cx.simulate_shared_keystrokes(["3", "."]).await;
// cx.assert_shared_state("\nworld\nworld\nrld\nˇrld").await; cx.set_shared_state("THE QUIˇck brown fox").await;
cx.run_until_parked();
cx.simulate_shared_keystrokes(["."]).await;
cx.assert_shared_state("THE QUICK ˇbrown fox").await;
}
// // "~" (note that counts apply to the action taken, not . itself) #[gpui::test]
// cx.set_shared_state("ˇthe quick brown fox").await; async fn test_repeat_ime(cx: &mut gpui::TestAppContext) {
// cx.simulate_shared_keystrokes(["2", "~", "."]).await; let mut cx = VimTestContext::new(cx, true).await;
// deterministic.run_until_parked();
// cx.set_shared_state("THE ˇquick brown fox").await;
// cx.simulate_shared_keystrokes(["3", "."]).await;
// deterministic.run_until_parked();
// cx.set_shared_state("THE QUIˇck brown fox").await;
// deterministic.run_until_parked();
// cx.simulate_shared_keystrokes(["."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state("THE QUICK ˇbrown fox").await;
// }
// #[gpui::test] cx.set_state("hˇllo", Mode::Normal);
// async fn test_repeat_ime(deterministic: Arc<Deterministic>, cx: &mut gpui::TestAppContext) { cx.simulate_keystrokes(["i"]);
// let mut cx = VimTestContext::new(cx, true).await;
// cx.set_state("hˇllo", Mode::Normal); // simulate brazilian input for ä.
// cx.simulate_keystrokes(["i"]); cx.update_editor(|editor, cx| {
editor.replace_and_mark_text_in_range(None, "\"", Some(1..1), cx);
editor.replace_text_in_range(None, "ä", cx);
});
cx.simulate_keystrokes(["escape"]);
cx.assert_state("hˇällo", Mode::Normal);
cx.simulate_keystrokes(["."]);
cx.assert_state("hˇäällo", Mode::Normal);
}
// // simulate brazilian input for ä. #[gpui::test]
// cx.update_editor(|editor, cx| { async fn test_repeat_completion(cx: &mut gpui::TestAppContext) {
// editor.replace_and_mark_text_in_range(None, "\"", Some(1..1), cx); VimTestContext::init(cx);
// editor.replace_text_in_range(None, "ä", cx); let cx = EditorLspTestContext::new_rust(
// }); lsp::ServerCapabilities {
// cx.simulate_keystrokes(["escape"]); completion_provider: Some(lsp::CompletionOptions {
// cx.assert_state("hˇällo", Mode::Normal); trigger_characters: Some(vec![".".to_string(), ":".to_string()]),
// cx.simulate_keystrokes(["."]); resolve_provider: Some(true),
// deterministic.run_until_parked(); ..Default::default()
// cx.assert_state("hˇäällo", Mode::Normal); }),
// } ..Default::default()
},
cx,
)
.await;
let mut cx = VimTestContext::new_with_lsp(cx, true);
// #[gpui::test] cx.set_state(
// async fn test_repeat_completion( indoc! {"
// deterministic: Arc<Deterministic>, onˇe
// cx: &mut gpui::TestAppContext, two
// ) { three
// let cx = EditorLspTestContext::new_rust( "},
// lsp::ServerCapabilities { Mode::Normal,
// completion_provider: Some(lsp::CompletionOptions { );
// trigger_characters: Some(vec![".".to_string(), ":".to_string()]),
// resolve_provider: Some(true),
// ..Default::default()
// }),
// ..Default::default()
// },
// cx,
// )
// .await;
// let mut cx = VimTestContext::new_with_lsp(cx, true);
// cx.set_state( let mut request =
// indoc! {" cx.handle_request::<lsp::request::Completion, _, _>(move |_, params, _| async move {
// onˇe let position = params.text_document_position.position;
// two Ok(Some(lsp::CompletionResponse::Array(vec![
// three lsp::CompletionItem {
// "}, label: "first".to_string(),
// Mode::Normal, text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
// ); range: lsp::Range::new(position.clone(), position.clone()),
new_text: "first".to_string(),
})),
..Default::default()
},
lsp::CompletionItem {
label: "second".to_string(),
text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
range: lsp::Range::new(position.clone(), position.clone()),
new_text: "second".to_string(),
})),
..Default::default()
},
])))
});
cx.simulate_keystrokes(["a", "."]);
request.next().await;
cx.condition(|editor, _| editor.context_menu_visible())
.await;
cx.simulate_keystrokes(["down", "enter", "!", "escape"]);
// let mut request = cx.assert_state(
// cx.handle_request::<lsp::request::Completion, _, _>(move |_, params, _| async move { indoc! {"
// let position = params.text_document_position.position; one.secondˇ!
// Ok(Some(lsp::CompletionResponse::Array(vec![ two
// lsp::CompletionItem { three
// label: "first".to_string(), "},
// text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit { Mode::Normal,
// range: lsp::Range::new(position.clone(), position.clone()), );
// new_text: "first".to_string(), cx.simulate_keystrokes(["j", "."]);
// })), cx.assert_state(
// ..Default::default() indoc! {"
// }, one.second!
// lsp::CompletionItem { two.secondˇ!
// label: "second".to_string(), three
// text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit { "},
// range: lsp::Range::new(position.clone(), position.clone()), Mode::Normal,
// new_text: "second".to_string(), );
// })), }
// ..Default::default()
// },
// ])))
// });
// cx.simulate_keystrokes(["a", "."]);
// request.next().await;
// cx.condition(|editor, _| editor.context_menu_visible())
// .await;
// cx.simulate_keystrokes(["down", "enter", "!", "escape"]);
// cx.assert_state( #[gpui::test]
// indoc! {" async fn test_repeat_visual(cx: &mut gpui::TestAppContext) {
// one.secondˇ! let mut cx = NeovimBackedTestContext::new(cx).await;
// two
// three
// "},
// Mode::Normal,
// );
// cx.simulate_keystrokes(["j", "."]);
// deterministic.run_until_parked();
// cx.assert_state(
// indoc! {"
// one.second!
// two.secondˇ!
// three
// "},
// Mode::Normal,
// );
// }
// #[gpui::test] // single-line (3 columns)
// async fn test_repeat_visual(deterministic: Arc<Deterministic>, cx: &mut gpui::TestAppContext) { cx.set_shared_state(indoc! {
// let mut cx = NeovimBackedTestContext::new(cx).await; "ˇthe quick brown
fox jumps over
the lazy dog"
})
.await;
cx.simulate_shared_keystrokes(["v", "i", "w", "s", "o", "escape"])
.await;
cx.assert_shared_state(indoc! {
"ˇo quick brown
fox jumps over
the lazy dog"
})
.await;
cx.simulate_shared_keystrokes(["j", "w", "."]).await;
cx.assert_shared_state(indoc! {
"o quick brown
fox ˇops over
the lazy dog"
})
.await;
cx.simulate_shared_keystrokes(["f", "r", "."]).await;
cx.assert_shared_state(indoc! {
"o quick brown
fox ops oveˇothe lazy dog"
})
.await;
// // single-line (3 columns) // visual
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "ˇthe quick brown "the ˇquick brown
// fox jumps over fox jumps over
// the lazy dog" fox jumps over
// }) fox jumps over
// .await; the lazy dog"
// cx.simulate_shared_keystrokes(["v", "i", "w", "s", "o", "escape"]) })
// .await; .await;
// cx.assert_shared_state(indoc! { cx.simulate_shared_keystrokes(["v", "j", "x"]).await;
// "ˇo quick brown cx.assert_shared_state(indoc! {
// fox jumps over "the ˇumps over
// the lazy dog" fox jumps over
// }) fox jumps over
// .await; the lazy dog"
// cx.simulate_shared_keystrokes(["j", "w", "."]).await; })
// deterministic.run_until_parked(); .await;
// cx.assert_shared_state(indoc! { cx.simulate_shared_keystrokes(["."]).await;
// "o quick brown cx.assert_shared_state(indoc! {
// fox ˇops over "the ˇumps over
// the lazy dog" fox jumps over
// }) the lazy dog"
// .await; })
// cx.simulate_shared_keystrokes(["f", "r", "."]).await; .await;
// deterministic.run_until_parked(); cx.simulate_shared_keystrokes(["w", "."]).await;
// cx.assert_shared_state(indoc! { cx.assert_shared_state(indoc! {
// "o quick brown "the umps ˇumps over
// fox ops oveˇothe lazy dog" the lazy dog"
// }) })
// .await; .await;
cx.simulate_shared_keystrokes(["j", "."]).await;
cx.assert_shared_state(indoc! {
"the umps umps over
the ˇog"
})
.await;
// // visual // block mode (3 rows)
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "the ˇquick brown "ˇthe quick brown
// fox jumps over fox jumps over
// fox jumps over the lazy dog"
// fox jumps over })
// the lazy dog" .await;
// }) cx.simulate_shared_keystrokes(["ctrl-v", "j", "j", "shift-i", "o", "escape"])
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "j", "x"]).await; cx.assert_shared_state(indoc! {
// cx.assert_shared_state(indoc! { "ˇothe quick brown
// "the ˇumps over ofox jumps over
// fox jumps over othe lazy dog"
// fox jumps over })
// the lazy dog" .await;
// }) cx.simulate_shared_keystrokes(["j", "4", "l", "."]).await;
// .await; cx.assert_shared_state(indoc! {
// cx.simulate_shared_keystrokes(["."]).await; "othe quick brown
// deterministic.run_until_parked(); ofoxˇo jumps over
// cx.assert_shared_state(indoc! { otheo lazy dog"
// "the ˇumps over })
// fox jumps over .await;
// the lazy dog"
// })
// .await;
// cx.simulate_shared_keystrokes(["w", "."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state(indoc! {
// "the umps ˇumps over
// the lazy dog"
// })
// .await;
// cx.simulate_shared_keystrokes(["j", "."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state(indoc! {
// "the umps umps over
// the ˇog"
// })
// .await;
// // block mode (3 rows) // line mode
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "ˇthe quick brown "ˇthe quick brown
// fox jumps over fox jumps over
// the lazy dog" the lazy dog"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["ctrl-v", "j", "j", "shift-i", "o", "escape"]) cx.simulate_shared_keystrokes(["shift-v", "shift-r", "o", "escape"])
// .await; .await;
// cx.assert_shared_state(indoc! { cx.assert_shared_state(indoc! {
// "ˇothe quick brown "ˇo
// ofox jumps over fox jumps over
// othe lazy dog" the lazy dog"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["j", "4", "l", "."]).await; cx.simulate_shared_keystrokes(["j", "."]).await;
// deterministic.run_until_parked(); cx.assert_shared_state(indoc! {
// cx.assert_shared_state(indoc! { "o
// "othe quick brown ˇo
// ofoxˇo jumps over the lazy dog"
// otheo lazy dog" })
// }) .await;
// .await; }
// // line mode #[gpui::test]
// cx.set_shared_state(indoc! { async fn test_repeat_motion_counts(cx: &mut gpui::TestAppContext) {
// "ˇthe quick brown let mut cx = NeovimBackedTestContext::new(cx).await;
// fox jumps over
// the lazy dog"
// })
// .await;
// cx.simulate_shared_keystrokes(["shift-v", "shift-r", "o", "escape"])
// .await;
// cx.assert_shared_state(indoc! {
// "ˇo
// fox jumps over
// the lazy dog"
// })
// .await;
// cx.simulate_shared_keystrokes(["j", "."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state(indoc! {
// "o
// ˇo
// the lazy dog"
// })
// .await;
// }
// #[gpui::test] cx.set_shared_state(indoc! {
// async fn test_repeat_motion_counts( "ˇthe quick brown
// deterministic: Arc<Deterministic>, fox jumps over
// cx: &mut gpui::TestAppContext, the lazy dog"
// ) { })
// let mut cx = NeovimBackedTestContext::new(cx).await; .await;
cx.simulate_shared_keystrokes(["3", "d", "3", "l"]).await;
cx.assert_shared_state(indoc! {
"ˇ brown
fox jumps over
the lazy dog"
})
.await;
cx.simulate_shared_keystrokes(["j", "."]).await;
cx.assert_shared_state(indoc! {
" brown
ˇ over
the lazy dog"
})
.await;
cx.simulate_shared_keystrokes(["j", "2", "."]).await;
cx.assert_shared_state(indoc! {
" brown
over
ˇe lazy dog"
})
.await;
}
// cx.set_shared_state(indoc! { #[gpui::test]
// "ˇthe quick brown async fn test_record_interrupted(cx: &mut gpui::TestAppContext) {
// fox jumps over let mut cx = VimTestContext::new(cx, true).await;
// the lazy dog"
// })
// .await;
// cx.simulate_shared_keystrokes(["3", "d", "3", "l"]).await;
// cx.assert_shared_state(indoc! {
// "ˇ brown
// fox jumps over
// the lazy dog"
// })
// .await;
// cx.simulate_shared_keystrokes(["j", "."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state(indoc! {
// " brown
// ˇ over
// the lazy dog"
// })
// .await;
// cx.simulate_shared_keystrokes(["j", "2", "."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state(indoc! {
// " brown
// over
// ˇe lazy dog"
// })
// .await;
// }
// #[gpui::test] cx.set_state("ˇhello\n", Mode::Normal);
// async fn test_record_interrupted( cx.simulate_keystrokes(["4", "i", "j", "cmd-shift-p", "escape"]);
// deterministic: Arc<Deterministic>, cx.simulate_keystrokes(["escape"]);
// cx: &mut gpui::TestAppContext, cx.assert_state("ˇjhello\n", Mode::Normal);
// ) { }
// let mut cx = VimTestContext::new(cx, true).await; }
// cx.set_state("ˇhello\n", Mode::Normal);
// cx.simulate_keystrokes(["4", "i", "j", "cmd-shift-p", "escape", "escape"]);
// deterministic.run_until_parked();
// cx.assert_state("ˇjhello\n", Mode::Normal);
// }
// }

View file

@ -347,58 +347,50 @@ fn parse_replace_all(query: &str) -> Replacement {
// #[cfg(test)] // #[cfg(test)]
// mod test { // mod test {
// use std::sync::Arc;
// use editor::DisplayPoint; // use editor::DisplayPoint;
// use search::BufferSearchBar; // use search::BufferSearchBar;
// use crate::{state::Mode, test::VimTestContext}; // use crate::{state::Mode, test::VimTestContext};
// #[gpui::test] // #[gpui::test]
// async fn test_move_to_next( // async fn test_move_to_next(cx: &mut gpui::TestAppContext) {
// cx: &mut gpui::TestAppContext,
// deterministic: Arc<gpui::executor::Deterministic>,
// ) {
// let mut cx = VimTestContext::new(cx, true).await; // let mut cx = VimTestContext::new(cx, true).await;
// cx.set_state("ˇhi\nhigh\nhi\n", Mode::Normal); // cx.set_state("ˇhi\nhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["*"]); // cx.simulate_keystrokes(["*"]);
// deterministic.run_until_parked(); // cx.run_until_parked();
// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); // cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal);
// cx.simulate_keystrokes(["*"]); // cx.simulate_keystrokes(["*"]);
// deterministic.run_until_parked(); // cx.run_until_parked();
// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); // cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["#"]); // cx.simulate_keystrokes(["#"]);
// deterministic.run_until_parked(); // cx.run_until_parked();
// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); // cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal);
// cx.simulate_keystrokes(["#"]); // cx.simulate_keystrokes(["#"]);
// deterministic.run_until_parked(); // cx.run_until_parked();
// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); // cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["2", "*"]); // cx.simulate_keystrokes(["2", "*"]);
// deterministic.run_until_parked(); // cx.run_until_parked();
// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); // cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["g", "*"]); // cx.simulate_keystrokes(["g", "*"]);
// deterministic.run_until_parked(); // cx.run_until_parked();
// cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); // cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["n"]); // cx.simulate_keystrokes(["n"]);
// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); // cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal);
// cx.simulate_keystrokes(["g", "#"]); // cx.simulate_keystrokes(["g", "#"]);
// deterministic.run_until_parked(); // cx.run_until_parked();
// cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); // cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal);
// } // }
// #[gpui::test] // #[gpui::test]
// async fn test_search( // async fn test_search(cx: &mut gpui::TestAppContext) {
// cx: &mut gpui::TestAppContext,
// deterministic: Arc<gpui::executor::Deterministic>,
// ) {
// let mut cx = VimTestContext::new(cx, true).await; // let mut cx = VimTestContext::new(cx, true).await;
// cx.set_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); // cx.set_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal);
@ -414,11 +406,11 @@ fn parse_replace_all(query: &str) -> Replacement {
// .expect("Buffer search bar should be deployed") // .expect("Buffer search bar should be deployed")
// }); // });
// search_bar.read_with(cx.cx, |bar, cx| { // cx.update_view(search_bar, |bar, cx| {
// assert_eq!(bar.query(cx), "cc"); // assert_eq!(bar.query(cx), "cc");
// }); // });
// deterministic.run_until_parked(); // cx.run_until_parked();
// cx.update_editor(|editor, cx| { // cx.update_editor(|editor, cx| {
// let highlights = editor.all_text_background_highlights(cx); // let highlights = editor.all_text_background_highlights(cx);
@ -440,51 +432,41 @@ fn parse_replace_all(query: &str) -> Replacement {
// // ?<enter> to go to previous // // ?<enter> to go to previous
// cx.simulate_keystrokes(["?", "enter"]); // cx.simulate_keystrokes(["?", "enter"]);
// deterministic.run_until_parked();
// cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); // cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal);
// cx.simulate_keystrokes(["?", "enter"]); // cx.simulate_keystrokes(["?", "enter"]);
// deterministic.run_until_parked();
// cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); // cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal);
// // /<enter> to go to next // // /<enter> to go to next
// cx.simulate_keystrokes(["/", "enter"]); // cx.simulate_keystrokes(["/", "enter"]);
// deterministic.run_until_parked();
// cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); // cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal);
// // ?{search}<enter> to search backwards // // ?{search}<enter> to search backwards
// cx.simulate_keystrokes(["?", "b", "enter"]); // cx.simulate_keystrokes(["?", "b", "enter"]);
// deterministic.run_until_parked();
// cx.assert_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); // cx.assert_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal);
// // works with counts // // works with counts
// cx.simulate_keystrokes(["4", "/", "c"]); // cx.simulate_keystrokes(["4", "/", "c"]);
// deterministic.run_until_parked();
// cx.simulate_keystrokes(["enter"]); // cx.simulate_keystrokes(["enter"]);
// cx.assert_state("aa\nbb\ncc\ncˇc\ncc\n", Mode::Normal); // cx.assert_state("aa\nbb\ncc\ncˇc\ncc\n", Mode::Normal);
// // check that searching resumes from cursor, not previous match // // check that searching resumes from cursor, not previous match
// cx.set_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); // cx.set_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal);
// cx.simulate_keystrokes(["/", "d"]); // cx.simulate_keystrokes(["/", "d"]);
// deterministic.run_until_parked();
// cx.simulate_keystrokes(["enter"]); // cx.simulate_keystrokes(["enter"]);
// cx.assert_state("aa\nbb\nˇdd\ncc\nbb\n", Mode::Normal); // 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.update_editor(|editor, cx| editor.move_to_beginning(&Default::default(), cx));
// cx.assert_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); // cx.assert_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal);
// cx.simulate_keystrokes(["/", "b"]); // cx.simulate_keystrokes(["/", "b"]);
// deterministic.run_until_parked();
// cx.simulate_keystrokes(["enter"]); // cx.simulate_keystrokes(["enter"]);
// cx.assert_state("aa\nˇbb\ndd\ncc\nbb\n", Mode::Normal); // cx.assert_state("aa\nˇbb\ndd\ncc\nbb\n", Mode::Normal);
// } // }
// #[gpui::test] // #[gpui::test]
// async fn test_non_vim_search( // async fn test_non_vim_search(cx: &mut gpui::TestAppContext) {
// cx: &mut gpui::TestAppContext,
// deterministic: Arc<gpui::executor::Deterministic>,
// ) {
// let mut cx = VimTestContext::new(cx, false).await; // let mut cx = VimTestContext::new(cx, false).await;
// cx.set_state("ˇone one one one", Mode::Normal); // cx.set_state("ˇone one one one", Mode::Normal);
// cx.simulate_keystrokes(["cmd-f"]); // cx.simulate_keystrokes(["cmd-f"]);
// deterministic.run_until_parked(); // cx.run_until_parked();
// cx.assert_editor_state("«oneˇ» one one one"); // cx.assert_editor_state("«oneˇ» one one one");
// cx.simulate_keystrokes(["enter"]); // cx.simulate_keystrokes(["enter"]);

View file

@ -18,7 +18,11 @@ pub struct VimTestContext<'a> {
} }
impl<'a> VimTestContext<'a> { impl<'a> VimTestContext<'a> {
pub async fn new(cx: &'a mut gpui::TestAppContext, enabled: bool) -> VimTestContext<'a> { pub fn init(cx: &mut gpui::TestAppContext) {
if cx.has_global::<Vim>() {
dbg!("OOPS");
return;
}
cx.update(|cx| { cx.update(|cx| {
search::init(cx); search::init(cx);
let settings = SettingsStore::test(cx); let settings = SettingsStore::test(cx);
@ -26,18 +30,16 @@ impl<'a> VimTestContext<'a> {
command_palette::init(cx); command_palette::init(cx);
crate::init(cx); crate::init(cx);
}); });
}
pub async fn new(cx: &'a mut gpui::TestAppContext, enabled: bool) -> VimTestContext<'a> {
Self::init(cx);
let lsp = EditorLspTestContext::new_rust(Default::default(), cx).await; let lsp = EditorLspTestContext::new_rust(Default::default(), cx).await;
Self::new_with_lsp(lsp, enabled) Self::new_with_lsp(lsp, enabled)
} }
pub async fn new_typescript(cx: &'a mut gpui::TestAppContext) -> VimTestContext<'a> { pub async fn new_typescript(cx: &'a mut gpui::TestAppContext) -> VimTestContext<'a> {
cx.update(|cx| { Self::init(cx);
search::init(cx);
let settings = SettingsStore::test(cx);
cx.set_global(settings);
command_palette::init(cx);
crate::init(cx);
});
Self::new_with_lsp( Self::new_with_lsp(
EditorLspTestContext::new_typescript(Default::default(), cx).await, EditorLspTestContext::new_typescript(Default::default(), cx).await,
true, true,