Commit 47374d44 authored by Mattias Engdegård's avatar Mattias Engdegård
Browse files

duplicate-line: fix optional argument and add test (bug#46621)

The test assumes that the current semantics are intended and desired,
which may or may not be true, but it's better than not having any at
all.

* lisp/misc.el (duplicate-line): Don't crash if called with no argument.
* test/lisp/misc-tests.el (misc--duplicate-line): New test.
parent 55c21025
Pipeline #18730 passed with stage
in 5 minutes and 26 seconds
......@@ -69,6 +69,8 @@ Also see the `duplicate-line' command."
Interactively, N is the prefix numeric argument, and defaults to 1.
Also see the `copy-from-above-command' command."
(interactive "p")
(unless n
(setq n 1))
(let ((line (buffer-substring (line-beginning-position) (line-end-position))))
(save-excursion
(forward-line 1)
......
......@@ -80,5 +80,21 @@
(backward-to-word 3)
(should (equal (point) 1))))
(ert-deftest misc--duplicate-line ()
;; Duplicate a line (twice).
(with-temp-buffer
(insert "abc\ndefg\nh\n")
(goto-char 7)
(duplicate-line 2)
(should (equal (buffer-string) "abc\ndefg\ndefg\ndefg\nh\n"))
(should (equal (point) 7)))
;; Duplicate a non-terminated line.
(with-temp-buffer
(insert "abc")
(goto-char 2)
(duplicate-line)
(should (equal (buffer-string) "abc\nabc\n"))
(should (equal (point) 2))))
(provide 'misc-tests)
;;; misc-tests.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment