summaryrefslogtreecommitdiff
path: root/test/lisp/misc-tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/lisp/misc-tests.el')
-rw-r--r--test/lisp/misc-tests.el38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/lisp/misc-tests.el b/test/lisp/misc-tests.el
index a56feaa0495..f84827ab025 100644
--- a/test/lisp/misc-tests.el
+++ b/test/lisp/misc-tests.el
@@ -96,5 +96,43 @@
(should (equal (buffer-string) "abc\nabc\n"))
(should (equal (point) 2))))
+(require 'rect)
+
+(ert-deftest misc--duplicate-dwim ()
+ ;; Duplicate a line.
+ (with-temp-buffer
+ (insert "abc\ndefg\nh\n")
+ (goto-char 7)
+ (duplicate-dwim 2)
+ (should (equal (buffer-string) "abc\ndefg\ndefg\ndefg\nh\n"))
+ (should (equal (point) 7)))
+
+ ;; Duplicate a region.
+ (with-temp-buffer
+ (insert "abc\ndef\n")
+ (set-mark 2)
+ (goto-char 7)
+ (transient-mark-mode)
+ (should (use-region-p))
+ (duplicate-dwim)
+ (should (equal (buffer-string) "abc\ndebc\ndef\n"))
+ (should (equal (point) 7))
+ (should (region-active-p))
+ (should (equal (mark) 2)))
+
+ ;; Duplicate a rectangular region.
+ (with-temp-buffer
+ (insert "x\n>a\n>bcde\n>fg\nyz\n")
+ (goto-char 4)
+ (rectangle-mark-mode)
+ (goto-char 15)
+ (rectangle-forward-char 1)
+ (duplicate-dwim)
+ (should (equal (buffer-string) "x\n>a a \n>bcdbcde\n>fg fg \nyz\n"))
+ (should (equal (point) 24))
+ (should (region-active-p))
+ (should rectangle-mark-mode)
+ (should (equal (mark) 4))))
+
(provide 'misc-tests)
;;; misc-tests.el ends here