Add visual line mode operator tests

Keith Simmons created

Change summary

crates/vim/src/vim_test_context.rs |   8 +
crates/vim/src/visual.rs           | 158 ++++++++++++++++++++++++++++++++
2 files changed, 165 insertions(+), 1 deletion(-)

Detailed changes

crates/vim/src/vim_test_context.rs 🔗

@@ -1,4 +1,4 @@
-use std::ops::{Deref, Range};
+use std::ops::{Deref, DerefMut, Range};
 
 use collections::BTreeMap;
 use itertools::{Either, Itertools};
@@ -404,3 +404,9 @@ impl<'a, const COUNT: usize> Deref for VimBindingTestContext<'a, COUNT> {
         &self.cx
     }
 }
+
+impl<'a, const COUNT: usize> DerefMut for VimBindingTestContext<'a, COUNT> {
+    fn deref_mut(&mut self) -> &mut Self::Target {
+        &mut self.cx
+    }
+}

crates/vim/src/visual.rs 🔗

@@ -249,6 +249,13 @@ mod test {
                 The |ver
                 the lazy dog"},
         );
+        // Test pasting code copied on delete
+        cx.simulate_keystrokes(["j", "p"]);
+        cx.assert_editor_state(indoc! {"
+            The ver
+            the lazy d|quick brown
+            fox jumps oog"});
+
         cx.assert(
             indoc! {"
                 The quick brown
@@ -299,6 +306,77 @@ mod test {
         );
     }
 
+    #[gpui::test]
+    async fn test_visual_line_delete(cx: &mut gpui::TestAppContext) {
+        let cx = VimTestContext::new(cx, true).await;
+        let mut cx = cx.binding(["shift-V", "x"]);
+        cx.assert(
+            indoc! {"
+                The qu|ick brown
+                fox jumps over
+                the lazy dog"},
+            indoc! {"
+                fox ju|mps over
+                the lazy dog"},
+        );
+        // Test pasting code copied on delete
+        cx.simulate_keystroke("p");
+        cx.assert_editor_state(indoc! {"
+            fox jumps over
+            |The quick brown
+            the lazy dog"});
+
+        cx.assert(
+            indoc! {"
+                The quick brown
+                fox ju|mps over
+                the lazy dog"},
+            indoc! {"
+                The quick brown
+                the la|zy dog"},
+        );
+        cx.assert(
+            indoc! {"
+                The quick brown
+                fox jumps over
+                the la|zy dog"},
+            indoc! {"
+                The quick brown
+                fox ju|mps over"},
+        );
+        let mut cx = cx.binding(["shift-V", "j", "x"]);
+        cx.assert(
+            indoc! {"
+                The qu|ick brown
+                fox jumps over
+                the lazy dog"},
+            "the la|zy dog",
+        );
+        // Test pasting code copied on delete
+        cx.simulate_keystroke("p");
+        cx.assert_editor_state(indoc! {"
+            the lazy dog
+            |The quick brown
+            fox jumps over"});
+
+        cx.assert(
+            indoc! {"
+                The quick brown
+                fox ju|mps over
+                the lazy dog"},
+            "The qu|ick brown",
+        );
+        cx.assert(
+            indoc! {"
+                The quick brown
+                fox jumps over
+                the la|zy dog"},
+            indoc! {"
+                The quick brown
+                fox ju|mps over"},
+        );
+    }
+
     #[gpui::test]
     async fn test_visual_change(cx: &mut gpui::TestAppContext) {
         let cx = VimTestContext::new(cx, true).await;
@@ -363,4 +441,84 @@ mod test {
                 the lazy dog"},
         );
     }
+
+    #[gpui::test]
+    async fn test_visual_line_change(cx: &mut gpui::TestAppContext) {
+        let cx = VimTestContext::new(cx, true).await;
+        let mut cx = cx.binding(["shift-V", "c"]).mode_after(Mode::Insert);
+        cx.assert(
+            indoc! {"
+                The qu|ick brown
+                fox jumps over
+                the lazy dog"},
+            indoc! {"
+                |
+                fox jumps over
+                the lazy dog"},
+        );
+        // Test pasting code copied on change
+        cx.simulate_keystrokes(["escape", "j", "p"]);
+        cx.assert_editor_state(indoc! {"
+            
+            fox jumps over
+            |The quick brown
+            the lazy dog"});
+
+        cx.assert(
+            indoc! {"
+                The quick brown
+                fox ju|mps over
+                the lazy dog"},
+            indoc! {"
+                The quick brown
+                |
+                the lazy dog"},
+        );
+        cx.assert(
+            indoc! {"
+                The quick brown
+                fox jumps over
+                the la|zy dog"},
+            indoc! {"
+                The quick brown
+                fox jumps over
+                |"},
+        );
+        let mut cx = cx.binding(["shift-V", "j", "c"]).mode_after(Mode::Insert);
+        cx.assert(
+            indoc! {"
+                The qu|ick brown
+                fox jumps over
+                the lazy dog"},
+            indoc! {"
+                |
+                the lazy dog"},
+        );
+        // Test pasting code copied on delete
+        cx.simulate_keystrokes(["escape", "j", "p"]);
+        cx.assert_editor_state(indoc! {"
+            
+            the lazy dog
+            |The quick brown
+            fox jumps over"});
+        cx.assert(
+            indoc! {"
+                The quick brown
+                fox ju|mps over
+                the lazy dog"},
+            indoc! {"
+                The quick brown
+                |"},
+        );
+        cx.assert(
+            indoc! {"
+                The quick brown
+                fox jumps over
+                the la|zy dog"},
+            indoc! {"
+                The quick brown
+                fox jumps over
+                |"},
+        );
+    }
 }