4 ;; (defmacro with-named-temp-buffer (name &rest body)
5 ;; (declare (indent with-current-buffer))
7 ;; (with-current-buffer (get-buffer-create ,name)
9 ;; (and (get-buffer ,name) (kill-buffer ,name))))
11 ;; (ert-deftest test-compilation ()
12 ;; (should (zerop (call-process "emacs" nil nil nil
13 ;; "-batch" "-Q" "-f" "batch-byte-compile"
16 (ert-deftest test-easy-kill-trim ()
17 (should (string= "" (easy-kill-trim " \f\t\n\n\n")))
18 (should (string= "abc" (easy-kill-trim " \t\fabc")))
19 (should (string= "abc" (easy-kill-trim "abc")))
20 (should (string= " \t\fabc" (easy-kill-trim " \t\fabc" 'right)))
21 (should (string= "abc" (easy-kill-trim " \t\fabc" 'left))))
23 (ert-deftest test-easy-kill-get ()
27 (setf (easy-kill-get bounds) '(1 . 4))
28 (should (string= (easy-kill-candidate) "two"))
29 (should-error (setf (easy-kill-get bounds) nil))
30 (setf (easy-kill-get end) (point-max))
31 (should (= (easy-kill-get end) (point-max)))))
33 (ert-deftest test-easy-kill-candidate ()
37 (should-error (easy-kill-candidate))
39 (easy-kill-thing 'word)
40 (should (string= w (easy-kill-candidate)))
41 (easy-kill-thing 'buffer-file-name)
42 (should (string= (directory-file-name default-directory)
43 (easy-kill-candidate))))))
45 (ert-deftest test-easy-kill-describe-candidate ()
47 (insert "(list 1 2 3)")
50 (easy-kill-thing 'sexp)
51 (easy-kill-thing 'list)
52 (should (string-match-p "^\\s-*thing:\\s-*list"
53 (easy-kill-describe-candidate)))))
55 (ert-deftest test-easy-kill-append ()
59 (easy-kill-thing 'word)
60 (call-interactively #'easy-kill-append)
61 (should (string= (car kill-ring) "abc"))))
63 ;;; Make sure the old format of easy-kill-alist is still supported.
64 (ert-deftest test-old-easy-kill-alist ()
65 (let ((easy-kill-alist '((?w . word)
71 (?b . buffer-file-name)))
72 (text "(first line\nsecond line\nthird line)"))
75 (goto-char (point-min))
77 (let ((last-command-event ?d))
78 (call-interactively #'easy-kill-thing))
79 (should (string= text (easy-kill-candidate))))))
81 (ert-deftest test-easy-kill-help ()
82 (let ((easy-kill-alist '((?w . word)
88 (?b . buffer-file-name)
89 (?x buffer-file-name-buffer-file-name "\t"))))
91 (with-current-buffer (help-buffer)
92 (goto-char (point-min))
93 (should (save-excursion
94 (re-search-forward "^w\\s-*word$" nil t)))
95 (should (save-excursion
96 (re-search-forward "^d\\s-*defun\\s-*\"\\\\n\\\\n\"$" nil t)))
97 (should (save-excursion
98 (re-search-forward "^f\\s-*filename$" nil t)))
99 (should (save-excursion
100 (re-search-forward "^b\\s-*buffer-file-name$" nil t))))))
102 (ert-deftest test-easy-kill-thing-handler ()
103 (should (eq (easy-kill-thing-handler "easy-kill-on-list" 'nxml-mode)
104 'easy-kill-on-list:nxml))
105 (should (eq (easy-kill-thing-handler "easy-kill-on-list" 'js2-mode)
106 'easy-kill-on-list:js2))
107 (should (eq (easy-kill-thing-handler "easy-kill-on-sexp" 'nxml-mode)
110 (fset 'js2:easy-kill-on-list #'ignore)
111 (eq (easy-kill-thing-handler "easy-kill-on-sexp" 'js2-mode)
112 'js2:easy-kill-on-list))
114 (ert-deftest test-easy-kill-bounds-of-list-at-point ()
115 (let ((text "\"abc (1 2 3) xyz\" ; dummy comment")
118 (should (string= \"display editor.\\nsome of the ways to customize it;\"
119 (easy-kill-candidate))))"))
120 (cl-labels ((getb (bounds)
122 (buffer-substring (car bounds) (cdr bounds))
127 (search-backward "2")
128 (should (string= (getb (easy-kill-bounds-of-list-at-point)) "(1 2 3)"))
131 (should (string= (getb (easy-kill-bounds-of-list-at-point))
132 "\"abc (1 2 3) xyz\""))
133 (search-forward "dummy")
135 (should (string= (getb (easy-kill-bounds-of-list-at-point))
140 (goto-char (point-min))
141 (re-search-forward "customize")
142 (call-interactively 'easy-kill)
143 (easy-kill-thing 'list)
144 (should (string= "\"display editor.\\nsome of the ways to customize it;\""
145 (easy-kill-candidate)))))))
147 (ert-deftest test-easy-kill-on-list ()
148 (let ((text "(defun first-error (&optional n)
149 \"This operates on the output from the \\\\[compile] command, for instance.\"
151 (next-error n t)) ;some dummy comment here"))
155 (goto-char (point-min))
156 (search-forward "[compile")
157 (call-interactively 'easy-kill)
158 (easy-kill-thing 'list)
159 (should (string= "[compile]" (easy-kill-candidate)))
161 (call-interactively 'easy-kill)
163 (cl-letf (((symbol-function 'easy-kill-interprogram-cut)
164 (lambda (text) (setq clipboard text))))
165 (easy-kill-thing 'list))
166 (should (string= (easy-kill-candidate) clipboard)))
167 (should (string= "\"This operates on the output from the \\\\[compile] command, for instance.\""
168 (easy-kill-candidate)))
169 (easy-kill-thing 'list)
170 (should (string-match-p "(interactive \"p\")" (easy-kill-candidate)))
171 (should (string-prefix-p "\"This operates on" (easy-kill-candidate)))
172 (forward-sexp 1) ; where bounds of list is nil
173 (call-interactively 'easy-kill)
174 (easy-kill-thing 'list)
175 (should (string= "\"This operates on the output from the \\\\[compile] command, for instance.\""
176 (easy-kill-candidate)))
177 (search-forward "dummy")
179 (call-interactively 'easy-kill)
180 (easy-kill-thing 'list)
181 (should (string= "dummy" (easy-kill-candidate))))))
183 (ert-deftest test-js2-mode ()
184 :expected-result :failed
185 (let ((js "function View(name, options) {
186 options = options || {};
188 this.root = options.root;
189 var engines = options.engines;
190 this.defaultEngine = options.defaultEngine;
191 var ext = this.ext = extname(name);
192 if (!ext && !this.defaultEngine) throw new Error('No default engine was specified and no extension was provided.');
193 if (!ext) name += (ext = this.ext = ('.' != this.defaultEngine[0] ? '.' : '') + this.defaultEngine);
194 this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);
195 this.path = this.lookup(name);
197 (buff (get-buffer-create "*js2*")))
198 (eval-and-compile (require 'js2-mode nil t))
199 (setq js2-idle-timer-delay 0)
200 (global-font-lock-mode 1)
202 (with-current-buffer buff
205 (goto-char (point-min))
208 (while js2-mode-buffer-dirty-p
210 (search-forward "this.defaultEngine =")
213 (easy-kill-thing 'char)
214 (easy-kill-thing 'list)
215 (should (string= "this.defaultEngine = options.defaultEngine"
216 (easy-kill-candidate)))
217 ;; XXX: should also test (easy-kill-digit-argument 0)
219 (kill-buffer buff))))
221 (ert-deftest test-nxml-mode ()
222 (let ((xml "<?xml version=\"1.0\"?>
225 <author>Gambardella, Matthew</author>
226 <title>XML Developer's Guide</title>
227 <genre>Computer</genre>
229 <publish_date>2000-10-01</publish_date>
230 <description>An in-depth look at creating applications
231 with XML.</description>
237 (goto-char (point-min))
238 (search-forward "Gambardella")
240 (easy-kill-thing 'sexp)
244 (should (eq (easy-kill-get thing) 'sexp))
245 (should (string= "<author>Gambardella, Matthew</author>"
246 (easy-kill-candidate)))
247 (call-interactively 'easy-kill)
248 (easy-kill-thing 'list)
249 (should (string= "<author>Gambardella, Matthew</author>"
250 (easy-kill-candidate)))
251 (easy-kill-thing nil 1)
252 (easy-kill-digit-argument 0)
253 (should (string= "<author>Gambardella, Matthew</author>"
254 (easy-kill-candidate))))))
256 (ert-deftest test-org-mode ()
257 (let ((org "#+title: This is a title
260 This is an example of org document.
277 (goto-char (point-min))
278 (search-forward "This is")
279 (call-interactively 'easy-kill)
280 (easy-kill-thing 'sexp)
282 (should (string= "#+title: This is a title\n" (easy-kill-candidate)))
283 (search-forward "Fruits")
284 (call-interactively 'easy-kill)
285 (easy-kill-thing 'sexp)
287 (should (string-prefix-p "*** Fruits" (easy-kill-candidate)))
288 (search-forward "Ferrari")
289 (call-interactively 'easy-kill)
290 (easy-kill-thing 'list)
291 (should (string= "Ferrari\n" (easy-kill-candidate)))
293 (should (string= " + Ferrari\n" (easy-kill-candidate)))
295 (search-backward "Lamborghini")
296 (call-interactively 'easy-kill)
297 (easy-kill-thing 'list)
298 ;; You get the whole plainlist here; see `org-element-at-point'.
300 (should (string= " + Lamborghini\n + Ferrari\n + Porsche\n"
301 (easy-kill-candidate)))
303 (should (string= "* Sports cars\n + Lamborghini\n + Ferrari\n + Porsche\n"
304 (easy-kill-candidate))))))
306 (ert-deftest test-elisp-mode ()
307 (let ((el "(defun set-hard-newline-properties (from to)
308 (let ((sticky (get-text-property from 'rear-nonsticky)))
309 ;; XXX: (put-text-property from to 'hard 't)
310 ;; If rear-nonsticky is not \"t\", add 'hard to rear-nonsticky list
311 (if (and (listp sticky) (not (memq 'hard sticky)))
312 (put-text-property from (point) 'rear-nonsticky
313 (cons 'hard sticky)))))"))
316 (goto-char (point-min))
317 (search-forward "put-text-property")
319 (easy-kill-thing 'sexp)
321 (should (eq (easy-kill-get thing) 'sexp))
322 (should (string= "(put-text-property from to 'hard 't)"
323 (easy-kill-candidate)))
326 (should (string= el (easy-kill-candidate)))
329 (should (string= "(put-text-property from to 'hard 't)"
330 (easy-kill-candidate)))
331 (easy-kill-digit-argument 0)
332 (should (string= (thing-at-point 'sexp) (easy-kill-candidate))))))
334 (ert-deftest test-easy-kill-thing-forward ()
335 (let ((txt "Emacs is the extensible
337 some of the ways to customize it;
343 (easy-kill-thing 'line)
344 (should (string= "some of the ways to customize it;\n24.3."
345 (easy-kill-candidate)))
347 (should (string= "some of the ways to customize it;\n"
348 (easy-kill-candidate)))
350 (should (string= " display editor.\nsome of the ways to customize it;\n"
351 (easy-kill-candidate)))
352 (easy-kill-thing 'word)
354 (should (string= "editor.\nsome" (easy-kill-candidate)))
356 (should (string= "display editor.\nsome" (easy-kill-candidate)))
358 (should (string= " editor.\nsome" (easy-kill-candidate)))
359 (easy-kill-destroy-candidate)
360 (goto-char (point-min))
362 (call-interactively 'easy-mark)
363 (should (string= " display" (easy-kill-candidate)))
364 (goto-char (easy-kill-get origin))
366 ;; Test the case where there is no thing at point
367 (call-interactively 'easy-kill)
368 (setf (easy-kill-get thing) 'word)
369 (setf (easy-kill-get bounds) (cons (point) (point)))
371 (should (string= " display" (easy-kill-candidate)))
375 (should (string= "the extensible\n" (easy-kill-candidate))))))
377 (ert-deftest test-workaround-defun-bug ()
378 ;; http://debbugs.gnu.org/17247
379 (let ((txt "(tan 2)\n\n(sin 2)\n(cos 2)\n"))
383 (easy-kill-thing 'defun)
385 (should (string= "(sin 2)\n(cos 2)\n" (easy-kill-candidate)))
387 (should (string= txt (easy-kill-candidate))))))
389 (ert-deftest test-easy-kill-exchange-point-and-mark ()
390 (let ((txt "(delete-region (point)
391 (if (re-search-forward \"[^ \\t\\n]\" nil t)
392 (progn (beginning-of-line) (point))
397 (goto-char (point-min))
398 (search-forward "re-search-forward")
399 (call-interactively 'easy-mark)
400 (should (string= "re-search-forward" (easy-kill-candidate)))
401 (should (= (point) (easy-kill-get end)))
402 (call-interactively 'easy-kill-exchange-point-and-mark)
404 (should (= (point) (easy-kill-get start)))
405 (should (= (mark t) (easy-kill-get end)))
406 (call-interactively 'easy-kill-exchange-point-and-mark)
408 (should (= (mark t) (easy-kill-get start)))
409 (should (= (point) (easy-kill-get end))))))