Skip to content

Commit

Permalink
Add tests for vi-replace-char (r).
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Sep 1, 2023
1 parent 4e126e1 commit 1c32e5c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
33 changes: 33 additions & 0 deletions extensions/vi-mode/tests/operator.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,39 @@
(cmd "J")
(ok (buf= #?"abcdefgh[ ]ijklmn\n")))))

(deftest vi-replace-char
(with-fake-interface ()
(with-vi-buffer ("a[n]t")
(cmd "rr")
(ok (buf= "a[r]t")))
(with-vi-buffer ("sh[o]ut")
(cmd "2re")
(ok (buf= "she[e]t")))
(with-vi-buffer ("<[m]>eat")
(cmd "rb")
(ok (buf= "[b]eat")))
(with-vi-buffer ("p<i[n]>k")
(cmd "re")
(ok (buf= "p[e]ek")))
(with-vi-buffer ("p<[i]c>k")
(cmd "re")
(ok (buf= "p[e]ek")))
(with-vi-buffer (#?"em[a]cs\n")
(cmd "VrX")
(ok (buf= #?"[X]XXXX\n")))
(with-vi-buffer (#?"a[b]cd\nefgh\n")
(cmd "<C-v>jlrx")
(ok (buf= #?"a[x]xd\nexxh\n")))
(with-vi-buffer (#?"ab[c]d\nefgh\n")
(cmd "<C-v>jhrx")
(ok (buf= #?"a[x]xd\nexxh\n")))
(with-vi-buffer (#?"abcd\nef[g]h\n")
(cmd "<C-v>khrx")
(ok (buf= #?"a[x]xd\nexxh\n")))
(with-vi-buffer (#?"abcd\ne[f]gh\n")
(cmd "<C-v>klrx")
(ok (buf= #?"a[x]xd\nexxh\n")))))

(deftest vi-repeat
(with-fake-interface ()
(with-vi-buffer (#?"[1]:abc\n2:def\n3:ghi\n4:jkl\n5:mno\n6:opq\n7:rst\n8:uvw")
Expand Down
4 changes: 2 additions & 2 deletions extensions/vi-mode/text-objects.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
(defmethod a-range-of (object (state visual) count)
(destructuring-bind (beg end)
(visual-range)
(when (point= beg end)
(when (point= beg (current-point))
(return-from a-range-of
(call-next-method)))
(let ((direction (cond
Expand Down Expand Up @@ -132,7 +132,7 @@
(defmethod inner-range-of (object (state visual) count)
(destructuring-bind (beg end)
(visual-range)
(when (point= beg end)
(when (point= beg (current-point))
(return-from inner-range-of (call-next-method)))

(let ((direction (cond
Expand Down
2 changes: 1 addition & 1 deletion extensions/vi-mode/visual.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
((visual-char-p)
(with-point ((start *start-point*)
(end (current-point)))
(cond ((point< start end)
(cond ((point<= start end)
(character-offset end 1))
((point< end start)
(character-offset start 1)))
Expand Down

0 comments on commit 1c32e5c

Please sign in to comment.