MOAR TESTS

This commit is contained in:
Conrad Irwin 2023-12-11 15:06:33 -07:00
parent 303189e086
commit 1e89092d62
8 changed files with 1215 additions and 1200 deletions

View file

@ -230,6 +230,12 @@ impl DispatchTree {
} }
} }
pub fn has_pending_keystrokes(&self) -> bool {
self.keystroke_matchers
.iter()
.any(|(_, matcher)| matcher.has_pending_keystrokes())
}
pub fn dispatch_path(&self, target: DispatchNodeId) -> SmallVec<[DispatchNodeId; 32]> { pub fn dispatch_path(&self, target: DispatchNodeId) -> SmallVec<[DispatchNodeId; 32]> {
let mut dispatch_path: SmallVec<[DispatchNodeId; 32]> = SmallVec::new(); let mut dispatch_path: SmallVec<[DispatchNodeId; 32]> = SmallVec::new();
let mut current_node_id = Some(target); let mut current_node_id = Some(target);

View file

@ -1451,6 +1451,13 @@ impl<'a> WindowContext<'a> {
self.dispatch_keystroke_observers(event, None); self.dispatch_keystroke_observers(event, None);
} }
pub fn has_pending_keystrokes(&self) -> bool {
self.window
.rendered_frame
.dispatch_tree
.has_pending_keystrokes()
}
fn dispatch_action_on_node(&mut self, node_id: DispatchNodeId, action: Box<dyn Action>) { fn dispatch_action_on_node(&mut self, node_id: DispatchNodeId, action: Box<dyn Action>) {
let dispatch_path = self let dispatch_path = self
.window .window

View file

@ -130,373 +130,373 @@ fn expand_changed_word_selection(
} }
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use indoc::indoc; use indoc::indoc;
// use crate::test::NeovimBackedTestContext; use crate::test::NeovimBackedTestContext;
// #[gpui::test] #[gpui::test]
// async fn test_change_h(cx: &mut gpui::TestAppContext) { async fn test_change_h(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "h"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "h"]);
// cx.assert("Teˇst").await; cx.assert("Teˇst").await;
// cx.assert("Tˇest").await; cx.assert("Tˇest").await;
// cx.assert("ˇTest").await; cx.assert("ˇTest").await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test Test
// ˇtest"}) ˇtest"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_backspace(cx: &mut gpui::TestAppContext) { async fn test_change_backspace(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx) let mut cx = NeovimBackedTestContext::new(cx)
// .await .await
// .binding(["c", "backspace"]); .binding(["c", "backspace"]);
// cx.assert("Teˇst").await; cx.assert("Teˇst").await;
// cx.assert("Tˇest").await; cx.assert("Tˇest").await;
// cx.assert("ˇTest").await; cx.assert("ˇTest").await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test Test
// ˇtest"}) ˇtest"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_l(cx: &mut gpui::TestAppContext) { async fn test_change_l(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "l"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "l"]);
// cx.assert("Teˇst").await; cx.assert("Teˇst").await;
// cx.assert("Tesˇt").await; cx.assert("Tesˇt").await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_w(cx: &mut gpui::TestAppContext) { async fn test_change_w(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "w"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "w"]);
// cx.assert("Teˇst").await; cx.assert("Teˇst").await;
// cx.assert("Tˇest test").await; cx.assert("Tˇest test").await;
// cx.assert("Testˇ test").await; cx.assert("Testˇ test").await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test teˇst Test teˇst
// test"}) test"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test tesˇt Test tesˇt
// test"}) test"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test test Test test
// ˇ ˇ
// test"}) test"})
// .await; .await;
// let mut cx = cx.binding(["c", "shift-w"]); let mut cx = cx.binding(["c", "shift-w"]);
// cx.assert("Test teˇst-test test").await; cx.assert("Test teˇst-test test").await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_e(cx: &mut gpui::TestAppContext) { async fn test_change_e(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "e"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "e"]);
// cx.assert("Teˇst Test").await; cx.assert("Teˇst Test").await;
// cx.assert("Tˇest test").await; cx.assert("Tˇest test").await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test teˇst Test teˇst
// test"}) test"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test tesˇt Test tesˇt
// test"}) test"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test test Test test
// ˇ ˇ
// test"}) test"})
// .await; .await;
// let mut cx = cx.binding(["c", "shift-e"]); let mut cx = cx.binding(["c", "shift-e"]);
// cx.assert("Test teˇst-test test").await; cx.assert("Test teˇst-test test").await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_b(cx: &mut gpui::TestAppContext) { async fn test_change_b(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "b"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "b"]);
// cx.assert("Teˇst Test").await; cx.assert("Teˇst Test").await;
// cx.assert("Test ˇtest").await; cx.assert("Test ˇtest").await;
// cx.assert("Test1 test2 ˇtest3").await; cx.assert("Test1 test2 ˇtest3").await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test test Test test
// ˇtest"}) ˇtest"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test test Test test
// ˇ ˇ
// test"}) test"})
// .await; .await;
// let mut cx = cx.binding(["c", "shift-b"]); let mut cx = cx.binding(["c", "shift-b"]);
// cx.assert("Test test-test ˇtest").await; cx.assert("Test test-test ˇtest").await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_end_of_line(cx: &mut gpui::TestAppContext) { async fn test_change_end_of_line(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "$"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "$"]);
// cx.assert(indoc! {" cx.assert(indoc! {"
// The qˇuick The qˇuick
// brown fox"}) brown fox"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quick The quick
// ˇ ˇ
// brown fox"}) brown fox"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_0(cx: &mut gpui::TestAppContext) { async fn test_change_0(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The qˇuick The qˇuick
// brown fox"}, brown fox"},
// ["c", "0"], ["c", "0"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// ˇ ˇ
// brown fox"}, brown fox"},
// ["c", "0"], ["c", "0"],
// ) )
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_k(cx: &mut gpui::TestAppContext) { async fn test_change_k(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown ˇfox brown ˇfox
// jumps over"}, jumps over"},
// ["c", "k"], ["c", "k"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown fox brown fox
// jumps ˇover"}, jumps ˇover"},
// ["c", "k"], ["c", "k"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The qˇuick The qˇuick
// brown fox brown fox
// jumps over"}, jumps over"},
// ["c", "k"], ["c", "k"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// ˇ ˇ
// brown fox brown fox
// jumps over"}, jumps over"},
// ["c", "k"], ["c", "k"],
// ) )
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_j(cx: &mut gpui::TestAppContext) { async fn test_change_j(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown ˇfox brown ˇfox
// jumps over"}, jumps over"},
// ["c", "j"], ["c", "j"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown fox brown fox
// jumps ˇover"}, jumps ˇover"},
// ["c", "j"], ["c", "j"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The qˇuick The qˇuick
// brown fox brown fox
// jumps over"}, jumps over"},
// ["c", "j"], ["c", "j"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown fox brown fox
// ˇ"}, ˇ"},
// ["c", "j"], ["c", "j"],
// ) )
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_end_of_document(cx: &mut gpui::TestAppContext) { async fn test_change_end_of_document(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brownˇ fox brownˇ fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["c", "shift-g"], ["c", "shift-g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brownˇ fox brownˇ fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["c", "shift-g"], ["c", "shift-g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown fox brown fox
// jumps over jumps over
// the lˇazy"}, the lˇazy"},
// ["c", "shift-g"], ["c", "shift-g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown fox brown fox
// jumps over jumps over
// ˇ"}, ˇ"},
// ["c", "shift-g"], ["c", "shift-g"],
// ) )
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_change_gg(cx: &mut gpui::TestAppContext) { async fn test_change_gg(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brownˇ fox brownˇ fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["c", "g", "g"], ["c", "g", "g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown fox brown fox
// jumps over jumps over
// the lˇazy"}, the lˇazy"},
// ["c", "g", "g"], ["c", "g", "g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The qˇuick The qˇuick
// brown fox brown fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["c", "g", "g"], ["c", "g", "g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// ˇ ˇ
// brown fox brown fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["c", "g", "g"], ["c", "g", "g"],
// ) )
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_repeated_cj(cx: &mut gpui::TestAppContext) { async fn test_repeated_cj(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// for count in 1..=5 { for count in 1..=5 {
// cx.assert_binding_matches_all( cx.assert_binding_matches_all(
// ["c", &count.to_string(), "j"], ["c", &count.to_string(), "j"],
// indoc! {" indoc! {"
// ˇThe quˇickˇ browˇn ˇThe quˇickˇ browˇn
// ˇ ˇ
// ˇfox ˇjumpsˇ-ˇoˇver ˇfox ˇjumpsˇ-ˇoˇver
// ˇthe lazy dog ˇthe lazy dog
// "}, "},
// ) )
// .await; .await;
// } }
// } }
// #[gpui::test] #[gpui::test]
// async fn test_repeated_cl(cx: &mut gpui::TestAppContext) { async fn test_repeated_cl(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// for count in 1..=5 { for count in 1..=5 {
// cx.assert_binding_matches_all( cx.assert_binding_matches_all(
// ["c", &count.to_string(), "l"], ["c", &count.to_string(), "l"],
// indoc! {" indoc! {"
// ˇThe quˇickˇ browˇn ˇThe quˇickˇ browˇn
// ˇ ˇ
// ˇfox ˇjumpsˇ-ˇoˇver ˇfox ˇjumpsˇ-ˇoˇver
// ˇthe lazy dog ˇthe lazy dog
// "}, "},
// ) )
// .await; .await;
// } }
// } }
// #[gpui::test] #[gpui::test]
// async fn test_repeated_cb(cx: &mut gpui::TestAppContext) { async fn test_repeated_cb(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// for count in 1..=5 { for count in 1..=5 {
// for marked_text in cx.each_marked_position(indoc! {" for marked_text in cx.each_marked_position(indoc! {"
// ˇThe quˇickˇ browˇn ˇThe quˇickˇ browˇn
// ˇ ˇ
// ˇfox ˇjumpsˇ-ˇoˇver ˇfox ˇjumpsˇ-ˇoˇver
// ˇthe lazy dog ˇthe lazy dog
// "}) "})
// { {
// cx.assert_neovim_compatible(&marked_text, ["c", &count.to_string(), "b"]) cx.assert_neovim_compatible(&marked_text, ["c", &count.to_string(), "b"])
// .await; .await;
// } }
// } }
// } }
// #[gpui::test] #[gpui::test]
// async fn test_repeated_ce(cx: &mut gpui::TestAppContext) { async fn test_repeated_ce(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// for count in 1..=5 { for count in 1..=5 {
// cx.assert_binding_matches_all( cx.assert_binding_matches_all(
// ["c", &count.to_string(), "e"], ["c", &count.to_string(), "e"],
// indoc! {" indoc! {"
// ˇThe quˇickˇ browˇn ˇThe quˇickˇ browˇn
// ˇ ˇ
// ˇfox ˇjumpsˇ-ˇoˇver ˇfox ˇjumpsˇ-ˇoˇver
// ˇthe lazy dog ˇthe lazy dog
// "}, "},
// ) )
// .await; .await;
// } }
// } }
// } }

View file

@ -117,359 +117,359 @@ pub fn delete_object(vim: &mut Vim, object: Object, around: bool, cx: &mut Windo
}); });
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use indoc::indoc; use indoc::indoc;
// use crate::{ use crate::{
// state::Mode, state::Mode,
// test::{ExemptionFeatures, NeovimBackedTestContext, VimTestContext}, test::{ExemptionFeatures, NeovimBackedTestContext, VimTestContext},
// }; };
// #[gpui::test] #[gpui::test]
// async fn test_delete_h(cx: &mut gpui::TestAppContext) { async fn test_delete_h(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "h"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "h"]);
// cx.assert("Teˇst").await; cx.assert("Teˇst").await;
// cx.assert("Tˇest").await; cx.assert("Tˇest").await;
// cx.assert("ˇTest").await; cx.assert("ˇTest").await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test Test
// ˇtest"}) ˇtest"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_l(cx: &mut gpui::TestAppContext) { async fn test_delete_l(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "l"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "l"]);
// cx.assert("ˇTest").await; cx.assert("ˇTest").await;
// cx.assert("Teˇst").await; cx.assert("Teˇst").await;
// cx.assert("Tesˇt").await; cx.assert("Tesˇt").await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Tesˇt Tesˇt
// test"}) test"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_w(cx: &mut gpui::TestAppContext) { async fn test_delete_w(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// Test tesˇt Test tesˇt
// test"}, test"},
// ["d", "w"], ["d", "w"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible("Teˇst", ["d", "w"]).await; cx.assert_neovim_compatible("Teˇst", ["d", "w"]).await;
// cx.assert_neovim_compatible("Tˇest test", ["d", "w"]).await; cx.assert_neovim_compatible("Tˇest test", ["d", "w"]).await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// Test teˇst Test teˇst
// test"}, test"},
// ["d", "w"], ["d", "w"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// Test tesˇt Test tesˇt
// test"}, test"},
// ["d", "w"], ["d", "w"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// Test test Test test
// ˇ ˇ
// test"}, test"},
// ["d", "w"], ["d", "w"],
// ) )
// .await; .await;
// let mut cx = cx.binding(["d", "shift-w"]); let mut cx = cx.binding(["d", "shift-w"]);
// cx.assert_neovim_compatible("Test teˇst-test test", ["d", "shift-w"]) cx.assert_neovim_compatible("Test teˇst-test test", ["d", "shift-w"])
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_next_word_end(cx: &mut gpui::TestAppContext) { async fn test_delete_next_word_end(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "e"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "e"]);
// // cx.assert("Teˇst Test").await; // cx.assert("Teˇst Test").await;
// // cx.assert("Tˇest test").await; // cx.assert("Tˇest test").await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test teˇst Test teˇst
// test"}) test"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test tesˇt Test tesˇt
// test"}) test"})
// .await; .await;
// cx.assert_exempted( cx.assert_exempted(
// indoc! {" indoc! {"
// Test test Test test
// ˇ ˇ
// test"}, test"},
// ExemptionFeatures::OperatorLastNewlineRemains, ExemptionFeatures::OperatorLastNewlineRemains,
// ) )
// .await; .await;
// let mut cx = cx.binding(["d", "shift-e"]); let mut cx = cx.binding(["d", "shift-e"]);
// cx.assert("Test teˇst-test test").await; cx.assert("Test teˇst-test test").await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_b(cx: &mut gpui::TestAppContext) { async fn test_delete_b(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "b"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "b"]);
// cx.assert("Teˇst Test").await; cx.assert("Teˇst Test").await;
// cx.assert("Test ˇtest").await; cx.assert("Test ˇtest").await;
// cx.assert("Test1 test2 ˇtest3").await; cx.assert("Test1 test2 ˇtest3").await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test test Test test
// ˇtest"}) ˇtest"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// Test test Test test
// ˇ ˇ
// test"}) test"})
// .await; .await;
// let mut cx = cx.binding(["d", "shift-b"]); let mut cx = cx.binding(["d", "shift-b"]);
// cx.assert("Test test-test ˇtest").await; cx.assert("Test test-test ˇtest").await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_end_of_line(cx: &mut gpui::TestAppContext) { async fn test_delete_end_of_line(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "$"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "$"]);
// cx.assert(indoc! {" cx.assert(indoc! {"
// The qˇuick The qˇuick
// brown fox"}) brown fox"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quick The quick
// ˇ ˇ
// brown fox"}) brown fox"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_0(cx: &mut gpui::TestAppContext) { async fn test_delete_0(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "0"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "0"]);
// cx.assert(indoc! {" cx.assert(indoc! {"
// The qˇuick The qˇuick
// brown fox"}) brown fox"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quick The quick
// ˇ ˇ
// brown fox"}) brown fox"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_k(cx: &mut gpui::TestAppContext) { async fn test_delete_k(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "k"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "k"]);
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quick The quick
// brown ˇfox brown ˇfox
// jumps over"}) jumps over"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quick The quick
// brown fox brown fox
// jumps ˇover"}) jumps ˇover"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// The qˇuick The qˇuick
// brown fox brown fox
// jumps over"}) jumps over"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// ˇbrown fox ˇbrown fox
// jumps over"}) jumps over"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_j(cx: &mut gpui::TestAppContext) { async fn test_delete_j(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "j"]); let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "j"]);
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quick The quick
// brown ˇfox brown ˇfox
// jumps over"}) jumps over"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quick The quick
// brown fox brown fox
// jumps ˇover"}) jumps ˇover"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// The qˇuick The qˇuick
// brown fox brown fox
// jumps over"}) jumps over"})
// .await; .await;
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quick The quick
// brown fox brown fox
// ˇ"}) ˇ"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_end_of_document(cx: &mut gpui::TestAppContext) { async fn test_delete_end_of_document(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brownˇ fox brownˇ fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["d", "shift-g"], ["d", "shift-g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brownˇ fox brownˇ fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["d", "shift-g"], ["d", "shift-g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown fox brown fox
// jumps over jumps over
// the lˇazy"}, the lˇazy"},
// ["d", "shift-g"], ["d", "shift-g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown fox brown fox
// jumps over jumps over
// ˇ"}, ˇ"},
// ["d", "shift-g"], ["d", "shift-g"],
// ) )
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_gg(cx: &mut gpui::TestAppContext) { async fn test_delete_gg(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx) let mut cx = NeovimBackedTestContext::new(cx)
// .await .await
// .binding(["d", "g", "g"]); .binding(["d", "g", "g"]);
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brownˇ fox brownˇ fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["d", "g", "g"], ["d", "g", "g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The quick The quick
// brown fox brown fox
// jumps over jumps over
// the lˇazy"}, the lˇazy"},
// ["d", "g", "g"], ["d", "g", "g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// The qˇuick The qˇuick
// brown fox brown fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["d", "g", "g"], ["d", "g", "g"],
// ) )
// .await; .await;
// cx.assert_neovim_compatible( cx.assert_neovim_compatible(
// indoc! {" indoc! {"
// ˇ ˇ
// brown fox brown fox
// jumps over jumps over
// the lazy"}, the lazy"},
// ["d", "g", "g"], ["d", "g", "g"],
// ) )
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_cancel_delete_operator(cx: &mut gpui::TestAppContext) { async fn test_cancel_delete_operator(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, true).await; let mut cx = VimTestContext::new(cx, true).await;
// cx.set_state( cx.set_state(
// indoc! {" indoc! {"
// The quick brown The quick brown
// fox juˇmps over fox juˇmps over
// the lazy dog"}, the lazy dog"},
// Mode::Normal, Mode::Normal,
// ); );
// // Canceling operator twice reverts to normal mode with no active operator // Canceling operator twice reverts to normal mode with no active operator
// cx.simulate_keystrokes(["d", "escape", "k"]); cx.simulate_keystrokes(["d", "escape", "k"]);
// assert_eq!(cx.active_operator(), None); assert_eq!(cx.active_operator(), None);
// assert_eq!(cx.mode(), Mode::Normal); assert_eq!(cx.mode(), Mode::Normal);
// cx.assert_editor_state(indoc! {" cx.assert_editor_state(indoc! {"
// The quˇick brown The quˇick brown
// fox jumps over fox jumps over
// the lazy dog"}); the lazy dog"});
// } }
// #[gpui::test] #[gpui::test]
// async fn test_unbound_command_cancels_pending_operator(cx: &mut gpui::TestAppContext) { async fn test_unbound_command_cancels_pending_operator(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, true).await; let mut cx = VimTestContext::new(cx, true).await;
// cx.set_state( cx.set_state(
// indoc! {" indoc! {"
// The quick brown The quick brown
// fox juˇmps over fox juˇmps over
// the lazy dog"}, the lazy dog"},
// Mode::Normal, Mode::Normal,
// ); );
// // Canceling operator twice reverts to normal mode with no active operator // Canceling operator twice reverts to normal mode with no active operator
// cx.simulate_keystrokes(["d", "y"]); cx.simulate_keystrokes(["d", "y"]);
// assert_eq!(cx.active_operator(), None); assert_eq!(cx.active_operator(), None);
// assert_eq!(cx.mode(), Mode::Normal); assert_eq!(cx.mode(), Mode::Normal);
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_with_counts(cx: &mut gpui::TestAppContext) { async fn test_delete_with_counts(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// 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(["d", "2", "d"]).await; cx.simulate_shared_keystrokes(["d", "2", "d"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// the ˇlazy dog"}) the ˇlazy dog"})
// .await; .await;
// 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(["2", "d", "d"]).await; cx.simulate_shared_keystrokes(["2", "d", "d"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// the ˇlazy dog"}) the ˇlazy dog"})
// .await; .await;
// cx.set_shared_state(indoc! {" cx.set_shared_state(indoc! {"
// The ˇquick brown The ˇquick brown
// fox jumps over fox jumps over
// the moon, the moon,
// a star, and a star, and
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.simulate_shared_keystrokes(["2", "d", "2", "d"]).await; cx.simulate_shared_keystrokes(["2", "d", "2", "d"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// the ˇlazy dog"}) the ˇlazy dog"})
// .await; .await;
// } }
// } }

View file

@ -173,106 +173,106 @@ fn find_number(
} }
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use indoc::indoc; use indoc::indoc;
// use crate::test::NeovimBackedTestContext; use crate::test::NeovimBackedTestContext;
// #[gpui::test] #[gpui::test]
// async fn test_increment(cx: &mut gpui::TestAppContext) { async fn test_increment(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.set_shared_state(indoc! {" cx.set_shared_state(indoc! {"
// 1ˇ2 1ˇ2
// "}) "})
// .await; .await;
// cx.simulate_shared_keystrokes(["ctrl-a"]).await; cx.simulate_shared_keystrokes(["ctrl-a"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// 1ˇ3 1ˇ3
// "}) "})
// .await; .await;
// cx.simulate_shared_keystrokes(["ctrl-x"]).await; cx.simulate_shared_keystrokes(["ctrl-x"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// 1ˇ2 1ˇ2
// "}) "})
// .await; .await;
// cx.simulate_shared_keystrokes(["9", "9", "ctrl-a"]).await; cx.simulate_shared_keystrokes(["9", "9", "ctrl-a"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// 11ˇ1 11ˇ1
// "}) "})
// .await; .await;
// cx.simulate_shared_keystrokes(["1", "1", "1", "ctrl-x"]) cx.simulate_shared_keystrokes(["1", "1", "1", "ctrl-x"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// ˇ0 ˇ0
// "}) "})
// .await; .await;
// cx.simulate_shared_keystrokes(["."]).await; cx.simulate_shared_keystrokes(["."]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// -11ˇ1 -11ˇ1
// "}) "})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_increment_radix(cx: &mut gpui::TestAppContext) { async fn test_increment_radix(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_matches_neovim("ˇ total: 0xff", ["ctrl-a"], " total: 0x10ˇ0") cx.assert_matches_neovim("ˇ total: 0xff", ["ctrl-a"], " total: 0x10ˇ0")
// .await; .await;
// cx.assert_matches_neovim("ˇ total: 0xff", ["ctrl-x"], " total: 0xfˇe") cx.assert_matches_neovim("ˇ total: 0xff", ["ctrl-x"], " total: 0xfˇe")
// .await; .await;
// cx.assert_matches_neovim("ˇ total: 0xFF", ["ctrl-x"], " total: 0xFˇE") cx.assert_matches_neovim("ˇ total: 0xFF", ["ctrl-x"], " total: 0xFˇE")
// .await; .await;
// cx.assert_matches_neovim("(ˇ0b10f)", ["ctrl-a"], "(0b1ˇ1f)") cx.assert_matches_neovim("(ˇ0b10f)", ["ctrl-a"], "(0b1ˇ1f)")
// .await; .await;
// cx.assert_matches_neovim("ˇ-1", ["ctrl-a"], "ˇ0").await; cx.assert_matches_neovim("ˇ-1", ["ctrl-a"], "ˇ0").await;
// cx.assert_matches_neovim("banˇana", ["ctrl-a"], "banˇana") cx.assert_matches_neovim("banˇana", ["ctrl-a"], "banˇana")
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_increment_steps(cx: &mut gpui::TestAppContext) { async fn test_increment_steps(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.set_shared_state(indoc! {" cx.set_shared_state(indoc! {"
// ˇ1 ˇ1
// 1 1
// 1 2 1 2
// 1 1
// 1"}) 1"})
// .await; .await;
// cx.simulate_shared_keystrokes(["j", "v", "shift-g", "g", "ctrl-a"]) cx.simulate_shared_keystrokes(["j", "v", "shift-g", "g", "ctrl-a"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// 1 1
// ˇ2 ˇ2
// 3 2 3 2
// 4 4
// 5"}) 5"})
// .await; .await;
// cx.simulate_shared_keystrokes(["shift-g", "ctrl-v", "g", "g"]) cx.simulate_shared_keystrokes(["shift-g", "ctrl-v", "g", "g"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// «1ˇ» «1ˇ»
// «2ˇ» «2ˇ»
// «3ˇ» 2 «3ˇ» 2
// «4ˇ» «4ˇ»
// «5ˇ»"}) «5ˇ»"})
// .await; .await;
// cx.simulate_shared_keystrokes(["g", "ctrl-x"]).await; cx.simulate_shared_keystrokes(["g", "ctrl-x"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// ˇ0 ˇ0
// 0 0
// 0 2 0 2
// 0 0
// 0"}) 0"})
// .await; .await;
// } }
// } }

View file

@ -197,280 +197,280 @@ fn paste(_: &mut Workspace, action: &Paste, cx: &mut ViewContext<Workspace>) {
}); });
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use crate::{ use crate::{
// state::Mode, state::Mode,
// test::{NeovimBackedTestContext, VimTestContext}, test::{NeovimBackedTestContext, VimTestContext},
// }; };
// use indoc::indoc; use indoc::indoc;
// #[gpui::test] #[gpui::test]
// async fn test_paste(cx: &mut gpui::TestAppContext) { async fn test_paste(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// // single line // single line
// 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(["v", "w", "y"]).await; cx.simulate_shared_keystrokes(["v", "w", "y"]).await;
// cx.assert_shared_clipboard("jumps o").await; cx.assert_shared_clipboard("jumps o").await;
// cx.set_shared_state(indoc! {" cx.set_shared_state(indoc! {"
// The quick brown The quick brown
// fox jumps oveˇr fox jumps oveˇr
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.simulate_shared_keystroke("p").await; cx.simulate_shared_keystroke("p").await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// fox jumps overjumps ˇo fox jumps overjumps ˇo
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.set_shared_state(indoc! {" cx.set_shared_state(indoc! {"
// The quick brown The quick brown
// fox jumps oveˇr fox jumps oveˇr
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.simulate_shared_keystroke("shift-p").await; cx.simulate_shared_keystroke("shift-p").await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// fox jumps ovejumps ˇor fox jumps ovejumps ˇor
// the lazy dog"}) the lazy dog"})
// .await; .await;
// // line mode // line mode
// cx.set_shared_state(indoc! {" cx.set_shared_state(indoc! {"
// The quick brown The quick brown
// fox juˇmps over fox juˇmps over
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.simulate_shared_keystrokes(["d", "d"]).await; cx.simulate_shared_keystrokes(["d", "d"]).await;
// cx.assert_shared_clipboard("fox jumps over\n").await; cx.assert_shared_clipboard("fox jumps over\n").await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// the laˇzy dog"}) the laˇzy dog"})
// .await; .await;
// cx.simulate_shared_keystroke("p").await; cx.simulate_shared_keystroke("p").await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// the lazy dog the lazy dog
// ˇfox jumps over"}) ˇfox jumps over"})
// .await; .await;
// cx.simulate_shared_keystrokes(["k", "shift-p"]).await; cx.simulate_shared_keystrokes(["k", "shift-p"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// ˇfox jumps over ˇfox jumps over
// the lazy dog the lazy dog
// fox jumps over"}) fox jumps over"})
// .await; .await;
// // multiline, cursor to first character of pasted text. // multiline, cursor to first character of pasted text.
// 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(["v", "j", "y"]).await; cx.simulate_shared_keystrokes(["v", "j", "y"]).await;
// cx.assert_shared_clipboard("over\nthe lazy do").await; cx.assert_shared_clipboard("over\nthe lazy do").await;
// cx.simulate_shared_keystroke("p").await; cx.simulate_shared_keystroke("p").await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// fox jumps oˇover fox jumps oˇover
// the lazy dover the lazy dover
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.simulate_shared_keystrokes(["u", "shift-p"]).await; cx.simulate_shared_keystrokes(["u", "shift-p"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// fox jumps ˇover fox jumps ˇover
// the lazy doover the lazy doover
// the lazy dog"}) the lazy dog"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_paste_visual(cx: &mut gpui::TestAppContext) { async fn test_paste_visual(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// // copy in visual mode // copy in visual mode
// cx.set_shared_state(indoc! {" cx.set_shared_state(indoc! {"
// The quick brown The quick brown
// fox jˇumps over fox jˇumps over
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "i", "w", "y"]).await; cx.simulate_shared_keystrokes(["v", "i", "w", "y"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// fox ˇjumps over fox ˇjumps over
// the lazy dog"}) the lazy dog"})
// .await; .await;
// // paste in visual mode // paste in visual mode
// cx.simulate_shared_keystrokes(["w", "v", "i", "w", "p"]) cx.simulate_shared_keystrokes(["w", "v", "i", "w", "p"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// fox jumps jumpˇs fox jumps jumpˇs
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.assert_shared_clipboard("over").await; cx.assert_shared_clipboard("over").await;
// // paste in visual line mode // paste in visual line mode
// cx.simulate_shared_keystrokes(["up", "shift-v", "shift-p"]) cx.simulate_shared_keystrokes(["up", "shift-v", "shift-p"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// ˇover ˇover
// fox jumps jumps fox jumps jumps
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.assert_shared_clipboard("over").await; cx.assert_shared_clipboard("over").await;
// // paste in visual block mode // paste in visual block mode
// cx.simulate_shared_keystrokes(["ctrl-v", "down", "down", "p"]) cx.simulate_shared_keystrokes(["ctrl-v", "down", "down", "p"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// oveˇrver oveˇrver
// overox jumps jumps overox jumps jumps
// overhe lazy dog"}) overhe lazy dog"})
// .await; .await;
// // copy in visual line mode // copy in visual line mode
// cx.set_shared_state(indoc! {" cx.set_shared_state(indoc! {"
// The quick brown The quick brown
// fox juˇmps over fox juˇmps over
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.simulate_shared_keystrokes(["shift-v", "d"]).await; cx.simulate_shared_keystrokes(["shift-v", "d"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// the laˇzy dog"}) the laˇzy dog"})
// .await; .await;
// // paste in visual mode // paste in visual mode
// cx.simulate_shared_keystrokes(["v", "i", "w", "p"]).await; cx.simulate_shared_keystrokes(["v", "i", "w", "p"]).await;
// cx.assert_shared_state( cx.assert_shared_state(
// &indoc! {" &indoc! {"
// The quick brown The quick brown
// the_ the_
// ˇfox jumps over ˇfox jumps over
// _dog"} _dog"}
// .replace("_", " "), // Hack for trailing whitespace .replace("_", " "), // Hack for trailing whitespace
// ) )
// .await; .await;
// cx.assert_shared_clipboard("lazy").await; cx.assert_shared_clipboard("lazy").await;
// cx.set_shared_state(indoc! {" cx.set_shared_state(indoc! {"
// The quick brown The quick brown
// fox juˇmps over fox juˇmps over
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.simulate_shared_keystrokes(["shift-v", "d"]).await; cx.simulate_shared_keystrokes(["shift-v", "d"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// the laˇzy dog"}) the laˇzy dog"})
// .await; .await;
// // paste in visual line mode // paste in visual line mode
// cx.simulate_shared_keystrokes(["k", "shift-v", "p"]).await; cx.simulate_shared_keystrokes(["k", "shift-v", "p"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// ˇfox jumps over ˇfox jumps over
// the lazy dog"}) the lazy dog"})
// .await; .await;
// cx.assert_shared_clipboard("The quick brown\n").await; cx.assert_shared_clipboard("The quick brown\n").await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_paste_visual_block(cx: &mut gpui::TestAppContext) { async fn test_paste_visual_block(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// // copy in visual block mode // copy in visual block 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", "2", "j", "y"]) cx.simulate_shared_keystrokes(["ctrl-v", "2", "j", "y"])
// .await; .await;
// cx.assert_shared_clipboard("q\nj\nl").await; cx.assert_shared_clipboard("q\nj\nl").await;
// cx.simulate_shared_keystrokes(["p"]).await; cx.simulate_shared_keystrokes(["p"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The qˇquick brown The qˇquick brown
// fox jjumps over fox jjumps over
// the llazy dog"}) the llazy dog"})
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "i", "w", "shift-p"]) cx.simulate_shared_keystrokes(["v", "i", "w", "shift-p"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The ˇq brown The ˇq brown
// fox jjjumps over fox jjjumps over
// the lllazy dog"}) the lllazy dog"})
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "i", "w", "shift-p"]) cx.simulate_shared_keystrokes(["v", "i", "w", "shift-p"])
// .await; .await;
// 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", "y"]).await; cx.simulate_shared_keystrokes(["ctrl-v", "j", "y"]).await;
// cx.assert_shared_clipboard("q\nj").await; cx.assert_shared_clipboard("q\nj").await;
// cx.simulate_shared_keystrokes(["l", "ctrl-v", "2", "j", "shift-p"]) cx.simulate_shared_keystrokes(["l", "ctrl-v", "2", "j", "shift-p"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The qˇqick brown The qˇqick brown
// fox jjmps over fox jjmps over
// the lzy dog"}) the lzy dog"})
// .await; .await;
// cx.simulate_shared_keystrokes(["shift-v", "p"]).await; cx.simulate_shared_keystrokes(["shift-v", "p"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// ˇq ˇq
// j j
// fox jjmps over fox jjmps over
// the lzy dog"}) the lzy dog"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_paste_indent(cx: &mut gpui::TestAppContext) { async fn test_paste_indent(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new_typescript(cx).await; let mut cx = VimTestContext::new_typescript(cx).await;
// cx.set_state( cx.set_state(
// indoc! {" indoc! {"
// class A {ˇ class A {ˇ
// } }
// "}, "},
// Mode::Normal, Mode::Normal,
// ); );
// cx.simulate_keystrokes(["o", "a", "(", ")", "{", "escape"]); cx.simulate_keystrokes(["o", "a", "(", ")", "{", "escape"]);
// cx.assert_state( cx.assert_state(
// indoc! {" indoc! {"
// class A { class A {
// a()ˇ{} a()ˇ{}
// } }
// "}, "},
// Mode::Normal, Mode::Normal,
// ); );
// // cursor goes to the first non-blank character in the line; // cursor goes to the first non-blank character in the line;
// cx.simulate_keystrokes(["y", "y", "p"]); cx.simulate_keystrokes(["y", "y", "p"]);
// cx.assert_state( cx.assert_state(
// indoc! {" indoc! {"
// class A { class A {
// a(){} a(){}
// ˇa(){} ˇa(){}
// } }
// "}, "},
// Mode::Normal, Mode::Normal,
// ); );
// // indentation is preserved when pasting // indentation is preserved when pasting
// cx.simulate_keystrokes(["u", "shift-v", "up", "y", "shift-p"]); cx.simulate_keystrokes(["u", "shift-v", "up", "y", "shift-p"]);
// cx.assert_state( cx.assert_state(
// indoc! {" indoc! {"
// ˇclass A { ˇclass A {
// a(){} a(){}
// class A { class A {
// a(){} a(){}
// } }
// "}, "},
// Mode::Normal, Mode::Normal,
// ); );
// } }
// } }

View file

@ -81,196 +81,196 @@ pub fn substitute(vim: &mut Vim, count: Option<usize>, line_mode: bool, cx: &mut
vim.switch_mode(Mode::Insert, true, cx); vim.switch_mode(Mode::Insert, true, cx);
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use crate::{ use crate::{
// state::Mode, state::Mode,
// test::{NeovimBackedTestContext, VimTestContext}, test::{NeovimBackedTestContext, VimTestContext},
// }; };
// use indoc::indoc; use indoc::indoc;
// #[gpui::test] #[gpui::test]
// async fn test_substitute(cx: &mut gpui::TestAppContext) { async fn test_substitute(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, true).await; let mut cx = VimTestContext::new(cx, true).await;
// // supports a single cursor // supports a single cursor
// cx.set_state(indoc! {"ˇabc\n"}, Mode::Normal); cx.set_state(indoc! {"ˇabc\n"}, Mode::Normal);
// cx.simulate_keystrokes(["s", "x"]); cx.simulate_keystrokes(["s", "x"]);
// cx.assert_editor_state("xˇbc\n"); cx.assert_editor_state("xˇbc\n");
// // supports a selection // supports a selection
// cx.set_state(indoc! {"a«bcˇ»\n"}, Mode::Visual); cx.set_state(indoc! {"a«bcˇ»\n"}, Mode::Visual);
// cx.assert_editor_state("a«bcˇ»\n"); cx.assert_editor_state("a«bcˇ»\n");
// cx.simulate_keystrokes(["s", "x"]); cx.simulate_keystrokes(["s", "x"]);
// cx.assert_editor_state("axˇ\n"); cx.assert_editor_state("axˇ\n");
// // supports counts // supports counts
// cx.set_state(indoc! {"ˇabc\n"}, Mode::Normal); cx.set_state(indoc! {"ˇabc\n"}, Mode::Normal);
// cx.simulate_keystrokes(["2", "s", "x"]); cx.simulate_keystrokes(["2", "s", "x"]);
// cx.assert_editor_state("xˇc\n"); cx.assert_editor_state("xˇc\n");
// // supports multiple cursors // supports multiple cursors
// cx.set_state(indoc! {"a«bcˇ»deˇffg\n"}, Mode::Normal); cx.set_state(indoc! {"a«bcˇ»deˇffg\n"}, Mode::Normal);
// cx.simulate_keystrokes(["2", "s", "x"]); cx.simulate_keystrokes(["2", "s", "x"]);
// cx.assert_editor_state("axˇdexˇg\n"); cx.assert_editor_state("axˇdexˇg\n");
// // does not read beyond end of line // does not read beyond end of line
// cx.set_state(indoc! {"ˇabc\n"}, Mode::Normal); cx.set_state(indoc! {"ˇabc\n"}, Mode::Normal);
// cx.simulate_keystrokes(["5", "s", "x"]); cx.simulate_keystrokes(["5", "s", "x"]);
// cx.assert_editor_state("xˇ\n"); cx.assert_editor_state("\n");
// // it handles multibyte characters // it handles multibyte characters
// cx.set_state(indoc! {"ˇcàfé\n"}, Mode::Normal); cx.set_state(indoc! {"ˇcàfé\n"}, Mode::Normal);
// cx.simulate_keystrokes(["4", "s"]); cx.simulate_keystrokes(["4", "s"]);
// cx.assert_editor_state("ˇ\n"); cx.assert_editor_state("ˇ\n");
// // should transactionally undo selection changes // should transactionally undo selection changes
// cx.simulate_keystrokes(["escape", "u"]); cx.simulate_keystrokes(["escape", "u"]);
// cx.assert_editor_state("ˇcàfé\n"); cx.assert_editor_state("ˇcàfé\n");
// // it handles visual line mode // it handles visual line mode
// cx.set_state( cx.set_state(
// indoc! {" indoc! {"
// alpha alpha
// beˇta beˇta
// gamma"}, gamma"},
// Mode::Normal, Mode::Normal,
// ); );
// cx.simulate_keystrokes(["shift-v", "s"]); cx.simulate_keystrokes(["shift-v", "s"]);
// cx.assert_editor_state(indoc! {" cx.assert_editor_state(indoc! {"
// alpha alpha
// ˇ ˇ
// gamma"}); gamma"});
// } }
// #[gpui::test] #[gpui::test]
// async fn test_visual_change(cx: &mut gpui::TestAppContext) { async fn test_visual_change(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.set_shared_state("The quick ˇbrown").await; cx.set_shared_state("The quick ˇbrown").await;
// cx.simulate_shared_keystrokes(["v", "w", "c"]).await; cx.simulate_shared_keystrokes(["v", "w", "c"]).await;
// cx.assert_shared_state("The quick ˇ").await; cx.assert_shared_state("The quick ˇ").await;
// 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(["v", "w", "j", "c"]).await; cx.simulate_shared_keystrokes(["v", "w", "j", "c"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The ˇver The ˇver
// the lazy dog"}) the lazy dog"})
// .await; .await;
// let cases = cx.each_marked_position(indoc! {" let cases = cx.each_marked_position(indoc! {"
// The ˇquick brown The ˇquick brown
// fox jumps ˇover fox jumps ˇover
// the ˇlazy dog"}); the ˇlazy dog"});
// for initial_state in cases { for initial_state in cases {
// cx.assert_neovim_compatible(&initial_state, ["v", "w", "j", "c"]) cx.assert_neovim_compatible(&initial_state, ["v", "w", "j", "c"])
// .await; .await;
// cx.assert_neovim_compatible(&initial_state, ["v", "w", "k", "c"]) cx.assert_neovim_compatible(&initial_state, ["v", "w", "k", "c"])
// .await; .await;
// } }
// } }
// #[gpui::test] #[gpui::test]
// async fn test_visual_line_change(cx: &mut gpui::TestAppContext) { async fn test_visual_line_change(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx) let mut cx = NeovimBackedTestContext::new(cx)
// .await .await
// .binding(["shift-v", "c"]); .binding(["shift-v", "c"]);
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quˇick brown The quˇick brown
// fox jumps over fox jumps over
// the lazy dog"}) the lazy dog"})
// .await; .await;
// // Test pasting code copied on change // Test pasting code copied on change
// cx.simulate_shared_keystrokes(["escape", "j", "p"]).await; cx.simulate_shared_keystrokes(["escape", "j", "p"]).await;
// cx.assert_state_matches().await; cx.assert_state_matches().await;
// cx.assert_all(indoc! {" cx.assert_all(indoc! {"
// The quick brown The quick brown
// fox juˇmps over fox juˇmps over
// the laˇzy dog"}) the laˇzy dog"})
// .await; .await;
// let mut cx = cx.binding(["shift-v", "j", "c"]); let mut cx = cx.binding(["shift-v", "j", "c"]);
// cx.assert(indoc! {" cx.assert(indoc! {"
// The quˇick brown The quˇick brown
// fox jumps over fox jumps over
// the lazy dog"}) the lazy dog"})
// .await; .await;
// // Test pasting code copied on delete // Test pasting code copied on delete
// cx.simulate_shared_keystrokes(["escape", "j", "p"]).await; cx.simulate_shared_keystrokes(["escape", "j", "p"]).await;
// cx.assert_state_matches().await; cx.assert_state_matches().await;
// cx.assert_all(indoc! {" cx.assert_all(indoc! {"
// The quick brown The quick brown
// fox juˇmps over fox juˇmps over
// the laˇzy dog"}) the laˇzy dog"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_substitute_line(cx: &mut gpui::TestAppContext) { async fn test_substitute_line(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// let initial_state = indoc! {" let initial_state = indoc! {"
// The quick brown The quick brown
// fox juˇmps over fox juˇmps over
// the lazy dog the lazy dog
// "}; "};
// // normal mode // normal mode
// cx.set_shared_state(initial_state).await; cx.set_shared_state(initial_state).await;
// cx.simulate_shared_keystrokes(["shift-s", "o"]).await; cx.simulate_shared_keystrokes(["shift-s", "o"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// oˇ
// the lazy dog the lazy dog
// "}) "})
// .await; .await;
// // visual mode // visual mode
// cx.set_shared_state(initial_state).await; cx.set_shared_state(initial_state).await;
// cx.simulate_shared_keystrokes(["v", "k", "shift-s", "o"]) cx.simulate_shared_keystrokes(["v", "k", "shift-s", "o"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// oˇ
// the lazy dog the lazy dog
// "}) "})
// .await; .await;
// // visual block mode // visual block mode
// cx.set_shared_state(initial_state).await; cx.set_shared_state(initial_state).await;
// cx.simulate_shared_keystrokes(["ctrl-v", "j", "shift-s", "o"]) cx.simulate_shared_keystrokes(["ctrl-v", "j", "shift-s", "o"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// oˇ
// "}) "})
// .await; .await;
// // visual mode including newline // visual mode including newline
// cx.set_shared_state(initial_state).await; cx.set_shared_state(initial_state).await;
// cx.simulate_shared_keystrokes(["v", "$", "shift-s", "o"]) cx.simulate_shared_keystrokes(["v", "$", "shift-s", "o"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// oˇ
// the lazy dog the lazy dog
// "}) "})
// .await; .await;
// // indentation // indentation
// cx.set_neovim_option("shiftwidth=4").await; cx.set_neovim_option("shiftwidth=4").await;
// cx.set_shared_state(initial_state).await; cx.set_shared_state(initial_state).await;
// cx.simulate_shared_keystrokes([">", ">", "shift-s", "o"]) cx.simulate_shared_keystrokes([">", ">", "shift-s", "o"])
// .await; .await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// The quick brown The quick brown
// oˇ
// the lazy dog the lazy dog
// "}) "})
// .await; .await;
// } }
// } }

View file

@ -140,6 +140,8 @@ pub fn observe_keystrokes(cx: &mut WindowContext) {
if action.name().starts_with("vim::") { if action.name().starts_with("vim::") {
return; return;
} }
} else if cx.has_pending_keystrokes() {
return;
} }
Vim::update(cx, |vim, cx| match vim.active_operator() { Vim::update(cx, |vim, cx| match vim.active_operator() {