2020-05-01 13:02:38 +02:00
|
|
|
;;; viper-tests.el --- tests for viper. -*- lexical-binding:t -*-
|
2016-05-23 10:39:26 +01:00
|
|
|
|
2024-01-02 09:47:10 +08:00
|
|
|
;; Copyright (C) 2016-2024 Free Software Foundation, Inc.
|
2016-05-23 10:39:26 +01:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2016-05-23 08:43:26 -07:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
2016-05-23 10:39:26 +01:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2016-05-23 10:39:26 +01:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
Prefer ert-with-temp-(directory|file)
* test/lisp/abbrev-tests.el (read-write-abbrev-file-test)
(read-write-abbrev-file-test-with-props)
(abbrev-edit-save-to-file-test):
* test/lisp/auth-source-tests.el (auth-source-test-netrc-create-secret)
(auth-source-delete):
* test/lisp/autoinsert-tests.el (autoinsert-tests-auto-insert-file):
* test/lisp/bookmark-tests.el (with-bookmark-test-save-load):
* test/lisp/buff-menu-tests.el (buff-menu-24962):
* test/lisp/calendar/icalendar-tests.el (icalendar-tests--do-test-export):
* test/lisp/calendar/todo-mode-tests.el (with-todo-test):
* test/lisp/dired-tests.el
(dired-test-bug27243-01, dired-test-bug27243-02)
(dired-test-bug27243-03, dired-test-bug27631)
(dired-test-bug27968, dired-test-with-temp-dirs):
* test/lisp/dired-x-tests.el (dired-test-bug25942):
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--with-temp-file):
* test/lisp/emacs-lisp/check-declare-tests.el (check-declare-tests-scan)
(check-declare-tests-verify-mismatch):
* test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-with-normal-env):
* test/lisp/emacs-lisp/package-tests.el (with-package-test)
(package-test-signed):
* test/lisp/emacs-lisp/testcover-tests.el (testcover-tests-markup-region)
(testcover-tests-run-test-case):
* test/lisp/emulation/viper-tests.el (viper-test-undo-kmacro):
* test/lisp/epg-tests.el (with-epg-tests):
* test/lisp/eshell/em-hist-tests.el (eshell-write-readonly-history):
* test/lisp/eshell/em-ls-tests.el (em-ls-test-bug27631):
* test/lisp/ffap-tests.el (ffap-tests-25243):
* test/lisp/files-tests.el (files-tests-bug-18141)
(files-tests-read-file-in-~, files-tests-make-directory)
(files-tests-copy-directory, files-tests-executable-find)
(files-tests-dont-rewrite-precious-files)
(files-tests--save-some-buffers):
* test/lisp/ls-lisp-tests.el (ls-lisp-test-bug27631):
* test/lisp/mail/uudecode-tests.el (uudecode-tests-decode-region-internal)
(uudecode-tests-decode-region-external):
* test/lisp/net/browse-url-tests.el (browse-url-tests-delete-temp-file):
* test/lisp/progmodes/elisp-mode-tests.el (xref--case-insensitive):
* test/lisp/progmodes/etags-tests.el (etags-buffer-local-tags-table-list):
* test/lisp/progmodes/flymake-tests.el (ruby-backend):
* test/lisp/progmodes/python-tests.el (python-tests-with-temp-file):
* test/lisp/progmodes/sql-tests.el (with-sql-test-connect-harness):
* test/lisp/saveplace-tests.el (saveplace-test-save-place-to-alist/file)
(saveplace-test-forget-unreadable-files)
(saveplace-test-place-alist-to-file):
* test/lisp/so-long-tests/spelling-tests.el:
* test/lisp/textmodes/reftex-tests.el (reftex-locate-bibliography-files)
(reftex-parse-from-file-test):
* test/lisp/thumbs-tests.el (thumbs-tests-thumbsdir/create-if-missing):
* test/lisp/vc/vc-bzr-tests.el (vc-bzr-test-bug9726)
(vc-bzr-test-bug9781, vc-bzr-test-faulty-bzr-autoloads):
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-ignore-trailing-dashes):
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug26084):
* test/lisp/wdired-tests.el (wdired-test-bug32173-01)
(wdired-test-bug32173-02, wdired-test-symlink-name)
(wdired-test-unfinished-edit-01, wdired-test-bug34915)
(wdired-test-bug39280):
* test/src/buffer-tests.el (test-kill-buffer-auto-save-default):
* test/src/filelock-tests.el (filelock-tests--fixture):
* test/src/inotify-tests.el (inotify-file-watch-simple):
* test/src/undo-tests.el (undo-test-file-modified): Prefer
'ert-with-temp-(directory|file)' to using 'make-temp-file' directly.
In some cases, this is just cleanup, but in several cases this fixes
bugs where an error would have lead to us not cleaning up.
2021-11-06 23:20:59 +01:00
|
|
|
(require 'ert)
|
|
|
|
(require 'ert-x)
|
2016-05-23 10:39:26 +01:00
|
|
|
(require 'viper)
|
|
|
|
|
|
|
|
(defun viper-test-undo-kmacro (kmacro)
|
|
|
|
"In a clean viper buffer, run KMACRO and return `buffer-string'.
|
|
|
|
|
|
|
|
This function makes as many attempts as possible to clean up
|
|
|
|
after itself, although it will leave a buffer called
|
|
|
|
*viper-test-buffer* if it fails (this is deliberate!)."
|
Prefer ert-with-temp-(directory|file)
* test/lisp/abbrev-tests.el (read-write-abbrev-file-test)
(read-write-abbrev-file-test-with-props)
(abbrev-edit-save-to-file-test):
* test/lisp/auth-source-tests.el (auth-source-test-netrc-create-secret)
(auth-source-delete):
* test/lisp/autoinsert-tests.el (autoinsert-tests-auto-insert-file):
* test/lisp/bookmark-tests.el (with-bookmark-test-save-load):
* test/lisp/buff-menu-tests.el (buff-menu-24962):
* test/lisp/calendar/icalendar-tests.el (icalendar-tests--do-test-export):
* test/lisp/calendar/todo-mode-tests.el (with-todo-test):
* test/lisp/dired-tests.el
(dired-test-bug27243-01, dired-test-bug27243-02)
(dired-test-bug27243-03, dired-test-bug27631)
(dired-test-bug27968, dired-test-with-temp-dirs):
* test/lisp/dired-x-tests.el (dired-test-bug25942):
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--with-temp-file):
* test/lisp/emacs-lisp/check-declare-tests.el (check-declare-tests-scan)
(check-declare-tests-verify-mismatch):
* test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-with-normal-env):
* test/lisp/emacs-lisp/package-tests.el (with-package-test)
(package-test-signed):
* test/lisp/emacs-lisp/testcover-tests.el (testcover-tests-markup-region)
(testcover-tests-run-test-case):
* test/lisp/emulation/viper-tests.el (viper-test-undo-kmacro):
* test/lisp/epg-tests.el (with-epg-tests):
* test/lisp/eshell/em-hist-tests.el (eshell-write-readonly-history):
* test/lisp/eshell/em-ls-tests.el (em-ls-test-bug27631):
* test/lisp/ffap-tests.el (ffap-tests-25243):
* test/lisp/files-tests.el (files-tests-bug-18141)
(files-tests-read-file-in-~, files-tests-make-directory)
(files-tests-copy-directory, files-tests-executable-find)
(files-tests-dont-rewrite-precious-files)
(files-tests--save-some-buffers):
* test/lisp/ls-lisp-tests.el (ls-lisp-test-bug27631):
* test/lisp/mail/uudecode-tests.el (uudecode-tests-decode-region-internal)
(uudecode-tests-decode-region-external):
* test/lisp/net/browse-url-tests.el (browse-url-tests-delete-temp-file):
* test/lisp/progmodes/elisp-mode-tests.el (xref--case-insensitive):
* test/lisp/progmodes/etags-tests.el (etags-buffer-local-tags-table-list):
* test/lisp/progmodes/flymake-tests.el (ruby-backend):
* test/lisp/progmodes/python-tests.el (python-tests-with-temp-file):
* test/lisp/progmodes/sql-tests.el (with-sql-test-connect-harness):
* test/lisp/saveplace-tests.el (saveplace-test-save-place-to-alist/file)
(saveplace-test-forget-unreadable-files)
(saveplace-test-place-alist-to-file):
* test/lisp/so-long-tests/spelling-tests.el:
* test/lisp/textmodes/reftex-tests.el (reftex-locate-bibliography-files)
(reftex-parse-from-file-test):
* test/lisp/thumbs-tests.el (thumbs-tests-thumbsdir/create-if-missing):
* test/lisp/vc/vc-bzr-tests.el (vc-bzr-test-bug9726)
(vc-bzr-test-bug9781, vc-bzr-test-faulty-bzr-autoloads):
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-ignore-trailing-dashes):
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug26084):
* test/lisp/wdired-tests.el (wdired-test-bug32173-01)
(wdired-test-bug32173-02, wdired-test-symlink-name)
(wdired-test-unfinished-edit-01, wdired-test-bug34915)
(wdired-test-bug39280):
* test/src/buffer-tests.el (test-kill-buffer-auto-save-default):
* test/src/filelock-tests.el (filelock-tests--fixture):
* test/src/inotify-tests.el (inotify-file-watch-simple):
* test/src/undo-tests.el (undo-test-file-modified): Prefer
'ert-with-temp-(directory|file)' to using 'make-temp-file' directly.
In some cases, this is just cleanup, but in several cases this fixes
bugs where an error would have lead to us not cleaning up.
2021-11-06 23:20:59 +01:00
|
|
|
(ert-with-temp-file viper-custom-file-name
|
|
|
|
;; viper loads this even with -q so make sure it's empty!
|
|
|
|
:prefix "emacs-viper-tests" :suffix ".elc"
|
|
|
|
(let (;; Viper just turns itself off during batch use.
|
|
|
|
(noninteractive nil)
|
|
|
|
;; Switch off start up message or it will chew the key presses.
|
|
|
|
(viper-inhibit-startup-message 't)
|
|
|
|
;; Select an expert-level for the same reason.
|
|
|
|
(viper-expert-level 5)
|
|
|
|
(before-buffer (current-buffer)))
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
;; viper-mode is essentially global, so set it here.
|
|
|
|
(viper-mode)
|
|
|
|
;; We must switch to buffer because we are using a keyboard macro
|
|
|
|
;; which appears to not go to the current-buffer but what ever is
|
|
|
|
;; currently taking keyboard events. We use a named buffer because
|
|
|
|
;; then we can see what it in it if it all goes wrong.
|
|
|
|
(switch-to-buffer
|
|
|
|
(get-buffer-create
|
|
|
|
"*viper-test-buffer*"))
|
|
|
|
(erase-buffer)
|
|
|
|
;; The new buffer fails to enter vi state so set it.
|
|
|
|
(viper-change-state-to-vi)
|
|
|
|
;; Run the macro.
|
|
|
|
(execute-kbd-macro kmacro)
|
|
|
|
(let ((rtn
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
(point-min)
|
|
|
|
(point-max))))
|
|
|
|
;; Kill the buffer iff the macro succeeds.
|
|
|
|
(kill-buffer)
|
|
|
|
rtn))
|
|
|
|
;; Switch everything off and restore the buffer.
|
|
|
|
(toggle-viper-mode)
|
|
|
|
(switch-to-buffer before-buffer)))))
|
2016-05-23 10:39:26 +01:00
|
|
|
|
|
|
|
(ert-deftest viper-test-fix ()
|
|
|
|
"Test that the viper kmacro fixture is working."
|
|
|
|
(should
|
|
|
|
(viper-test-undo-kmacro [])))
|
|
|
|
|
|
|
|
(ert-deftest viper-test-undo-1 ()
|
2016-08-05 13:31:10 -07:00
|
|
|
"Test for VI like undo behavior.
|
2016-05-23 10:39:26 +01:00
|
|
|
|
|
|
|
Insert 1, then 2 on consecutive lines, followed by undo. This
|
|
|
|
should leave just 1 in the buffer.
|
|
|
|
|
|
|
|
Test for Bug #22295"
|
|
|
|
(should
|
|
|
|
(equal
|
|
|
|
"1\n"
|
|
|
|
(viper-test-undo-kmacro
|
|
|
|
[
|
|
|
|
?a
|
|
|
|
?1
|
|
|
|
escape
|
|
|
|
?o
|
|
|
|
?2
|
|
|
|
escape
|
|
|
|
?u
|
|
|
|
]
|
|
|
|
))))
|
|
|
|
|
|
|
|
(ert-deftest viper-test-undo-2 ()
|
2016-08-05 13:31:10 -07:00
|
|
|
"Test for VI like undo behavior.
|
2016-05-23 10:39:26 +01:00
|
|
|
|
|
|
|
Insert \"1 2 3 4 5\" then delete the 2, then the 4, and undo.
|
|
|
|
Should restore the 4, but leave the 2 deleted.
|
|
|
|
|
|
|
|
Test for Bug #22295"
|
|
|
|
(should
|
|
|
|
(equal
|
|
|
|
"1 3 4 5\n"
|
|
|
|
(viper-test-undo-kmacro
|
|
|
|
[
|
|
|
|
?i
|
|
|
|
?1 ? ?2 ? ?3 ? ?4 ? ?5
|
|
|
|
escape
|
|
|
|
?F ?2 ?d ?w
|
|
|
|
?w ?d ?w
|
|
|
|
?u
|
|
|
|
]))))
|
|
|
|
|
|
|
|
(ert-deftest viper-test-undo-3 ()
|
2016-08-05 13:31:10 -07:00
|
|
|
"Test for VI like undo behavior.
|
2016-05-23 10:39:26 +01:00
|
|
|
|
|
|
|
Insert \"1 2 3 4 5 6\", delete the 2, then the 3 4 and 5.
|
|
|
|
Should restore the 3 4 and 5 but not the 2.
|
|
|
|
|
|
|
|
Test for Bug #22295"
|
|
|
|
(should
|
|
|
|
(equal
|
|
|
|
"1 3 4 5 6\n"
|
|
|
|
(viper-test-undo-kmacro
|
|
|
|
[
|
|
|
|
;; Insert this lot.
|
|
|
|
?i ?1 ? ?2 ? ?3 ? ?4 ? ?5 ? ?6
|
|
|
|
escape
|
|
|
|
;; Start of line.
|
|
|
|
?0
|
|
|
|
;; Move to 2, delete
|
|
|
|
?w ?d ?w
|
|
|
|
;; Delete 3 4 5
|
|
|
|
?. ?. ?.
|
|
|
|
;; Undo del 5, then
|
|
|
|
?u ?. ?.
|
|
|
|
]))))
|
|
|
|
|
|
|
|
|
|
|
|
(ert-deftest viper-test-undo-4()
|
|
|
|
(should
|
|
|
|
(equal
|
|
|
|
""
|
|
|
|
(viper-test-undo-kmacro
|
|
|
|
[
|
|
|
|
?i ?1 escape
|
|
|
|
?o ?2 escape
|
|
|
|
?o ?3 escape
|
|
|
|
?u ?. ?.
|
|
|
|
])
|
|
|
|
)))
|
|
|
|
|
|
|
|
;;; viper-tests.el ends here
|