- MOAR TESTS

[[PR Description]]

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2023-12-11 16:42:03 -07:00 committed by GitHub
commit 149e90c3d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 2820 additions and 2809 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

@ -1468,6 +1468,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

@ -36,100 +36,90 @@ fn normal_before(_: &mut Workspace, action: &NormalBefore, cx: &mut ViewContext<
} }
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use std::sync::Arc; use crate::{
state::Mode,
test::{NeovimBackedTestContext, VimTestContext},
};
// use gpui::executor::Deterministic; #[gpui::test]
async fn test_enter_and_exit_insert_mode(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
cx.simulate_keystroke("i");
assert_eq!(cx.mode(), Mode::Insert);
cx.simulate_keystrokes(["T", "e", "s", "t"]);
cx.assert_editor_state("Testˇ");
cx.simulate_keystroke("escape");
assert_eq!(cx.mode(), Mode::Normal);
cx.assert_editor_state("Tesˇt");
}
// use crate::{ #[gpui::test]
// state::Mode, async fn test_insert_with_counts(cx: &mut gpui::TestAppContext) {
// test::{NeovimBackedTestContext, VimTestContext}, let mut cx = NeovimBackedTestContext::new(cx).await;
// };
// #[gpui::test] cx.set_shared_state("ˇhello\n").await;
// async fn test_enter_and_exit_insert_mode(cx: &mut gpui::TestAppContext) { cx.simulate_shared_keystrokes(["5", "i", "-", "escape"])
// let mut cx = VimTestContext::new(cx, true).await; .await;
// cx.simulate_keystroke("i"); cx.run_until_parked();
// assert_eq!(cx.mode(), Mode::Insert); cx.assert_shared_state("----ˇ-hello\n").await;
// cx.simulate_keystrokes(["T", "e", "s", "t"]);
// cx.assert_editor_state("Testˇ");
// cx.simulate_keystroke("escape");
// assert_eq!(cx.mode(), Mode::Normal);
// cx.assert_editor_state("Tesˇt");
// }
// #[gpui::test] cx.set_shared_state("ˇhello\n").await;
// async fn test_insert_with_counts( cx.simulate_shared_keystrokes(["5", "a", "-", "escape"])
// deterministic: Arc<Deterministic>, .await;
// cx: &mut gpui::TestAppContext, cx.run_until_parked();
// ) { cx.assert_shared_state("h----ˇ-ello\n").await;
// let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.set_shared_state("ˇhello\n").await; cx.simulate_shared_keystrokes(["4", "shift-i", "-", "escape"])
// cx.simulate_shared_keystrokes(["5", "i", "-", "escape"]) .await;
// .await; cx.run_until_parked();
// deterministic.run_until_parked(); cx.assert_shared_state("---ˇ-h-----ello\n").await;
// cx.assert_shared_state("----ˇ-hello\n").await;
// cx.set_shared_state("ˇhello\n").await; cx.simulate_shared_keystrokes(["3", "shift-a", "-", "escape"])
// cx.simulate_shared_keystrokes(["5", "a", "-", "escape"]) .await;
// .await; cx.run_until_parked();
// deterministic.run_until_parked(); cx.assert_shared_state("----h-----ello--ˇ-\n").await;
// cx.assert_shared_state("h----ˇ-ello\n").await;
// cx.simulate_shared_keystrokes(["4", "shift-i", "-", "escape"]) cx.set_shared_state("ˇhello\n").await;
// .await; cx.simulate_shared_keystrokes(["3", "o", "o", "i", "escape"])
// deterministic.run_until_parked(); .await;
// cx.assert_shared_state("---ˇ-h-----ello\n").await; cx.run_until_parked();
cx.assert_shared_state("hello\noi\noi\noˇi\n").await;
// cx.simulate_shared_keystrokes(["3", "shift-a", "-", "escape"]) cx.set_shared_state("ˇhello\n").await;
// .await; cx.simulate_shared_keystrokes(["3", "shift-o", "o", "i", "escape"])
// deterministic.run_until_parked(); .await;
// cx.assert_shared_state("----h-----ello--ˇ-\n").await; cx.run_until_parked();
cx.assert_shared_state("oi\noi\noˇi\nhello\n").await;
}
// cx.set_shared_state("ˇhello\n").await; #[gpui::test]
// cx.simulate_shared_keystrokes(["3", "o", "o", "i", "escape"]) async fn test_insert_with_repeat(cx: &mut gpui::TestAppContext) {
// .await; let mut cx = NeovimBackedTestContext::new(cx).await;
// deterministic.run_until_parked();
// cx.assert_shared_state("hello\noi\noi\noˇi\n").await;
// cx.set_shared_state("ˇhello\n").await; cx.set_shared_state("ˇhello\n").await;
// cx.simulate_shared_keystrokes(["3", "shift-o", "o", "i", "escape"]) cx.simulate_shared_keystrokes(["3", "i", "-", "escape"])
// .await; .await;
// deterministic.run_until_parked(); cx.run_until_parked();
// cx.assert_shared_state("oi\noi\noˇi\nhello\n").await; cx.assert_shared_state("--ˇ-hello\n").await;
// } cx.simulate_shared_keystrokes(["."]).await;
cx.run_until_parked();
cx.assert_shared_state("----ˇ--hello\n").await;
cx.simulate_shared_keystrokes(["2", "."]).await;
cx.run_until_parked();
cx.assert_shared_state("-----ˇ---hello\n").await;
// #[gpui::test] cx.set_shared_state("ˇhello\n").await;
// async fn test_insert_with_repeat( cx.simulate_shared_keystrokes(["2", "o", "k", "k", "escape"])
// deterministic: Arc<Deterministic>, .await;
// cx: &mut gpui::TestAppContext, cx.run_until_parked();
// ) { cx.assert_shared_state("hello\nkk\nkˇk\n").await;
// let mut cx = NeovimBackedTestContext::new(cx).await; cx.simulate_shared_keystrokes(["."]).await;
cx.run_until_parked();
// cx.set_shared_state("ˇhello\n").await; cx.assert_shared_state("hello\nkk\nkk\nkk\nkˇk\n").await;
// cx.simulate_shared_keystrokes(["3", "i", "-", "escape"]) cx.simulate_shared_keystrokes(["1", "."]).await;
// .await; cx.run_until_parked();
// deterministic.run_until_parked(); cx.assert_shared_state("hello\nkk\nkk\nkk\nkk\nkˇk\n").await;
// cx.assert_shared_state("--ˇ-hello\n").await; }
// cx.simulate_shared_keystrokes(["."]).await; }
// deterministic.run_until_parked();
// cx.assert_shared_state("----ˇ--hello\n").await;
// cx.simulate_shared_keystrokes(["2", "."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state("-----ˇ---hello\n").await;
// cx.set_shared_state("ˇhello\n").await;
// cx.simulate_shared_keystrokes(["2", "o", "k", "k", "escape"])
// .await;
// deterministic.run_until_parked();
// cx.assert_shared_state("hello\nkk\nkˇk\n").await;
// cx.simulate_shared_keystrokes(["."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state("hello\nkk\nkk\nkk\nkˇk\n").await;
// cx.simulate_shared_keystrokes(["1", "."]).await;
// deterministic.run_until_parked();
// cx.assert_shared_state("hello\nkk\nkk\nkk\nkk\nkˇk\n").await;
// }
// }

