1 ;;; viper-tests.el --- tests for viper.
3 ;; Copyright (C) 2016 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; This program is free software: you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see `http://www.gnu.org/licenses/'.
27 (defun viper-test-undo-kmacro (kmacro)
28 "In a clean viper buffer, run KMACRO and return `buffer-string'.
30 This function makes as many attempts as possible to clean up
31 after itself, although it will leave a buffer called
32 *viper-test-buffer* if it fails (this is deliberate!)."
34 ;; Viper just turns itself off during batch use.
36 ;; Switch off start up message or it will chew the key presses
37 (viper-inhibit-startup-message 't)
38 ;; Select an expert-level for the same reason.
39 (viper-expert-level 5)
40 ;; viper loads this even with -q so make sure it's empty!
41 (viper-custom-file-name (make-temp-file "viper-tests"))
42 (before-buffer (current-buffer)))
45 ;; viper-mode is essentially global, so set it here
47 ;; We must switch to buffer because we are using a keyboard macro
48 ;; which appears to not go to the current-buffer but what ever is
49 ;; currently taking keyboard events. We use a named buffer because
50 ;; then we can see what it in it if it all goes wrong.
53 "*viper-test-buffer*"))
55 ;; The new buffer fails to enter vi state so set it.
56 (viper-change-state-to-vi)
58 (execute-kbd-macro kmacro)
60 (buffer-substring-no-properties
63 ;; Kill the buffer iff the macro succeeds
66 ;; switch everthing off and restore the buffer
68 (switch-to-buffer before-buffer))))
70 (ert-deftest viper-test-go ()
71 "Test that this file is running."
74 (ert-deftest viper-test-fix ()
75 "Test that the viper kmacro fixture is working."
77 (viper-test-undo-kmacro [])))
79 (ert-deftest viper-test-undo-1 ()
80 "Test for VI like undo behaviour.
82 Insert 1, then 2 on consecutive lines, followed by undo. This
83 should leave just 1 in the buffer.
89 (viper-test-undo-kmacro
101 (ert-deftest viper-test-undo-2 ()
102 "Test for VI like undo behaviour.
104 Insert \"1 2 3 4 5\" then delete the 2, then the 4, and undo.
105 Should restore the 4, but leave the 2 deleted.
111 (viper-test-undo-kmacro
114 ?1 ? ?2 ? ?3 ? ?4 ? ?5
121 (ert-deftest viper-test-undo-3 ()
122 "Test for VI like undo behaviour.
124 Insert \"1 2 3 4 5 6\", delete the 2, then the 3 4 and 5.
125 Should restore the 3 4 and 5 but not the 2.
131 (viper-test-undo-kmacro
134 ?i ?1 ? ?2 ? ?3 ? ?4 ? ?5 ? ?6
147 (ert-deftest viper-test-undo-4()
151 (viper-test-undo-kmacro
160 ;;; viper-tests.el ends here