aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVibhav Pant2017-02-11 19:54:37 +0530
committerVibhav Pant2017-02-11 19:54:37 +0530
commitc1a9b5db0e2985e7c46fb3b1e50e9d17785f7fa3 (patch)
treea33cb8c57d628541baee88bef5b0907327056e88 /test
parenta75d080b17a6b6c6296ff4e24d8129d77bb3bb6b (diff)
parentac83b2dfe4504babfbafc5efb37dbde4bed34fed (diff)
downloademacs-c1a9b5db0e2985e7c46fb3b1e50e9d17785f7fa3.tar.gz
emacs-c1a9b5db0e2985e7c46fb3b1e50e9d17785f7fa3.zip
Merge branch 'master' into feature/byte-switch
Diffstat (limited to 'test')
-rw-r--r--test/lisp/filenotify-tests.el4
-rw-r--r--test/lisp/progmodes/bat-mode-tests.el86
-rw-r--r--test/src/fns-tests.el298
3 files changed, 388 insertions, 0 deletions
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el
index 27434bcef20..dcd83a3ef3b 100644
--- a/test/lisp/filenotify-tests.el
+++ b/test/lisp/filenotify-tests.el
@@ -676,6 +676,9 @@ delivered."
676 buf) 676 buf)
677 (unwind-protect 677 (unwind-protect
678 (progn 678 (progn
679 ;; In the remote case, `vc-refresh-state' returns undesired
680 ;; error messages. Let's suppress them.
681 (advice-add 'vc-refresh-state :around 'ignore)
679 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) 682 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
680 (write-region 683 (write-region
681 "any text" nil file-notify--test-tmpfile nil 'no-message) 684 "any text" nil file-notify--test-tmpfile nil 'no-message)
@@ -745,6 +748,7 @@ delivered."
745 (file-notify--test-cleanup-p)) 748 (file-notify--test-cleanup-p))
746 749
747 ;; Cleanup. 750 ;; Cleanup.
751 (advice-remove 'vc-refresh-state 'ignore)
748 (ignore-errors (kill-buffer buf)) 752 (ignore-errors (kill-buffer buf))
749 (file-notify--test-cleanup)))) 753 (file-notify--test-cleanup))))
750 754
diff --git a/test/lisp/progmodes/bat-mode-tests.el b/test/lisp/progmodes/bat-mode-tests.el
new file mode 100644
index 00000000000..565718eea41
--- /dev/null
+++ b/test/lisp/progmodes/bat-mode-tests.el
@@ -0,0 +1,86 @@
1;;; bat-mode-tests.el --- Tests for bat-mode.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2017 Free Software Foundation, Inc.
4
5;; Author: Vladimir Panteleev <vladimir@thecybershadow.net>
6;; Keywords:
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;;
26
27;;; Code:
28
29(require 'ert)
30(require 'bat-mode)
31(require 'htmlfontify)
32
33(defun bat-test-fontify (str)
34 "Fontify STR in `bat-mode' to a HTML string using `htmlfontify' and return it."
35 (with-temp-buffer
36 (insert str)
37 (bat-mode)
38 (let ((hfy-optimizations '(body-text-only merge-adjacent-tags)))
39 (with-current-buffer (htmlfontify-buffer) (buffer-string)))))
40
41(ert-deftest bat-test-fontification-var-decl ()
42 "Test fontification of variable declarations."
43 (should
44 (equal
45 (bat-test-fontify "set a_b-c{d}e=f")
46 "<span class=\"builtin\">set</span> <span class=\"variable-name\">a_b-c{d}e</span>=f")))
47
48(ert-deftest bat-test-fontification-var-exp ()
49 "Test fontification of variable expansions."
50 (should
51 (equal
52 (bat-test-fontify "echo %a_b-c{d}e%")
53 "<span class=\"builtin\">echo</span> %<span class=\"variable-name\">a_b-c{d}e</span>%")))
54
55(ert-deftest bat-test-fontification-var-delayed-exp ()
56 "Test fontification of delayed variable expansions."
57 (should
58 (equal
59 (bat-test-fontify "echo !a_b-c{d}e!")
60 "<span class=\"builtin\">echo</span> !<span class=\"variable-name\">a_b-c{d}e</span>!")))
61
62(ert-deftest bat-test-fontification-iter-var-1 ()
63 "Test fontification of iteration variables."
64 (should
65 (equal
66 (bat-test-fontify "echo %%a\necho %%~dp1\necho %%~$PATH:I")
67 "<span class=\"builtin\">echo</span> %%<span class=\"variable-name\">a</span>
68<span class=\"builtin\">echo</span> %%~dp<span class=\"variable-name\">1</span>
69<span class=\"builtin\">echo</span> %%~$<span class=\"variable-name\">PATH</span>:<span class=\"variable-name\">I</span>")))
70
71(defun bat-test-fill-paragraph (str)
72 "Return the result of invoking `fill-paragraph' on STR in a `bat-mode' buffer."
73 (with-temp-buffer
74 (bat-mode)
75 (insert str)
76 (goto-char 1)
77 (font-lock-ensure)
78 (fill-paragraph)
79 (buffer-string)))
80
81(ert-deftest bat-test-fill-paragraph-comment ()
82 "Test `fill-paragraph' in a comment block."
83 (should (equal (bat-test-fill-paragraph "rem foo\nrem bar\n") "rem foo bar\n")))
84
85(provide 'bat-tests)
86;;; bat-mode-tests.el ends here
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index ee3c5dc77e4..160d0f106e9 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -245,3 +245,301 @@
245 (let ((data '((foo) (bar)))) 245 (let ((data '((foo) (bar))))
246 (should (equal (mapcan #'identity data) '(foo bar))) 246 (should (equal (mapcan #'identity data) '(foo bar)))
247 (should (equal data '((foo bar) (bar)))))) 247 (should (equal data '((foo bar) (bar))))))
248
249;; Test handling of cyclic and dotted lists.
250
251(defun cyc1 (a)
252 (let ((ls (make-list 10 a)))
253 (nconc ls ls)
254 ls))
255
256(defun cyc2 (a b)
257 (let ((ls1 (make-list 10 a))
258 (ls2 (make-list 1000 b)))
259 (nconc ls2 ls2)
260 (nconc ls1 ls2)
261 ls1))
262
263(defun dot1 (a)
264 (let ((ls (make-list 10 a)))
265 (nconc ls 'tail)
266 ls))
267
268(defun dot2 (a b)
269 (let ((ls1 (make-list 10 a))
270 (ls2 (make-list 10 b)))
271 (nconc ls1 ls2)
272 (nconc ls2 'tail)
273 ls1))
274
275(ert-deftest test-cycle-length ()
276 (should-error (length (cyc1 1)) :type 'circular-list)
277 (should-error (length (cyc2 1 2)) :type 'circular-list)
278 (should-error (length (dot1 1)) :type 'wrong-type-argument)
279 (should-error (length (dot2 1 2)) :type 'wrong-type-argument))
280
281(ert-deftest test-cycle-safe-length ()
282 (should (<= 10 (safe-length (cyc1 1))))
283 (should (<= 1010 (safe-length (cyc2 1 2))))
284 (should (= 10 (safe-length (dot1 1))))
285 (should (= 20 (safe-length (dot2 1 2)))))
286
287(ert-deftest test-cycle-member ()
288 (let ((c1 (cyc1 1))
289 (c2 (cyc2 1 2))
290 (d1 (dot1 1))
291 (d2 (dot2 1 2)))
292 (should (member 1 c1))
293 (should (member 1 c2))
294 (should (member 1 d1))
295 (should (member 1 d2))
296 (should-error (member 2 c1) :type 'circular-list)
297 (should (member 2 c2))
298 (should-error (member 2 d1) :type 'wrong-type-argument)
299 (should (member 2 d2))
300 (should-error (member 3 c1) :type 'circular-list)
301 (should-error (member 3 c2) :type 'circular-list)
302 (should-error (member 3 d1) :type 'wrong-type-argument)
303 (should-error (member 3 d2) :type 'wrong-type-argument)))
304
305(ert-deftest test-cycle-memq ()
306 (let ((c1 (cyc1 1))
307 (c2 (cyc2 1 2))
308 (d1 (dot1 1))
309 (d2 (dot2 1 2)))
310 (should (memq 1 c1))
311 (should (memq 1 c2))
312 (should (memq 1 d1))
313 (should (memq 1 d2))
314 (should-error (memq 2 c1) :type 'circular-list)
315 (should (memq 2 c2))
316 (should-error (memq 2 d1) :type 'wrong-type-argument)
317 (should (memq 2 d2))
318 (should-error (memq 3 c1) :type 'circular-list)
319 (should-error (memq 3 c2) :type 'circular-list)
320 (should-error (memq 3 d1) :type 'wrong-type-argument)
321 (should-error (memq 3 d2) :type 'wrong-type-argument)))
322
323(ert-deftest test-cycle-memql ()
324 (let ((c1 (cyc1 1))
325 (c2 (cyc2 1 2))
326 (d1 (dot1 1))
327 (d2 (dot2 1 2)))
328 (should (memql 1 c1))
329 (should (memql 1 c2))
330 (should (memql 1 d1))
331 (should (memql 1 d2))
332 (should-error (memql 2 c1) :type 'circular-list)
333 (should (memql 2 c2))
334 (should-error (memql 2 d1) :type 'wrong-type-argument)
335 (should (memql 2 d2))
336 (should-error (memql 3 c1) :type 'circular-list)
337 (should-error (memql 3 c2) :type 'circular-list)
338 (should-error (memql 3 d1) :type 'wrong-type-argument)
339 (should-error (memql 3 d2) :type 'wrong-type-argument)))
340
341(ert-deftest test-cycle-assq ()
342 (let ((c1 (cyc1 '(1)))
343 (c2 (cyc2 '(1) '(2)))
344 (d1 (dot1 '(1)))
345 (d2 (dot2 '(1) '(2))))
346 (should (assq 1 c1))
347 (should (assq 1 c2))
348 (should (assq 1 d1))
349 (should (assq 1 d2))
350 (should-error (assq 2 c1) :type 'circular-list)
351 (should (assq 2 c2))
352 (should-error (assq 2 d1) :type 'wrong-type-argument)
353 (should (assq 2 d2))
354 (should-error (assq 3 c1) :type 'circular-list)
355 (should-error (assq 3 c2) :type 'circular-list)
356 (should-error (assq 3 d1) :type 'wrong-type-argument)
357 (should-error (assq 3 d2) :type 'wrong-type-argument)))
358
359(ert-deftest test-cycle-assoc ()
360 (let ((c1 (cyc1 '(1)))
361 (c2 (cyc2 '(1) '(2)))
362 (d1 (dot1 '(1)))
363 (d2 (dot2 '(1) '(2))))
364 (should (assoc 1 c1))
365 (should (assoc 1 c2))
366 (should (assoc 1 d1))
367 (should (assoc 1 d2))
368 (should-error (assoc 2 c1) :type 'circular-list)
369 (should (assoc 2 c2))
370 (should-error (assoc 2 d1) :type 'wrong-type-argument)
371 (should (assoc 2 d2))
372 (should-error (assoc 3 c1) :type 'circular-list)
373 (should-error (assoc 3 c2) :type 'circular-list)
374 (should-error (assoc 3 d1) :type 'wrong-type-argument)
375 (should-error (assoc 3 d2) :type 'wrong-type-argument)))
376
377(ert-deftest test-cycle-rassq ()
378 (let ((c1 (cyc1 '(0 . 1)))
379 (c2 (cyc2 '(0 . 1) '(0 . 2)))
380 (d1 (dot1 '(0 . 1)))
381 (d2 (dot2 '(0 . 1) '(0 . 2))))
382 (should (rassq 1 c1))
383 (should (rassq 1 c2))
384 (should (rassq 1 d1))
385 (should (rassq 1 d2))
386 (should-error (rassq 2 c1) :type 'circular-list)
387 (should (rassq 2 c2))
388 (should-error (rassq 2 d1) :type 'wrong-type-argument)
389 (should (rassq 2 d2))
390 (should-error (rassq 3 c1) :type 'circular-list)
391 (should-error (rassq 3 c2) :type 'circular-list)
392 (should-error (rassq 3 d1) :type 'wrong-type-argument)
393 (should-error (rassq 3 d2) :type 'wrong-type-argument)))
394
395(ert-deftest test-cycle-rassoc ()
396 (let ((c1 (cyc1 '(0 . 1)))
397 (c2 (cyc2 '(0 . 1) '(0 . 2)))
398 (d1 (dot1 '(0 . 1)))
399 (d2 (dot2 '(0 . 1) '(0 . 2))))
400 (should (rassoc 1 c1))
401 (should (rassoc 1 c2))
402 (should (rassoc 1 d1))
403 (should (rassoc 1 d2))
404 (should-error (rassoc 2 c1) :type 'circular-list)
405 (should (rassoc 2 c2))
406 (should-error (rassoc 2 d1) :type 'wrong-type-argument)
407 (should (rassoc 2 d2))
408 (should-error (rassoc 3 c1) :type 'circular-list)
409 (should-error (rassoc 3 c2) :type 'circular-list)
410 (should-error (rassoc 3 d1) :type 'wrong-type-argument)
411 (should-error (rassoc 3 d2) :type 'wrong-type-argument)))
412
413(ert-deftest test-cycle-delq ()
414 (should-error (delq 1 (cyc1 1)) :type 'circular-list)
415 (should-error (delq 1 (cyc2 1 2)) :type 'circular-list)
416 (should-error (delq 1 (dot1 1)) :type 'wrong-type-argument)
417 (should-error (delq 1 (dot2 1 2)) :type 'wrong-type-argument)
418 (should-error (delq 2 (cyc1 1)) :type 'circular-list)
419 (should-error (delq 2 (cyc2 1 2)) :type 'circular-list)
420 (should-error (delq 2 (dot1 1)) :type 'wrong-type-argument)
421 (should-error (delq 2 (dot2 1 2)) :type 'wrong-type-argument)
422 (should-error (delq 3 (cyc1 1)) :type 'circular-list)
423 (should-error (delq 3 (cyc2 1 2)) :type 'circular-list)
424 (should-error (delq 3 (dot1 1)) :type 'wrong-type-argument)
425 (should-error (delq 3 (dot2 1 2)) :type 'wrong-type-argument))
426
427(ert-deftest test-cycle-delete ()
428 (should-error (delete 1 (cyc1 1)) :type 'circular-list)
429 (should-error (delete 1 (cyc2 1 2)) :type 'circular-list)
430 (should-error (delete 1 (dot1 1)) :type 'wrong-type-argument)
431 (should-error (delete 1 (dot2 1 2)) :type 'wrong-type-argument)
432 (should-error (delete 2 (cyc1 1)) :type 'circular-list)
433 (should-error (delete 2 (cyc2 1 2)) :type 'circular-list)
434 (should-error (delete 2 (dot1 1)) :type 'wrong-type-argument)
435 (should-error (delete 2 (dot2 1 2)) :type 'wrong-type-argument)
436 (should-error (delete 3 (cyc1 1)) :type 'circular-list)
437 (should-error (delete 3 (cyc2 1 2)) :type 'circular-list)
438 (should-error (delete 3 (dot1 1)) :type 'wrong-type-argument)
439 (should-error (delete 3 (dot2 1 2)) :type 'wrong-type-argument))
440
441(ert-deftest test-cycle-reverse ()
442 (should-error (reverse (cyc1 1)) :type 'circular-list)
443 (should-error (reverse (cyc2 1 2)) :type 'circular-list)
444 (should-error (reverse (dot1 1)) :type 'wrong-type-argument)
445 (should-error (reverse (dot2 1 2)) :type 'wrong-type-argument))
446
447(ert-deftest test-cycle-plist-get ()
448 (let ((c1 (cyc1 1))
449 (c2 (cyc2 1 2))
450 (d1 (dot1 1))
451 (d2 (dot2 1 2)))
452 (should (plist-get c1 1))
453 (should (plist-get c2 1))
454 (should (plist-get d1 1))
455 (should (plist-get d2 1))
456 (should-not (plist-get c1 2))
457 (should (plist-get c2 2))
458 (should-not (plist-get d1 2))
459 (should (plist-get d2 2))
460 (should-not (plist-get c1 3))
461 (should-not (plist-get c2 3))
462 (should-not (plist-get d1 3))
463 (should-not (plist-get d2 3))))
464
465(ert-deftest test-cycle-lax-plist-get ()
466 (let ((c1 (cyc1 1))
467 (c2 (cyc2 1 2))
468 (d1 (dot1 1))
469 (d2 (dot2 1 2)))
470 (should (lax-plist-get c1 1))
471 (should (lax-plist-get c2 1))
472 (should (lax-plist-get d1 1))
473 (should (lax-plist-get d2 1))
474 (should-error (lax-plist-get c1 2) :type 'circular-list)
475 (should (lax-plist-get c2 2))
476 (should-not (lax-plist-get d1 2))
477 (should (lax-plist-get d2 2))
478 (should-error (lax-plist-get c1 3) :type 'circular-list)
479 (should-error (lax-plist-get c2 3) :type 'circular-list)
480 (should-not (lax-plist-get d1 3))
481 (should-not (lax-plist-get d2 3))))
482
483(ert-deftest test-cycle-plist-member ()
484 (let ((c1 (cyc1 1))
485 (c2 (cyc2 1 2))
486 (d1 (dot1 1))
487 (d2 (dot2 1 2)))
488 (should (plist-member c1 1))
489 (should (plist-member c2 1))
490 (should (plist-member d1 1))
491 (should (plist-member d2 1))
492 (should-error (plist-member c1 2) :type 'circular-list)
493 (should (plist-member c2 2))
494 (should-error (plist-member d1 2) :type 'wrong-type-argument)
495 (should (plist-member d2 2))
496 (should-error (plist-member c1 3) :type 'circular-list)
497 (should-error (plist-member c2 3) :type 'circular-list)
498 (should-error (plist-member d1 3) :type 'wrong-type-argument)
499 (should-error (plist-member d2 3) :type 'wrong-type-argument)))
500
501(ert-deftest test-cycle-plist-put ()
502 (let ((c1 (cyc1 1))
503 (c2 (cyc2 1 2))
504 (d1 (dot1 1))
505 (d2 (dot2 1 2)))
506 (should (plist-put c1 1 1))
507 (should (plist-put c2 1 1))
508 (should (plist-put d1 1 1))
509 (should (plist-put d2 1 1))
510 (should-error (plist-put c1 2 2) :type 'circular-list)
511 (should (plist-put c2 2 2))
512 (should (plist-put d1 2 2))
513 (should (plist-put d2 2 2))
514 (should-error (plist-put c1 3 3) :type 'circular-list)
515 (should-error (plist-put c2 3 3) :type 'circular-list)
516 (should (plist-put d1 3 3))
517 (should (plist-put d2 3 3))))
518
519(ert-deftest test-cycle-lax-plist-put ()
520 (let ((c1 (cyc1 1))
521 (c2 (cyc2 1 2))
522 (d1 (dot1 1))
523 (d2 (dot2 1 2)))
524 (should (lax-plist-put c1 1 1))
525 (should (lax-plist-put c2 1 1))
526 (should (lax-plist-put d1 1 1))
527 (should (lax-plist-put d2 1 1))
528 (should-error (lax-plist-put c1 2 2) :type 'circular-list)
529 (should (lax-plist-put c2 2 2))
530 (should (lax-plist-put d1 2 2))
531 (should (lax-plist-put d2 2 2))
532 (should-error (lax-plist-put c1 3 3) :type 'circular-list)
533 (should-error (lax-plist-put c2 3 3) :type 'circular-list)
534 (should (lax-plist-put d1 3 3))
535 (should (lax-plist-put d2 3 3))))
536
537(ert-deftest test-cycle-equal ()
538 (should-error (equal (cyc1 1) (cyc1 1)))
539 (should-error (equal (cyc2 1 2) (cyc2 1 2))))
540
541(ert-deftest test-cycle-nconc ()
542 (should-error (nconc (cyc1 1) 'tail) :type 'circular-list)
543 (should-error (nconc (cyc2 1 2) 'tail) :type 'circular-list))
544
545(provide 'fns-tests)