View file

@ -952,147 +952,156 @@ pub(crate) fn next_line_end(
end_of_line(map, false, point) end_of_line(map, false, point)
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use crate::test::NeovimBackedTestContext; use crate::test::NeovimBackedTestContext;
// use indoc::indoc; use indoc::indoc;
// #[gpui::test] #[gpui::test]
// async fn test_start_end_of_paragraph(cx: &mut gpui::TestAppContext) { async fn test_start_end_of_paragraph(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// let initial_state = indoc! {r"ˇabc let initial_state = indoc! {r"ˇabc
// def def
// paragraph paragraph
// the second the second
// third and
// final"};
// // goes down once
// cx.set_shared_state(initial_state).await;
// cx.simulate_shared_keystrokes(["}"]).await;
// cx.assert_shared_state(indoc! {r"abc
// def
// ˇ
// paragraph
// the second
// third and third and
// final"}) final"};
// .await;
// // goes up once // goes down once
// cx.simulate_shared_keystrokes(["{"]).await; cx.set_shared_state(initial_state).await;
// cx.assert_shared_state(initial_state).await; cx.simulate_shared_keystrokes(["}"]).await;
cx.assert_shared_state(indoc! {r"abc
def
ˇ
paragraph
the second
// // goes down twice
// cx.simulate_shared_keystrokes(["2", "}"]).await;
// cx.assert_shared_state(indoc! {r"abc
// def
// paragraph
// the second
// ˇ
// third and third and
// final"}) final"})
// .await; .await;
// // goes down over multiple blanks // goes up once
// cx.simulate_shared_keystrokes(["}"]).await; cx.simulate_shared_keystrokes(["{"]).await;
// cx.assert_shared_state(indoc! {r"abc cx.assert_shared_state(initial_state).await;
// def
// paragraph // goes down twice
// the second cx.simulate_shared_keystrokes(["2", "}"]).await;
cx.assert_shared_state(indoc! {r"abc
def
// third and paragraph
// finaˇl"}) the second
// .await; ˇ
// // goes up twice
// cx.simulate_shared_keystrokes(["2", "{"]).await;
// cx.assert_shared_state(indoc! {r"abc
// def
// ˇ
// paragraph
// the second
// third and third and
// final"}) final"})
// .await .await;
// }
// #[gpui::test] // goes down over multiple blanks
// async fn test_matching(cx: &mut gpui::TestAppContext) { cx.simulate_shared_keystrokes(["}"]).await;
// let mut cx = NeovimBackedTestContext::new(cx).await; cx.assert_shared_state(indoc! {r"abc
def
// cx.set_shared_state(indoc! {r"func ˇ(a string) { paragraph
// do(something(with<Types>.and_arrays[0, 2])) the second
// }"})
// .await;
// cx.simulate_shared_keystrokes(["%"]).await;
// cx.assert_shared_state(indoc! {r"func (a stringˇ) {
// do(something(with<Types>.and_arrays[0, 2]))
// }"})
// .await;
// // test it works on the last character of the line
// cx.set_shared_state(indoc! {r"func (a string) ˇ{
// do(something(with<Types>.and_arrays[0, 2]))
// }"})
// .await;
// cx.simulate_shared_keystrokes(["%"]).await;
// cx.assert_shared_state(indoc! {r"func (a string) {
// do(something(with<Types>.and_arrays[0, 2]))
// ˇ}"})
// .await;
// // test it works on immediate nesting
// cx.set_shared_state("ˇ{()}").await;
// cx.simulate_shared_keystrokes(["%"]).await;
// cx.assert_shared_state("{()ˇ}").await;
// cx.simulate_shared_keystrokes(["%"]).await;
// cx.assert_shared_state("ˇ{()}").await;
// // test it works on immediate nesting inside braces third and
// cx.set_shared_state("{\n ˇ{()}\n}").await; finaˇl"})
// cx.simulate_shared_keystrokes(["%"]).await; .await;
// cx.assert_shared_state("{\n {()ˇ}\n}").await;
// // test it jumps to the next paren on a line // goes up twice
// cx.set_shared_state("func ˇboop() {\n}").await; cx.simulate_shared_keystrokes(["2", "{"]).await;
// cx.simulate_shared_keystrokes(["%"]).await; cx.assert_shared_state(indoc! {r"abc
// cx.assert_shared_state("func boop(ˇ) {\n}").await; def
// } ˇ
paragraph
the second
// #[gpui::test]
// async fn test_comma_semicolon(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.set_shared_state("ˇone two three four").await;
// cx.simulate_shared_keystrokes(["f", "o"]).await;
// cx.assert_shared_state("one twˇo three four").await;
// cx.simulate_shared_keystrokes([","]).await;
// cx.assert_shared_state("ˇone two three four").await;
// cx.simulate_shared_keystrokes(["2", ";"]).await;
// cx.assert_shared_state("one two three fˇour").await;
// cx.simulate_shared_keystrokes(["shift-t", "e"]).await;
// cx.assert_shared_state("one two threeˇ four").await;
// cx.simulate_shared_keystrokes(["3", ";"]).await;
// cx.assert_shared_state("oneˇ two three four").await;
// cx.simulate_shared_keystrokes([","]).await;
// cx.assert_shared_state("one two thˇree four").await;
// }
// #[gpui::test] third and
// async fn test_next_line_start(cx: &mut gpui::TestAppContext) { final"})
// let mut cx = NeovimBackedTestContext::new(cx).await; .await
// cx.set_shared_state("ˇone\n two\nthree").await; }
// cx.simulate_shared_keystrokes(["enter"]).await;
// cx.assert_shared_state("one\n ˇtwo\nthree").await; #[gpui::test]
// } async fn test_matching(cx: &mut gpui::TestAppContext) {
// } let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state(indoc! {r"func ˇ(a string) {
do(something(with<Types>.and_arrays[0, 2]))
}"})
.await;
cx.simulate_shared_keystrokes(["%"]).await;
cx.assert_shared_state(indoc! {r"func (a stringˇ) {
do(something(with<Types>.and_arrays[0, 2]))
}"})
.await;
// test it works on the last character of the line
cx.set_shared_state(indoc! {r"func (a string) ˇ{
do(something(with<Types>.and_arrays[0, 2]))
}"})
.await;
cx.simulate_shared_keystrokes(["%"]).await;
cx.assert_shared_state(indoc! {r"func (a string) {
do(something(with<Types>.and_arrays[0, 2]))
ˇ}"})
.await;
// test it works on immediate nesting
cx.set_shared_state("ˇ{()}").await;
cx.simulate_shared_keystrokes(["%"]).await;
cx.assert_shared_state("{()ˇ}").await;
cx.simulate_shared_keystrokes(["%"]).await;
cx.assert_shared_state("ˇ{()}").await;
// test it works on immediate nesting inside braces
cx.set_shared_state("{\n ˇ{()}\n}").await;
cx.simulate_shared_keystrokes(["%"]).await;
cx.assert_shared_state("{\n {()ˇ}\n}").await;
// test it jumps to the next paren on a line
cx.set_shared_state("func ˇboop() {\n}").await;
cx.simulate_shared_keystrokes(["%"]).await;
cx.assert_shared_state("func boop(ˇ) {\n}").await;
}
#[gpui::test]
async fn test_comma_semicolon(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state("ˇone two three four").await;
cx.simulate_shared_keystrokes(["f", "o"]).await;
cx.assert_shared_state("one twˇo three four").await;
cx.simulate_shared_keystrokes([","]).await;
cx.assert_shared_state("ˇone two three four").await;
cx.simulate_shared_keystrokes(["2", ";"]).await;
cx.assert_shared_state("one two three fˇour").await;
cx.simulate_shared_keystrokes(["shift-t", "e"]).await;
cx.assert_shared_state("one two threeˇ four").await;
cx.simulate_shared_keystrokes(["3", ";"]).await;
cx.assert_shared_state("oneˇ two three four").await;
cx.simulate_shared_keystrokes([","]).await;
cx.assert_shared_state("one two thˇree four").await;
}
#[gpui::test]
async fn test_next_line_start(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state("ˇone\n two\nthree").await;
cx.simulate_shared_keystrokes(["enter"]).await;
cx.assert_shared_state("one\n ˇtwo\nthree").await;
}
}

View file

@ -74,43 +74,43 @@ pub fn change_case(_: &mut Workspace, _: &ChangeCase, cx: &mut ViewContext<Works
vim.switch_mode(Mode::Normal, true, cx) vim.switch_mode(Mode::Normal, true, cx)
}) })
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use crate::{state::Mode, test::NeovimBackedTestContext}; use crate::{state::Mode, test::NeovimBackedTestContext};
// #[gpui::test] #[gpui::test]
// async fn test_change_case(cx: &mut gpui::TestAppContext) { async fn test_change_case(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.set_shared_state("ˇabC\n").await; cx.set_shared_state("ˇabC\n").await;
// cx.simulate_shared_keystrokes(["~"]).await; cx.simulate_shared_keystrokes(["~"]).await;
// cx.assert_shared_state("AˇbC\n").await; cx.assert_shared_state("AˇbC\n").await;
// cx.simulate_shared_keystrokes(["2", "~"]).await; cx.simulate_shared_keystrokes(["2", "~"]).await;
// cx.assert_shared_state("ABˇc\n").await; cx.assert_shared_state("ABˇc\n").await;
// // works in visual mode // works in visual mode
// cx.set_shared_state("a😀C«dÉ1*fˇ»\n").await; cx.set_shared_state("a😀C«dÉ1*fˇ»\n").await;
// cx.simulate_shared_keystrokes(["~"]).await; cx.simulate_shared_keystrokes(["~"]).await;
// cx.assert_shared_state("a😀CˇDé1*F\n").await; cx.assert_shared_state("a😀CˇDé1*F\n").await;
// // works with multibyte characters // works with multibyte characters
// cx.simulate_shared_keystrokes(["~"]).await; cx.simulate_shared_keystrokes(["~"]).await;
// cx.set_shared_state("aˇC😀é1*F\n").await; cx.set_shared_state("aˇC😀é1*F\n").await;
// cx.simulate_shared_keystrokes(["4", "~"]).await; cx.simulate_shared_keystrokes(["4", "~"]).await;
// cx.assert_shared_state("ac😀É1ˇ*F\n").await; cx.assert_shared_state("ac😀É1ˇ*F\n").await;
// // works with line selections // works with line selections
// cx.set_shared_state("abˇC\n").await; cx.set_shared_state("abˇC\n").await;
// cx.simulate_shared_keystrokes(["shift-v", "~"]).await; cx.simulate_shared_keystrokes(["shift-v", "~"]).await;
// cx.assert_shared_state("ˇABc\n").await; cx.assert_shared_state("ˇABc\n").await;
// // works in visual block mode // works in visual block mode
// cx.set_shared_state("ˇaa\nbb\ncc").await; cx.set_shared_state("ˇaa\nbb\ncc").await;
// cx.simulate_shared_keystrokes(["ctrl-v", "j", "~"]).await; cx.simulate_shared_keystrokes(["ctrl-v", "j", "~"]).await;
// cx.assert_shared_state("ˇAa\nBb\ncc").await; cx.assert_shared_state("ˇAa\nBb\ncc").await;
// // works with multiple cursors (zed only) // works with multiple cursors (zed only)
// cx.set_state("aˇßcdˇe\n", Mode::Normal); cx.set_state("aˇßcdˇe\n", Mode::Normal);
// cx.simulate_keystroke("~"); cx.simulate_keystroke("~");
// cx.assert_state("aSSˇcdˇE\n", Mode::Normal); cx.assert_state("aSSˇcdˇE\n", Mode::Normal);
// } }
// } }

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

@ -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

@ -108,122 +108,140 @@ fn scroll_editor(
} }
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use crate::{ use crate::{
// state::Mode, state::Mode,
// test::{NeovimBackedTestContext, VimTestContext}, test::{NeovimBackedTestContext, VimTestContext},
// }; };
// use gpui::geometry::vector::vec2f; use gpui::{point, px, size, Context};
// use indoc::indoc; use indoc::indoc;
// use language::Point; use language::Point;
// #[gpui::test] #[gpui::test]
// async fn test_scroll(cx: &mut gpui::TestAppContext) { async fn test_scroll(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, true).await; let mut cx = VimTestContext::new(cx, true).await;
// let window = cx.window; let (line_height, visible_line_count) = cx.editor(|editor, cx| {
// let line_height = cx.editor(|editor, cx| editor.style().text.line_height(cx.font_cache())); (
// window.simulate_resize(vec2f(1000., 8.0 * line_height - 1.0), &mut cx); editor
.style()
.unwrap()
.text
.line_height_in_pixels(cx.rem_size()),
editor.visible_line_count().unwrap(),
)
});
// cx.set_state( let window = cx.window;
// indoc!( let margin = cx
// "ˇone .update_window(window, |_, cx| {
// two cx.viewport_size().height - line_height * visible_line_count
// three })
// four .unwrap();
// five cx.simulate_window_resize(
// six cx.window,
// seven size(px(1000.), margin + 8. * line_height - px(1.0)),
// eight );
// nine
// ten
// eleven
// twelve
// "
// ),
// Mode::Normal,
// );
// cx.update_editor(|editor, cx| { cx.set_state(
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 0.)) indoc!(
// }); "ˇone
// cx.simulate_keystrokes(["ctrl-e"]); two
// cx.update_editor(|editor, cx| { three
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 1.)) four
// }); five
// cx.simulate_keystrokes(["2", "ctrl-e"]); six
// cx.update_editor(|editor, cx| { seven
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 3.)) eight
// }); nine
// cx.simulate_keystrokes(["ctrl-y"]); ten
// cx.update_editor(|editor, cx| { eleven
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 2.)) twelve
// }); "
),
Mode::Normal,
);
// // does not select in normal mode cx.update_editor(|editor, cx| {
// cx.simulate_keystrokes(["g", "g"]); assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 0.))
// cx.update_editor(|editor, cx| { });
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 0.)) cx.simulate_keystrokes(["ctrl-e"]);
// }); cx.update_editor(|editor, cx| {
// cx.simulate_keystrokes(["ctrl-d"]); assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 1.))
// cx.update_editor(|editor, cx| { });
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 3.0)); cx.simulate_keystrokes(["2", "ctrl-e"]);
// assert_eq!( cx.update_editor(|editor, cx| {
// editor.selections.newest(cx).range(), assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 3.))
// Point::new(6, 0)..Point::new(6, 0) });
// ) cx.simulate_keystrokes(["ctrl-y"]);
// }); cx.update_editor(|editor, cx| {
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 2.))
});
// // does select in visual mode // does not select in normal mode
// cx.simulate_keystrokes(["g", "g"]); cx.simulate_keystrokes(["g", "g"]);
// cx.update_editor(|editor, cx| { cx.update_editor(|editor, cx| {
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 0.)) assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 0.))
// }); });
// cx.simulate_keystrokes(["v", "ctrl-d"]); cx.simulate_keystrokes(["ctrl-d"]);
// cx.update_editor(|editor, cx| { cx.update_editor(|editor, cx| {
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 3.0)); assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 3.0));
// assert_eq!( assert_eq!(
// editor.selections.newest(cx).range(), editor.selections.newest(cx).range(),
// Point::new(0, 0)..Point::new(6, 1) Point::new(6, 0)..Point::new(6, 0)
// ) )
// }); });
// }
// #[gpui::test]
// async fn test_ctrl_d_u(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.set_scroll_height(10).await; // does select in visual mode
cx.simulate_keystrokes(["g", "g"]);
cx.update_editor(|editor, cx| {
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 0.))
});
cx.simulate_keystrokes(["v", "ctrl-d"]);
cx.update_editor(|editor, cx| {
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 3.0));
assert_eq!(
editor.selections.newest(cx).range(),
Point::new(0, 0)..Point::new(6, 1)
)
});
}
#[gpui::test]
async fn test_ctrl_d_u(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
// pub fn sample_text(rows: usize, cols: usize, start_char: char) -> String { cx.set_scroll_height(10).await;
// let mut text = String::new();
// for row in 0..rows {
// let c: char = (start_char as u32 + row as u32) as u8 as char;
// let mut line = c.to_string().repeat(cols);
// if row < rows - 1 {
// line.push('\n');
// }
// text += &line;
// }
// text
// }
// let content = "ˇ".to_owned() + &sample_text(26, 2, 'a');
// cx.set_shared_state(&content).await;
// // skip over the scrolloff at the top pub fn sample_text(rows: usize, cols: usize, start_char: char) -> String {
// // test ctrl-d let mut text = String::new();
// cx.simulate_shared_keystrokes(["4", "j", "ctrl-d"]).await; for row in 0..rows {
// cx.assert_state_matches().await; let c: char = (start_char as u32 + row as u32) as u8 as char;
// cx.simulate_shared_keystrokes(["ctrl-d"]).await; let mut line = c.to_string().repeat(cols);
// cx.assert_state_matches().await; if row < rows - 1 {
// cx.simulate_shared_keystrokes(["g", "g", "ctrl-d"]).await; line.push('\n');
// cx.assert_state_matches().await; }
text += &line;
}
text
}
let content = "ˇ".to_owned() + &sample_text(26, 2, 'a');
cx.set_shared_state(&content).await;
// // test ctrl-u // skip over the scrolloff at the top
// cx.simulate_shared_keystrokes(["ctrl-u"]).await; // test ctrl-d
// cx.assert_state_matches().await; cx.simulate_shared_keystrokes(["4", "j", "ctrl-d"]).await;
// cx.simulate_shared_keystrokes(["ctrl-d", "ctrl-d", "4", "j", "ctrl-u", "ctrl-u"]) cx.assert_state_matches().await;
// .await; cx.simulate_shared_keystrokes(["ctrl-d"]).await;
// cx.assert_state_matches().await; cx.assert_state_matches().await;
// } cx.simulate_shared_keystrokes(["g", "g", "ctrl-d"]).await;
// } cx.assert_state_matches().await;
// test ctrl-u
cx.simulate_shared_keystrokes(["ctrl-u"]).await;
cx.assert_state_matches().await;
cx.simulate_shared_keystrokes(["ctrl-d", "ctrl-d", "4", "j", "ctrl-u", "ctrl-u"])
.await;
cx.assert_state_matches().await;
}
}

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

