aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhillip Lord2016-05-23 10:39:26 +0100
committerPhillip Lord2016-05-23 10:39:26 +0100
commitdf4a14be69bdf878df391fe78d2a3d25bd7fd139 (patch)
tree60a11e7bb2c1ac6ba2191993797645897d16cc2d
parentc0139e32f1f3bb287b04e02a69a7848d6a040003 (diff)
downloademacs-df4a14be69bdf878df391fe78d2a3d25bd7fd139.tar.gz
emacs-df4a14be69bdf878df391fe78d2a3d25bd7fd139.zip
Add automated test for viper-tests.el
-rw-r--r--test/automated/viper-tests.el160
1 files changed, 160 insertions, 0 deletions
diff --git a/test/automated/viper-tests.el b/test/automated/viper-tests.el
new file mode 100644
index 00000000000..1be92a4e1f6
--- /dev/null
+++ b/test/automated/viper-tests.el
@@ -0,0 +1,160 @@
1;;; viper-tests.el --- tests for viper.
2
3;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
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.
11;;
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.
16;;
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/'.
19
20;;; Commentary:
21
22;;; Code:
23
24
25(require 'viper)
26
27(defun viper-test-undo-kmacro (kmacro)
28 "In a clean viper buffer, run KMACRO and return `buffer-string'.
29
30This function makes as many attempts as possible to clean up
31after itself, although it will leave a buffer called
32*viper-test-buffer* if it fails (this is deliberate!)."
33 (let (
34 ;; Viper just turns itself off during batch use.
35 (noninteractive nil)
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)))
43 (unwind-protect
44 (progn
45 ;; viper-mode is essentially global, so set it here
46 (viper-mode)
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.
51 (switch-to-buffer
52 (get-buffer-create
53 "*viper-test-buffer*"))
54 (erase-buffer)
55 ;; The new buffer fails to enter vi state so set it.
56 (viper-change-state-to-vi)
57 ;; Run the macro
58 (execute-kbd-macro kmacro)
59 (let ((rtn
60 (buffer-substring-no-properties
61 (point-min)
62 (point-max))))
63 ;; Kill the buffer iff the macro succeeds
64 (kill-buffer)
65 rtn))
66 ;; switch everthing off and restore the buffer
67 (toggle-viper-mode)
68 (switch-to-buffer before-buffer))))
69
70(ert-deftest viper-test-go ()
71 "Test that this file is running."
72 (should t))
73
74(ert-deftest viper-test-fix ()
75 "Test that the viper kmacro fixture is working."
76 (should
77 (viper-test-undo-kmacro [])))
78
79(ert-deftest viper-test-undo-1 ()
80 "Test for VI like undo behaviour.
81
82Insert 1, then 2 on consecutive lines, followed by undo. This
83should leave just 1 in the buffer.
84
85Test for Bug #22295"
86 (should
87 (equal
88 "1\n"
89 (viper-test-undo-kmacro
90 [
91 ?a
92 ?1
93 escape
94 ?o
95 ?2
96 escape
97 ?u
98 ]
99 ))))
100
101(ert-deftest viper-test-undo-2 ()
102 "Test for VI like undo behaviour.
103
104Insert \"1 2 3 4 5\" then delete the 2, then the 4, and undo.
105Should restore the 4, but leave the 2 deleted.
106
107Test for Bug #22295"
108 (should
109 (equal
110 "1 3 4 5\n"
111 (viper-test-undo-kmacro
112 [
113 ?i
114 ?1 ? ?2 ? ?3 ? ?4 ? ?5
115 escape
116 ?F ?2 ?d ?w
117 ?w ?d ?w
118 ?u
119 ]))))
120
121(ert-deftest viper-test-undo-3 ()
122 "Test for VI like undo behaviour.
123
124Insert \"1 2 3 4 5 6\", delete the 2, then the 3 4 and 5.
125Should restore the 3 4 and 5 but not the 2.
126
127Test for Bug #22295"
128 (should
129 (equal
130 "1 3 4 5 6\n"
131 (viper-test-undo-kmacro
132 [
133 ;; Insert this lot.
134 ?i ?1 ? ?2 ? ?3 ? ?4 ? ?5 ? ?6
135 escape
136 ;; Start of line.
137 ?0
138 ;; Move to 2, delete
139 ?w ?d ?w
140 ;; Delete 3 4 5
141 ?. ?. ?.
142 ;; Undo del 5, then
143 ?u ?. ?.
144 ]))))
145
146
147(ert-deftest viper-test-undo-4()
148 (should
149 (equal
150 ""
151 (viper-test-undo-kmacro
152 [
153 ?i ?1 escape
154 ?o ?2 escape
155 ?o ?3 escape
156 ?u ?. ?.
157 ])
158 )))
159
160;;; viper-tests.el ends here