@ -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

@ -587,439 +587,439 @@ fn surrounding_markers(
) )
} }
// #[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},
// }; };
// const WORD_LOCATIONS: &'static str = indoc! {" const WORD_LOCATIONS: &'static str = indoc! {"
// The quick ˇbrowˇnˇ••• The quick ˇbrowˇnˇ
// fox ˇjuˇmpsˇ over fox ˇjuˇmpsˇ over
// the lazy dogˇ•• the lazy dogˇ
// ˇ ˇ
// ˇ ˇ
// ˇ ˇ
// Thˇeˇ-ˇquˇickˇ ˇbrownˇ• Thˇeˇ-ˇquˇickˇ ˇbrownˇ
// ˇ•• ˇ
// ˇ•• ˇ
// ˇ fox-jumpˇs over ˇ fox-jumpˇs over
// the lazy dogˇ• the lazy dogˇ
// ˇ ˇ
// " "
// }; };
// #[gpui::test] #[gpui::test]
// async fn test_change_word_object(cx: &mut gpui::TestAppContext) { async fn test_change_word_object(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_binding_matches_all(["c", "i", "w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["c", "i", "w"], WORD_LOCATIONS)
// .await; .await;
// cx.assert_binding_matches_all(["c", "i", "shift-w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["c", "i", "shift-w"], WORD_LOCATIONS)
// .await; .await;
// cx.assert_binding_matches_all(["c", "a", "w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["c", "a", "w"], WORD_LOCATIONS)
// .await; .await;
// cx.assert_binding_matches_all(["c", "a", "shift-w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["c", "a", "shift-w"], WORD_LOCATIONS)
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_word_object(cx: &mut gpui::TestAppContext) { async fn test_delete_word_object(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.assert_binding_matches_all(["d", "i", "w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["d", "i", "w"], WORD_LOCATIONS)
// .await; .await;
// cx.assert_binding_matches_all(["d", "i", "shift-w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["d", "i", "shift-w"], WORD_LOCATIONS)
// .await; .await;
// cx.assert_binding_matches_all(["d", "a", "w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["d", "a", "w"], WORD_LOCATIONS)
// .await; .await;
// cx.assert_binding_matches_all(["d", "a", "shift-w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["d", "a", "shift-w"], WORD_LOCATIONS)
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_visual_word_object(cx: &mut gpui::TestAppContext) { async fn test_visual_word_object(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\nfox").await; cx.set_shared_state("The quick ˇbrown\nfox").await;
// cx.simulate_shared_keystrokes(["v"]).await; cx.simulate_shared_keystrokes(["v"]).await;
// cx.assert_shared_state("The quick «bˇ»rown\nfox").await; cx.assert_shared_state("The quick «bˇ»rown\nfox").await;
// cx.simulate_shared_keystrokes(["i", "w"]).await; cx.simulate_shared_keystrokes(["i", "w"]).await;
// cx.assert_shared_state("The quick «brownˇ»\nfox").await; cx.assert_shared_state("The quick «brownˇ»\nfox").await;
// */ */
// cx.set_shared_state("The quick brown\nˇ\nfox").await; cx.set_shared_state("The quick brown\nˇ\nfox").await;
// cx.simulate_shared_keystrokes(["v"]).await; cx.simulate_shared_keystrokes(["v"]).await;
// cx.assert_shared_state("The quick brown\n«\nˇ»fox").await; cx.assert_shared_state("The quick brown\n«\nˇ»fox").await;
// cx.simulate_shared_keystrokes(["i", "w"]).await; cx.simulate_shared_keystrokes(["i", "w"]).await;
// cx.assert_shared_state("The quick brown\n«\nˇ»fox").await; cx.assert_shared_state("The quick brown\n«\nˇ»fox").await;
// cx.assert_binding_matches_all(["v", "i", "w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["v", "i", "w"], WORD_LOCATIONS)
// .await; .await;
// cx.assert_binding_matches_all_exempted( cx.assert_binding_matches_all_exempted(
// ["v", "h", "i", "w"], ["v", "h", "i", "w"],
// WORD_LOCATIONS, WORD_LOCATIONS,
// ExemptionFeatures::NonEmptyVisualTextObjects, ExemptionFeatures::NonEmptyVisualTextObjects,
// ) )
// .await; .await;
// cx.assert_binding_matches_all_exempted( cx.assert_binding_matches_all_exempted(
// ["v", "l", "i", "w"], ["v", "l", "i", "w"],
// WORD_LOCATIONS, WORD_LOCATIONS,
// ExemptionFeatures::NonEmptyVisualTextObjects, ExemptionFeatures::NonEmptyVisualTextObjects,
// ) )
// .await; .await;
// cx.assert_binding_matches_all(["v", "i", "shift-w"], WORD_LOCATIONS) cx.assert_binding_matches_all(["v", "i", "shift-w"], WORD_LOCATIONS)
// .await; .await;
// cx.assert_binding_matches_all_exempted( cx.assert_binding_matches_all_exempted(
// ["v", "i", "h", "shift-w"], ["v", "i", "h", "shift-w"],
// WORD_LOCATIONS, WORD_LOCATIONS,
// ExemptionFeatures::NonEmptyVisualTextObjects, ExemptionFeatures::NonEmptyVisualTextObjects,
// ) )
// .await; .await;
// cx.assert_binding_matches_all_exempted( cx.assert_binding_matches_all_exempted(
// ["v", "i", "l", "shift-w"], ["v", "i", "l", "shift-w"],
// WORD_LOCATIONS, WORD_LOCATIONS,
// ExemptionFeatures::NonEmptyVisualTextObjects, ExemptionFeatures::NonEmptyVisualTextObjects,
// ) )
// .await; .await;
// cx.assert_binding_matches_all_exempted( cx.assert_binding_matches_all_exempted(
// ["v", "a", "w"], ["v", "a", "w"],
// WORD_LOCATIONS, WORD_LOCATIONS,
// ExemptionFeatures::AroundObjectLeavesWhitespaceAtEndOfLine, ExemptionFeatures::AroundObjectLeavesWhitespaceAtEndOfLine,
// ) )
// .await; .await;
// cx.assert_binding_matches_all_exempted( cx.assert_binding_matches_all_exempted(
// ["v", "a", "shift-w"], ["v", "a", "shift-w"],
// WORD_LOCATIONS, WORD_LOCATIONS,
// ExemptionFeatures::AroundObjectLeavesWhitespaceAtEndOfLine, ExemptionFeatures::AroundObjectLeavesWhitespaceAtEndOfLine,
// ) )
// .await; .await;
// } }
// const SENTENCE_EXAMPLES: &[&'static str] = &[ const SENTENCE_EXAMPLES: &[&'static str] = &[
// "ˇThe quick ˇbrownˇ?ˇ ˇFox Jˇumpsˇ!ˇ Ovˇer theˇ lazyˇ.", "ˇThe quick ˇbrownˇ?ˇ ˇFox Jˇumpsˇ!ˇ Ovˇer theˇ lazyˇ.",
// indoc! {" indoc! {"
// ˇThe quick ˇbrownˇ ˇThe quick ˇbrownˇ
// fox jumps over fox jumps over
// the lazy doˇgˇ.ˇ ˇThe quick ˇ the lazy doˇgˇ.ˇ ˇThe quick ˇ
// brown fox jumps over brown fox jumps over
// "}, "},
// indoc! {" indoc! {"
// The quick brown fox jumps. The quick brown fox jumps.
// Over the lazy dog Over the lazy dog
// ˇ ˇ
// ˇ ˇ
// ˇ fox-jumpˇs over ˇ fox-jumpˇs over
// the lazy dog.ˇ the lazy dog.ˇ
// ˇ ˇ
// "}, "},
// r#"ˇThe ˇquick brownˇ.)ˇ]ˇ'ˇ" Brown ˇfox jumpsˇ.ˇ "#, r#"ˇThe ˇquick brownˇ.)ˇ]ˇ'ˇ" Brown ˇfox jumpsˇ.ˇ "#,
// ]; ];
// #[gpui::test] #[gpui::test]
// async fn test_change_sentence_object(cx: &mut gpui::TestAppContext) { async fn test_change_sentence_object(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx) let mut cx = NeovimBackedTestContext::new(cx)
// .await .await
// .binding(["c", "i", "s"]); .binding(["c", "i", "s"]);
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown fox jumps.\nOver the lazy dog\nˇ\nˇ\n fox-jumps over\nthe lazy dog.\n\n", "The quick brown fox jumps.\nOver the lazy dog\nˇ\nˇ\n fox-jumps over\nthe lazy dog.\n\n",
// ExemptionFeatures::SentenceOnEmptyLines); ExemptionFeatures::SentenceOnEmptyLines);
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown fox jumps.\nOver the lazy dog\n\n\nˇ foxˇ-ˇjumpˇs over\nthe lazy dog.\n\n", "The quick brown fox jumps.\nOver the lazy dog\n\n\nˇ foxˇ-ˇjumpˇs over\nthe lazy dog.\n\n",
// ExemptionFeatures::SentenceAtStartOfLineWithWhitespace); ExemptionFeatures::SentenceAtStartOfLineWithWhitespace);
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown fox jumps.\nOver the lazy dog\n\n\n fox-jumps over\nthe lazy dog.ˇ\nˇ\n", "The quick brown fox jumps.\nOver the lazy dog\n\n\n fox-jumps over\nthe lazy dog.ˇ\nˇ\n",
// ExemptionFeatures::SentenceAfterPunctuationAtEndOfFile); ExemptionFeatures::SentenceAfterPunctuationAtEndOfFile);
// for sentence_example in SENTENCE_EXAMPLES { for sentence_example in SENTENCE_EXAMPLES {
// cx.assert_all(sentence_example).await; cx.assert_all(sentence_example).await;
// } }
// let mut cx = cx.binding(["c", "a", "s"]); let mut cx = cx.binding(["c", "a", "s"]);
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown?ˇ Fox Jumps! Over the lazy.", "The quick brown?ˇ Fox Jumps! Over the lazy.",
// ExemptionFeatures::IncorrectLandingPosition, ExemptionFeatures::IncorrectLandingPosition,
// ); );
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown.)]\'\" Brown fox jumps.ˇ ", "The quick brown.)]\'\" Brown fox jumps.ˇ ",
// ExemptionFeatures::AroundObjectLeavesWhitespaceAtEndOfLine, ExemptionFeatures::AroundObjectLeavesWhitespaceAtEndOfLine,
// ); );
// for sentence_example in SENTENCE_EXAMPLES { for sentence_example in SENTENCE_EXAMPLES {
// cx.assert_all(sentence_example).await; cx.assert_all(sentence_example).await;
// } }
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_sentence_object(cx: &mut gpui::TestAppContext) { async fn test_delete_sentence_object(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx) let mut cx = NeovimBackedTestContext::new(cx)
// .await .await
// .binding(["d", "i", "s"]); .binding(["d", "i", "s"]);
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown fox jumps.\nOver the lazy dog\nˇ\nˇ\n fox-jumps over\nthe lazy dog.\n\n", "The quick brown fox jumps.\nOver the lazy dog\nˇ\nˇ\n fox-jumps over\nthe lazy dog.\n\n",
// ExemptionFeatures::SentenceOnEmptyLines); ExemptionFeatures::SentenceOnEmptyLines);
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown fox jumps.\nOver the lazy dog\n\n\nˇ foxˇ-ˇjumpˇs over\nthe lazy dog.\n\n", "The quick brown fox jumps.\nOver the lazy dog\n\n\nˇ foxˇ-ˇjumpˇs over\nthe lazy dog.\n\n",
// ExemptionFeatures::SentenceAtStartOfLineWithWhitespace); ExemptionFeatures::SentenceAtStartOfLineWithWhitespace);
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown fox jumps.\nOver the lazy dog\n\n\n fox-jumps over\nthe lazy dog.ˇ\nˇ\n", "The quick brown fox jumps.\nOver the lazy dog\n\n\n fox-jumps over\nthe lazy dog.ˇ\nˇ\n",
// ExemptionFeatures::SentenceAfterPunctuationAtEndOfFile); ExemptionFeatures::SentenceAfterPunctuationAtEndOfFile);
// for sentence_example in SENTENCE_EXAMPLES { for sentence_example in SENTENCE_EXAMPLES {
// cx.assert_all(sentence_example).await; cx.assert_all(sentence_example).await;
// } }
// let mut cx = cx.binding(["d", "a", "s"]); let mut cx = cx.binding(["d", "a", "s"]);
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown?ˇ Fox Jumps! Over the lazy.", "The quick brown?ˇ Fox Jumps! Over the lazy.",
// ExemptionFeatures::IncorrectLandingPosition, ExemptionFeatures::IncorrectLandingPosition,
// ); );
// cx.add_initial_state_exemptions( cx.add_initial_state_exemptions(
// "The quick brown.)]\'\" Brown fox jumps.ˇ ", "The quick brown.)]\'\" Brown fox jumps.ˇ ",
// ExemptionFeatures::AroundObjectLeavesWhitespaceAtEndOfLine, ExemptionFeatures::AroundObjectLeavesWhitespaceAtEndOfLine,
// ); );
// for sentence_example in SENTENCE_EXAMPLES { for sentence_example in SENTENCE_EXAMPLES {
// cx.assert_all(sentence_example).await; cx.assert_all(sentence_example).await;
// } }
// } }
// #[gpui::test] #[gpui::test]
// async fn test_visual_sentence_object(cx: &mut gpui::TestAppContext) { async fn test_visual_sentence_object(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx) let mut cx = NeovimBackedTestContext::new(cx)
// .await .await
// .binding(["v", "i", "s"]); .binding(["v", "i", "s"]);
// for sentence_example in SENTENCE_EXAMPLES { for sentence_example in SENTENCE_EXAMPLES {
// cx.assert_all_exempted(sentence_example, ExemptionFeatures::SentenceOnEmptyLines) cx.assert_all_exempted(sentence_example, ExemptionFeatures::SentenceOnEmptyLines)
// .await; .await;
// } }
// let mut cx = cx.binding(["v", "a", "s"]); let mut cx = cx.binding(["v", "a", "s"]);
// for sentence_example in SENTENCE_EXAMPLES { for sentence_example in SENTENCE_EXAMPLES {
// cx.assert_all_exempted( cx.assert_all_exempted(
// sentence_example, sentence_example,
// ExemptionFeatures::AroundSentenceStartingBetweenIncludesWrongWhitespace, ExemptionFeatures::AroundSentenceStartingBetweenIncludesWrongWhitespace,
// ) )
// .await; .await;
// } }
// } }
// // Test string with "`" for opening surrounders and "'" for closing surrounders // Test string with "`" for opening surrounders and "'" for closing surrounders
// const SURROUNDING_MARKER_STRING: &str = indoc! {" const SURROUNDING_MARKER_STRING: &str = indoc! {"
// ˇTh'ˇe ˇ`ˇ'ˇquˇi`ˇck broˇ'wn` ˇTh'ˇe ˇ`ˇ'ˇquˇi`ˇck broˇ'wn`
// 'ˇfox juˇmps ovˇ`ˇer 'ˇfox juˇmps ovˇ`ˇer
// the ˇlazy dˇ'ˇoˇ`ˇg"}; the ˇlazy 'ˇ`ˇg"};
// const SURROUNDING_OBJECTS: &[(char, char)] = &[ const SURROUNDING_OBJECTS: &[(char, char)] = &[
// ('\'', '\''), // Quote ('\'', '\''), // Quote
// ('`', '`'), // Back Quote ('`', '`'), // Back Quote
// ('"', '"'), // Double Quote ('"', '"'), // Double Quote
// ('(', ')'), // Parentheses ('(', ')'), // Parentheses
// ('[', ']'), // SquareBrackets ('[', ']'), // SquareBrackets
// ('{', '}'), // CurlyBrackets ('{', '}'), // CurlyBrackets
// ('<', '>'), // AngleBrackets ('<', '>'), // AngleBrackets
// ]; ];
// #[gpui::test] #[gpui::test]
// async fn test_change_surrounding_character_objects(cx: &mut gpui::TestAppContext) { async fn test_change_surrounding_character_objects(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// for (start, end) in SURROUNDING_OBJECTS { for (start, end) in SURROUNDING_OBJECTS {
// let marked_string = SURROUNDING_MARKER_STRING let marked_string = SURROUNDING_MARKER_STRING
// .replace('`', &start.to_string()) .replace('`', &start.to_string())
// .replace('\'', &end.to_string()); .replace('\'', &end.to_string());
// cx.assert_binding_matches_all(["c", "i", &start.to_string()], &marked_string) cx.assert_binding_matches_all(["c", "i", &start.to_string()], &marked_string)
// .await; .await;
// cx.assert_binding_matches_all(["c", "i", &end.to_string()], &marked_string) cx.assert_binding_matches_all(["c", "i", &end.to_string()], &marked_string)
// .await; .await;
// cx.assert_binding_matches_all(["c", "a", &start.to_string()], &marked_string) cx.assert_binding_matches_all(["c", "a", &start.to_string()], &marked_string)
// .await; .await;
// cx.assert_binding_matches_all(["c", "a", &end.to_string()], &marked_string) cx.assert_binding_matches_all(["c", "a", &end.to_string()], &marked_string)
// .await; .await;
// } }
// } }
// #[gpui::test] #[gpui::test]
// async fn test_singleline_surrounding_character_objects(cx: &mut gpui::TestAppContext) { async fn test_singleline_surrounding_character_objects(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// cx.set_shared_wrap(12).await; cx.set_shared_wrap(12).await;
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "helˇlo \"world\"!" "helˇlo \"world\"!"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "i", "\""]).await; cx.simulate_shared_keystrokes(["v", "i", "\""]).await;
// cx.assert_shared_state(indoc! { cx.assert_shared_state(indoc! {
// "hello \"«worldˇ»\"!" "hello \"«worldˇ»\"!"
// }) })
// .await; .await;
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "hello \"wˇorld\"!" "hello \"wˇorld\"!"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "i", "\""]).await; cx.simulate_shared_keystrokes(["v", "i", "\""]).await;
// cx.assert_shared_state(indoc! { cx.assert_shared_state(indoc! {
// "hello \"«worldˇ»\"!" "hello \"«worldˇ»\"!"
// }) })
// .await; .await;
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "hello \"wˇorld\"!" "hello \"wˇorld\"!"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "a", "\""]).await; cx.simulate_shared_keystrokes(["v", "a", "\""]).await;
// cx.assert_shared_state(indoc! { cx.assert_shared_state(indoc! {
// "hello« \"world\"ˇ»!" "hello« \"world\"ˇ»!"
// }) })
// .await; .await;
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "hello \"wˇorld\" !" "hello \"wˇorld\" !"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "a", "\""]).await; cx.simulate_shared_keystrokes(["v", "a", "\""]).await;
// cx.assert_shared_state(indoc! { cx.assert_shared_state(indoc! {
// "hello «\"world\" ˇ»!" "hello «\"world\" ˇ»!"
// }) })
// .await; .await;
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "hello \"wˇorld\" "hello \"wˇorld\"
// goodbye" goodbye"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "a", "\""]).await; cx.simulate_shared_keystrokes(["v", "a", "\""]).await;
// cx.assert_shared_state(indoc! { cx.assert_shared_state(indoc! {
// "hello «\"world\" ˇ» "hello «\"world\" ˇ»
// goodbye" goodbye"
// }) })
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_multiline_surrounding_character_objects(cx: &mut gpui::TestAppContext) { async fn test_multiline_surrounding_character_objects(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! {
// "func empty(a string) bool { "func empty(a string) bool {
// if a == \"\" { if a == \"\" {
// return true return true
// } }
// ˇreturn false ˇreturn false
// }" }"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "i", "{"]).await; cx.simulate_shared_keystrokes(["v", "i", "{"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// func empty(a string) bool { func empty(a string) bool {
// « if a == \"\" { « if a == \"\" {
// return true return true
// } }
// return false return false
// ˇ»}"}) ˇ»}"})
// .await; .await;
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "func empty(a string) bool { "func empty(a string) bool {
// if a == \"\" { if a == \"\" {
// ˇreturn true ˇreturn true
// } }
// return false return false
// }" }"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "i", "{"]).await; cx.simulate_shared_keystrokes(["v", "i", "{"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// func empty(a string) bool { func empty(a string) bool {
// if a == \"\" { if a == \"\" {
// « return true « return true
// ˇ» } ˇ» }
// return false return false
// }"}) }"})
// .await; .await;
// cx.set_shared_state(indoc! { cx.set_shared_state(indoc! {
// "func empty(a string) bool { "func empty(a string) bool {
// if a == \"\" ˇ{ if a == \"\" ˇ{
// return true return true
// } }
// return false return false
// }" }"
// }) })
// .await; .await;
// cx.simulate_shared_keystrokes(["v", "i", "{"]).await; cx.simulate_shared_keystrokes(["v", "i", "{"]).await;
// cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
// func empty(a string) bool { func empty(a string) bool {
// if a == \"\" { if a == \"\" {
// « return true « return true
// ˇ» } ˇ» }
// return false return false
// }"}) }"})
// .await; .await;
// } }
// #[gpui::test] #[gpui::test]
// async fn test_vertical_bars(cx: &mut gpui::TestAppContext) { async fn test_vertical_bars(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! {"
// fn boop() { fn boop() {
// baz(ˇ|a, b| { bar(|j, k| { })}) baz(ˇ|a, b| { bar(|j, k| { })})
// }" }"
// }, },
// Mode::Normal, Mode::Normal,
// ); );
// cx.simulate_keystrokes(["c", "i", "|"]); cx.simulate_keystrokes(["c", "i", "|"]);
// cx.assert_state( cx.assert_state(
// indoc! {" indoc! {"
// fn boop() { fn boop() {
// baz(|ˇ| { bar(|j, k| { })}) baz(|ˇ| { bar(|j, k| { })})
// }" }"
// }, },
// Mode::Insert, Mode::Insert,
// ); );
// cx.simulate_keystrokes(["escape", "1", "8", "|"]); cx.simulate_keystrokes(["escape", "1", "8", "|"]);
// cx.assert_state( cx.assert_state(
// indoc! {" indoc! {"
// fn boop() { fn boop() {
// baz(|| { bar(ˇ|j, k| { })}) baz(|| { bar(ˇ|j, k| { })})
// }" }"
// }, },
// Mode::Normal, Mode::Normal,
// ); );
// cx.simulate_keystrokes(["v", "a", "|"]); cx.simulate_keystrokes(["v", "a", "|"]);
// cx.assert_state( cx.assert_state(
// indoc! {" indoc! {"
// fn boop() { fn boop() {
// baz(|| { bar(«|j, k| ˇ»{ })}) baz(|| { bar(«|j, k| ˇ»{ })})
// }" }"
// }, },
// Mode::Visual, Mode::Visual,
// ); );
// } }
// #[gpui::test] #[gpui::test]
// async fn test_delete_surrounding_character_objects(cx: &mut gpui::TestAppContext) { async fn test_delete_surrounding_character_objects(cx: &mut gpui::TestAppContext) {
// let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
// for (start, end) in SURROUNDING_OBJECTS { for (start, end) in SURROUNDING_OBJECTS {
// let marked_string = SURROUNDING_MARKER_STRING let marked_string = SURROUNDING_MARKER_STRING
// .replace('`', &start.to_string()) .replace('`', &start.to_string())
// .replace('\'', &end.to_string()); .replace('\'', &end.to_string());
// cx.assert_binding_matches_all(["d", "i", &start.to_string()], &marked_string) cx.assert_binding_matches_all(["d", "i", &start.to_string()], &marked_string)
// .await; .await;
// cx.assert_binding_matches_all(["d", "i", &end.to_string()], &marked_string) cx.assert_binding_matches_all(["d", "i", &end.to_string()], &marked_string)
// .await; .await;
// cx.assert_binding_matches_all(["d", "a", &start.to_string()], &marked_string) cx.assert_binding_matches_all(["d", "a", &start.to_string()], &marked_string)
// .await; .await;
// cx.assert_binding_matches_all(["d", "a", &end.to_string()], &marked_string) cx.assert_binding_matches_all(["d", "a", &end.to_string()], &marked_string)
// .await; .await;
// } }
// } }
// } }

View file

@ -2,6 +2,7 @@
// todo!() // todo!()
use editor::{scroll::VERTICAL_SCROLL_MARGIN, test::editor_test_context::ContextHandle}; use editor::{scroll::VERTICAL_SCROLL_MARGIN, test::editor_test_context::ContextHandle};
use gpui::{point, px, rems, size, Context};
use indoc::indoc; use indoc::indoc;
use settings::SettingsStore; use settings::SettingsStore;
use std::{ use std::{
@ -153,20 +154,36 @@ impl<'a> NeovimBackedTestContext<'a> {
}) })
} }
// todo!() pub async fn set_scroll_height(&mut self, rows: u32) {
// pub async fn set_scroll_height(&mut self, rows: u32) { // match Zed's scrolling behavior
// // match Zed's scrolling behavior self.neovim
// self.neovim .set_option(&format!("scrolloff={}", VERTICAL_SCROLL_MARGIN))
// .set_option(&format!("scrolloff={}", VERTICAL_SCROLL_MARGIN)) .await;
// .await; // +2 to account for the vim command UI at the bottom.
// // +2 to account for the vim command UI at the bottom. self.neovim.set_option(&format!("lines={}", rows + 2)).await;
// self.neovim.set_option(&format!("lines={}", rows + 2)).await; let (line_height, visible_line_count) = self.editor(|editor, cx| {
// let window = self.window; (
// let line_height = editor
// self.editor(|editor, cx| editor.style().text.line_height(cx.font_cache())); .style()
.unwrap()
.text
.line_height_in_pixels(cx.rem_size()),
editor.visible_line_count().unwrap(),
)
});
// window.simulate_resize(vec2f(1000., (rows as f32) * line_height), &mut self.cx); let window = self.window;
// } let margin = self
.update_window(window, |_, cx| {
cx.viewport_size().height - line_height * visible_line_count
})
.unwrap();
self.simulate_window_resize(
self.window,
size(px(1000.), margin + (rows as f32) * line_height),
);
}
pub async fn set_neovim_option(&mut self, option: &str) { pub async fn set_neovim_option(&mut self, option: &str) {
self.neovim.set_option(option).await; self.neovim.set_option(option).await;

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,

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() {

File diff suppressed because it is too large Load diff