1 ;;; hydra-test.el --- Tests for Hydra
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 (message "Emacs version: %s" emacs-version)
30 (ert-deftest hydra-red-error ()
34 '(defhydra hydra-error (global-map "M-g")
36 ("h" first-error "first")
37 ("j" next-error "next")
38 ("k" previous-error "prev")
39 ("SPC" hydra-repeat "rep" :bind nil)))
42 (defvar hydra-error/keymap nil
43 "Keymap for hydra-error.")
47 (107 . hydra-error/previous-error)
48 (106 . hydra-error/next-error)
49 (104 . hydra-error/first-error)
50 (kp-subtract . hydra--negative-argument)
51 (kp-9 . hydra--digit-argument)
52 (kp-8 . hydra--digit-argument)
53 (kp-7 . hydra--digit-argument)
54 (kp-6 . hydra--digit-argument)
55 (kp-5 . hydra--digit-argument)
56 (kp-4 . hydra--digit-argument)
57 (kp-3 . hydra--digit-argument)
58 (kp-2 . hydra--digit-argument)
59 (kp-1 . hydra--digit-argument)
60 (kp-0 . hydra--digit-argument)
61 (57 . hydra--digit-argument)
62 (56 . hydra--digit-argument)
63 (55 . hydra--digit-argument)
64 (54 . hydra--digit-argument)
65 (53 . hydra--digit-argument)
66 (52 . hydra--digit-argument)
67 (51 . hydra--digit-argument)
68 (50 . hydra--digit-argument)
69 (49 . hydra--digit-argument)
70 (48 . hydra--digit-argument)
71 (45 . hydra--negative-argument)
72 (21 . hydra--universal-argument))))
74 (defvar hydra-error/heads nil
75 "Heads for hydra-error.")
94 (defun hydra-error/first-error nil
95 "Create a hydra with a \"M-g\" body and the heads:
99 \"k\": `previous-error',
100 \"SPC\": `hydra-repeat'
102 The body can be accessed via `hydra-error/body'.
104 Call the head: `first-error'."
107 (let ((hydra--ignore t))
108 (hydra-keyboard-quit))
114 (function first-error)))
117 (unless hydra-lv (sit-for 0.8))))
118 (when hydra-is-helpful
121 (eval hydra-error/hint))
123 (eval hydra-error/hint))))
124 (hydra-set-transient-map
127 (hydra-keyboard-quit)
130 (defun hydra-error/next-error nil
131 "Create a hydra with a \"M-g\" body and the heads:
133 \"h\": `first-error',
135 \"k\": `previous-error',
136 \"SPC\": `hydra-repeat'
138 The body can be accessed via `hydra-error/body'.
140 Call the head: `next-error'."
143 (let ((hydra--ignore t))
144 (hydra-keyboard-quit))
150 (function next-error)))
153 (unless hydra-lv (sit-for 0.8))))
154 (when hydra-is-helpful
157 (eval hydra-error/hint))
159 (eval hydra-error/hint))))
160 (hydra-set-transient-map
163 (hydra-keyboard-quit)
166 (defun hydra-error/previous-error nil
167 "Create a hydra with a \"M-g\" body and the heads:
169 \"h\": `first-error',
171 \"k\": `previous-error',
172 \"SPC\": `hydra-repeat'
174 The body can be accessed via `hydra-error/body'.
176 Call the head: `previous-error'."
179 (let ((hydra--ignore t))
180 (hydra-keyboard-quit))
184 (quote previous-error))
186 (function previous-error)))
189 (unless hydra-lv (sit-for 0.8))))
190 (when hydra-is-helpful
193 (eval hydra-error/hint))
195 (eval hydra-error/hint))))
196 (hydra-set-transient-map
199 (hydra-keyboard-quit)
206 (define-key global-map (kbd "M-g")
208 (define-key global-map [134217831 104]
210 hydra-error/first-error))
211 (define-key global-map [134217831 106]
213 hydra-error/next-error))
214 (define-key global-map [134217831 107]
216 hydra-error/previous-error))
218 (defvar hydra-error/hint nil
219 "Dynamic hint for hydra-error.")
222 #("error: [h]: first, [j]: next, [k]: prev, [SPC]: rep."
223 8 9 (face hydra-face-red)
224 20 21 (face hydra-face-red)
225 31 32 (face hydra-face-red)
226 42 45 (face hydra-face-red)))))
227 (defun hydra-error/body nil
228 "Create a hydra with a \"M-g\" body and the heads:
230 \"h\": `first-error',
232 \"k\": `previous-error',
233 \"SPC\": `hydra-repeat'
235 The body can be accessed via `hydra-error/body'."
238 (let ((hydra--ignore nil))
239 (hydra-keyboard-quit))
240 (when hydra-is-helpful
243 (eval hydra-error/hint))
245 (eval hydra-error/hint))))
246 (hydra-set-transient-map
249 (hydra-keyboard-quit)
253 current-prefix-arg))))))
255 (ert-deftest hydra-blue-toggle ()
259 '(defhydra hydra-toggle (:color blue)
261 ("t" toggle-truncate-lines "truncate")
262 ("f" auto-fill-mode "fill")
263 ("a" abbrev-mode "abbrev")
267 (defvar hydra-toggle/keymap nil
268 "Keymap for hydra-toggle.")
271 (113 . hydra-toggle/nil)
272 (97 . hydra-toggle/abbrev-mode-and-exit)
273 (102 . hydra-toggle/auto-fill-mode-and-exit)
274 (116 . hydra-toggle/toggle-truncate-lines-and-exit)
275 (kp-subtract . hydra--negative-argument)
276 (kp-9 . hydra--digit-argument)
277 (kp-8 . hydra--digit-argument)
278 (kp-7 . hydra--digit-argument)
279 (kp-6 . hydra--digit-argument)
280 (kp-5 . hydra--digit-argument)
281 (kp-4 . hydra--digit-argument)
282 (kp-3 . hydra--digit-argument)
283 (kp-2 . hydra--digit-argument)
284 (kp-1 . hydra--digit-argument)
285 (kp-0 . hydra--digit-argument)
286 (57 . hydra--digit-argument)
287 (56 . hydra--digit-argument)
288 (55 . hydra--digit-argument)
289 (54 . hydra--digit-argument)
290 (53 . hydra--digit-argument)
291 (52 . hydra--digit-argument)
292 (51 . hydra--digit-argument)
293 (50 . hydra--digit-argument)
294 (49 . hydra--digit-argument)
295 (48 . hydra--digit-argument)
296 (45 . hydra--negative-argument)
297 (21 . hydra--universal-argument))))
299 (defvar hydra-toggle/heads nil
300 "Heads for hydra-toggle.")
303 toggle-truncate-lines
314 ("q" nil "cancel" :exit t))))
315 (defun hydra-toggle/toggle-truncate-lines-and-exit nil
316 "Create a hydra with no body and the heads:
318 \"t\": `toggle-truncate-lines',
319 \"f\": `auto-fill-mode',
320 \"a\": `abbrev-mode',
323 The body can be accessed via `hydra-toggle/body'.
325 Call the head: `toggle-truncate-lines'."
328 (hydra-keyboard-quit)
331 (quote toggle-truncate-lines))
334 toggle-truncate-lines))))
335 (defun hydra-toggle/auto-fill-mode-and-exit nil
336 "Create a hydra with no body and the heads:
338 \"t\": `toggle-truncate-lines',
339 \"f\": `auto-fill-mode',
340 \"a\": `abbrev-mode',
343 The body can be accessed via `hydra-toggle/body'.
345 Call the head: `auto-fill-mode'."
348 (hydra-keyboard-quit)
351 (quote auto-fill-mode))
353 (function auto-fill-mode))))
354 (defun hydra-toggle/abbrev-mode-and-exit nil
355 "Create a hydra with no body and the heads:
357 \"t\": `toggle-truncate-lines',
358 \"f\": `auto-fill-mode',
359 \"a\": `abbrev-mode',
362 The body can be accessed via `hydra-toggle/body'.
364 Call the head: `abbrev-mode'."
367 (hydra-keyboard-quit)
372 (function abbrev-mode))))
373 (defun hydra-toggle/nil nil
374 "Create a hydra with no body and the heads:
376 \"t\": `toggle-truncate-lines',
377 \"f\": `auto-fill-mode',
378 \"a\": `abbrev-mode',
381 The body can be accessed via `hydra-toggle/body'.
383 Call the head: `nil'."
386 (hydra-keyboard-quit))
388 (defvar hydra-toggle/hint nil
389 "Dynamic hint for hydra-toggle.")
392 #("toggle: [t]: truncate, [f]: fill, [a]: abbrev, [q]: cancel."
393 9 10 (face hydra-face-blue)
394 24 25 (face hydra-face-blue)
395 35 36 (face hydra-face-blue)
396 48 49 (face hydra-face-blue)))))
397 (defun hydra-toggle/body nil
398 "Create a hydra with no body and the heads:
400 \"t\": `toggle-truncate-lines',
401 \"f\": `auto-fill-mode',
402 \"a\": `abbrev-mode',
405 The body can be accessed via `hydra-toggle/body'."
408 (let ((hydra--ignore nil))
409 (hydra-keyboard-quit))
410 (when hydra-is-helpful
413 (eval hydra-toggle/hint))
415 (eval hydra-toggle/hint))))
416 (hydra-set-transient-map
419 (hydra-keyboard-quit)
423 current-prefix-arg))))))
425 (ert-deftest hydra-amaranth-vi ()
431 (set-cursor-color "#e52b50")
433 (set-cursor-color "#ffffff")
441 (defvar hydra-vi/keymap nil
442 "Keymap for hydra-vi.")
446 (107 . hydra-vi/previous-line)
447 (106 . hydra-vi/next-line)
448 (kp-subtract . hydra--negative-argument)
449 (kp-9 . hydra--digit-argument)
450 (kp-8 . hydra--digit-argument)
451 (kp-7 . hydra--digit-argument)
452 (kp-6 . hydra--digit-argument)
453 (kp-5 . hydra--digit-argument)
454 (kp-4 . hydra--digit-argument)
455 (kp-3 . hydra--digit-argument)
456 (kp-2 . hydra--digit-argument)
457 (kp-1 . hydra--digit-argument)
458 (kp-0 . hydra--digit-argument)
459 (57 . hydra--digit-argument)
460 (56 . hydra--digit-argument)
461 (55 . hydra--digit-argument)
462 (54 . hydra--digit-argument)
463 (53 . hydra--digit-argument)
464 (52 . hydra--digit-argument)
465 (51 . hydra--digit-argument)
466 (50 . hydra--digit-argument)
467 (49 . hydra--digit-argument)
468 (48 . hydra--digit-argument)
469 (45 . hydra--negative-argument)
470 (21 . hydra--universal-argument))))
472 (defvar hydra-vi/heads nil
473 "Heads for hydra-vi.")
475 (("j" next-line "" :exit nil)
480 ("q" nil "quit" :exit t))))
481 (defun hydra-vi/next-line nil
482 "Create a hydra with no body and the heads:
485 \"k\": `previous-line',
488 The body can be accessed via `hydra-vi/body'.
490 Call the head: `next-line'."
493 (set-cursor-color "#e52b50")
494 (let ((hydra--ignore t))
495 (hydra-keyboard-quit))
501 (function next-line)))
504 (unless hydra-lv (sit-for 0.8))))
505 (when hydra-is-helpful
508 (eval hydra-vi/hint))
509 (message (eval hydra-vi/hint))))
510 (hydra-set-transient-map
513 (hydra-keyboard-quit)
514 (set-cursor-color "#ffffff"))
516 (defun hydra-vi/previous-line nil
517 "Create a hydra with no body and the heads:
520 \"k\": `previous-line',
523 The body can be accessed via `hydra-vi/body'.
525 Call the head: `previous-line'."
528 (set-cursor-color "#e52b50")
529 (let ((hydra--ignore t))
530 (hydra-keyboard-quit))
534 (quote previous-line))
536 (function previous-line)))
539 (unless hydra-lv (sit-for 0.8))))
540 (when hydra-is-helpful
543 (eval hydra-vi/hint))
544 (message (eval hydra-vi/hint))))
545 (hydra-set-transient-map
548 (hydra-keyboard-quit)
549 (set-cursor-color "#ffffff"))
551 (defun hydra-vi/nil nil
552 "Create a hydra with no body and the heads:
555 \"k\": `previous-line',
558 The body can be accessed via `hydra-vi/body'.
560 Call the head: `nil'."
563 (set-cursor-color "#e52b50")
564 (hydra-keyboard-quit))
566 (defvar hydra-vi/hint nil
567 "Dynamic hint for hydra-vi.")
570 #("vi: j, k, [q]: quit."
571 4 5 (face hydra-face-amaranth)
572 7 8 (face hydra-face-amaranth)
573 11 12 (face hydra-face-teal)))))
574 (defun hydra-vi/body nil
575 "Create a hydra with no body and the heads:
578 \"k\": `previous-line',
581 The body can be accessed via `hydra-vi/body'."
584 (set-cursor-color "#e52b50")
585 (let ((hydra--ignore nil))
586 (hydra-keyboard-quit))
587 (when hydra-is-helpful
590 (eval hydra-vi/hint))
591 (message (eval hydra-vi/hint))))
592 (hydra-set-transient-map
595 (hydra-keyboard-quit)
596 (set-cursor-color "#ffffff"))
599 current-prefix-arg))))))
601 (ert-deftest hydra-zoom-duplicate-1 ()
605 '(defhydra hydra-zoom ()
607 ("r" (text-scale-set 0) "reset")
608 ("0" (text-scale-set 0) :bind nil :exit t)
609 ("1" (text-scale-set 0) nil :bind nil :exit t)))
612 (defvar hydra-zoom/keymap nil
613 "Keymap for hydra-zoom.")
616 (114 . hydra-zoom/lambda-r)
617 (kp-subtract . hydra--negative-argument)
618 (kp-9 . hydra--digit-argument)
619 (kp-8 . hydra--digit-argument)
620 (kp-7 . hydra--digit-argument)
621 (kp-6 . hydra--digit-argument)
622 (kp-5 . hydra--digit-argument)
623 (kp-4 . hydra--digit-argument)
624 (kp-3 . hydra--digit-argument)
625 (kp-2 . hydra--digit-argument)
626 (kp-1 . hydra--digit-argument)
627 (kp-0 . hydra--digit-argument)
628 (57 . hydra--digit-argument)
629 (56 . hydra--digit-argument)
630 (55 . hydra--digit-argument)
631 (54 . hydra--digit-argument)
632 (53 . hydra--digit-argument)
633 (52 . hydra--digit-argument)
634 (51 . hydra--digit-argument)
635 (50 . hydra--digit-argument)
636 (49 . hydra-zoom/lambda-0-and-exit)
637 (48 . hydra-zoom/lambda-0-and-exit)
638 (45 . hydra--negative-argument)
639 (21 . hydra--universal-argument))))
641 (defvar hydra-zoom/heads nil
642 "Heads for hydra-zoom.")
658 (defun hydra-zoom/lambda-r nil
659 "Create a hydra with no body and the heads:
661 \"r\": `(text-scale-set 0)',
662 \"0\": `(text-scale-set 0)',
663 \"1\": `(text-scale-set 0)'
665 The body can be accessed via `hydra-zoom/body'.
667 Call the head: `(text-scale-set 0)'."
670 (let ((hydra--ignore t))
671 (hydra-keyboard-quit))
677 (text-scale-set 0))))
680 (unless hydra-lv (sit-for 0.8))))
681 (when hydra-is-helpful
684 (eval hydra-zoom/hint))
686 (eval hydra-zoom/hint))))
687 (hydra-set-transient-map
690 (hydra-keyboard-quit)
693 (defun hydra-zoom/lambda-0-and-exit nil
694 "Create a hydra with no body and the heads:
696 \"r\": `(text-scale-set 0)',
697 \"0\": `(text-scale-set 0)',
698 \"1\": `(text-scale-set 0)'
700 The body can be accessed via `hydra-zoom/body'.
702 Call the head: `(text-scale-set 0)'."
705 (hydra-keyboard-quit)
710 (text-scale-set 0)))))
712 (defvar hydra-zoom/hint nil
713 "Dynamic hint for hydra-zoom.")
716 #("zoom: [r 0]: reset."
717 7 8 (face hydra-face-red)
718 9 10 (face hydra-face-blue)))))
719 (defun hydra-zoom/body nil
720 "Create a hydra with no body and the heads:
722 \"r\": `(text-scale-set 0)',
723 \"0\": `(text-scale-set 0)',
724 \"1\": `(text-scale-set 0)'
726 The body can be accessed via `hydra-zoom/body'."
729 (let ((hydra--ignore nil))
730 (hydra-keyboard-quit))
731 (when hydra-is-helpful
734 (eval hydra-zoom/hint))
736 (eval hydra-zoom/hint))))
737 (hydra-set-transient-map
740 (hydra-keyboard-quit)
744 current-prefix-arg))))))
746 (ert-deftest hydra-zoom-duplicate-2 ()
750 '(defhydra hydra-zoom ()
752 ("r" (text-scale-set 0) "reset")
753 ("0" (text-scale-set 0) :bind nil :exit t)
754 ("1" (text-scale-set 0) nil :bind nil)))
757 (defvar hydra-zoom/keymap nil
758 "Keymap for hydra-zoom.")
761 (114 . hydra-zoom/lambda-r)
762 (kp-subtract . hydra--negative-argument)
763 (kp-9 . hydra--digit-argument)
764 (kp-8 . hydra--digit-argument)
765 (kp-7 . hydra--digit-argument)
766 (kp-6 . hydra--digit-argument)
767 (kp-5 . hydra--digit-argument)
768 (kp-4 . hydra--digit-argument)
769 (kp-3 . hydra--digit-argument)
770 (kp-2 . hydra--digit-argument)
771 (kp-1 . hydra--digit-argument)
772 (kp-0 . hydra--digit-argument)
773 (57 . hydra--digit-argument)
774 (56 . hydra--digit-argument)
775 (55 . hydra--digit-argument)
776 (54 . hydra--digit-argument)
777 (53 . hydra--digit-argument)
778 (52 . hydra--digit-argument)
779 (51 . hydra--digit-argument)
780 (50 . hydra--digit-argument)
781 (49 . hydra-zoom/lambda-r)
782 (48 . hydra-zoom/lambda-0-and-exit)
783 (45 . hydra--negative-argument)
784 (21 . hydra--universal-argument))))
786 (defvar hydra-zoom/heads nil
787 "Heads for hydra-zoom.")
803 (defun hydra-zoom/lambda-r nil
804 "Create a hydra with no body and the heads:
806 \"r\": `(text-scale-set 0)',
807 \"0\": `(text-scale-set 0)',
808 \"1\": `(text-scale-set 0)'
810 The body can be accessed via `hydra-zoom/body'.
812 Call the head: `(text-scale-set 0)'."
815 (let ((hydra--ignore t))
816 (hydra-keyboard-quit))
822 (text-scale-set 0))))
825 (unless hydra-lv (sit-for 0.8))))
826 (when hydra-is-helpful
829 (eval hydra-zoom/hint))
831 (eval hydra-zoom/hint))))
832 (hydra-set-transient-map
835 (hydra-keyboard-quit)
838 (defun hydra-zoom/lambda-0-and-exit nil
839 "Create a hydra with no body and the heads:
841 \"r\": `(text-scale-set 0)',
842 \"0\": `(text-scale-set 0)',
843 \"1\": `(text-scale-set 0)'
845 The body can be accessed via `hydra-zoom/body'.
847 Call the head: `(text-scale-set 0)'."
850 (hydra-keyboard-quit)
855 (text-scale-set 0)))))
857 (defvar hydra-zoom/hint nil
858 "Dynamic hint for hydra-zoom.")
861 #("zoom: [r 0]: reset."
862 7 8 (face hydra-face-red)
863 9 10 (face hydra-face-blue)))))
864 (defun hydra-zoom/body nil
865 "Create a hydra with no body and the heads:
867 \"r\": `(text-scale-set 0)',
868 \"0\": `(text-scale-set 0)',
869 \"1\": `(text-scale-set 0)'
871 The body can be accessed via `hydra-zoom/body'."
874 (let ((hydra--ignore nil))
875 (hydra-keyboard-quit))
876 (when hydra-is-helpful
879 (eval hydra-zoom/hint))
881 (eval hydra-zoom/hint))))
882 (hydra-set-transient-map
885 (hydra-keyboard-quit)
889 current-prefix-arg))))))
891 (ert-deftest defhydradio ()
894 '(defhydradio hydra-test ()
895 (num "Num" [0 1 2 3 4 5 6 7 8 9 10])
896 (str "Str" ["foo" "bar" "baz"])))
898 (defvar hydra-test/num 0
900 (put 'hydra-test/num 'range [0 1 2 3 4 5 6 7 8 9 10])
901 (defun hydra-test/num ()
902 (hydra--cycle-radio 'hydra-test/num))
903 (defvar hydra-test/str "foo"
905 (put 'hydra-test/str 'range ["foo" "bar" "baz"])
906 (defun hydra-test/str ()
907 (hydra--cycle-radio 'hydra-test/str))
908 (defvar hydra-test/names '(hydra-test/num hydra-test/str))))))
910 (ert-deftest hydra-blue-compat ()
914 '(defhydra hydra-toggle (:color blue)
916 ("t" toggle-truncate-lines "truncate")
917 ("f" auto-fill-mode "fill")
918 ("a" abbrev-mode "abbrev")
921 '(defhydra hydra-toggle (:exit t)
923 ("t" toggle-truncate-lines "truncate")
924 ("f" auto-fill-mode "fill")
925 ("a" abbrev-mode "abbrev")
926 ("q" nil "cancel"))))))
928 (ert-deftest hydra-amaranth-compat ()
934 (set-cursor-color "#e52b50")
936 (set-cursor-color "#ffffff")
945 (set-cursor-color "#e52b50")
947 (set-cursor-color "#ffffff")
952 ("q" nil "quit"))))))
954 (ert-deftest hydra-pink-compat ()
958 '(defhydra hydra-zoom (global-map "<f2>"
961 ("g" text-scale-increase "in")
962 ("l" text-scale-decrease "out")
965 '(defhydra hydra-zoom (global-map "<f2>"
968 ("g" text-scale-increase "in")
969 ("l" text-scale-decrease "out")
970 ("q" nil "quit"))))))
972 (ert-deftest hydra-teal-compat ()
976 '(defhydra hydra-zoom (global-map "<f2>"
979 ("g" text-scale-increase "in")
980 ("l" text-scale-decrease "out")
983 '(defhydra hydra-zoom (global-map "<f2>"
987 ("g" text-scale-increase "in")
988 ("l" text-scale-decrease "out")
989 ("q" nil "quit"))))))
991 (ert-deftest hydra-format-1 ()
993 (let ((hydra-fontify-head-function
994 'hydra-fontify-head-greyscale))
999 _a_ abbrev-mode: %`abbrev-mode
1000 _d_ debug-on-error: %`debug-on-error
1001 _f_ auto-fill-mode: %`auto-fill-function
1002 " '(("a" abbrev-mode nil)
1003 ("d" toggle-debug-on-error nil)
1004 ("f" auto-fill-mode nil)
1005 ("g" golden-ratio-mode nil)
1006 ("t" toggle-truncate-lines nil)
1007 ("w" whitespace-mode nil)
1009 '(concat (format "%s abbrev-mode: %S
1010 %s debug-on-error: %S
1011 %s auto-fill-mode: %S
1012 " "{a}" abbrev-mode "{d}" debug-on-error "{f}" auto-fill-function) "[{q}]: quit"))))
1014 (ert-deftest hydra-format-2 ()
1016 (let ((hydra-fontify-head-function
1017 'hydra-fontify-head-greyscale))
1022 '(("a" (quote t) "" :cmd-name bar/lambda-a :exit nil)
1023 ("q" nil "" :cmd-name bar/nil :exit t))))
1024 '(concat (format " bar %s\n" foo) "{a}, [q]"))))
1026 (ert-deftest hydra-format-3 ()
1028 (let ((hydra-fontify-head-function
1029 'hydra-fontify-head-greyscale))
1033 "\n_<SPC>_ ^^ace jump\n"
1034 '(("<SPC>" ace-jump-char-mode nil :cmd-name bar/ace-jump-char-mode))))
1035 '(concat (format "%s ace jump\n" "{<SPC>}") ""))))
1037 (ert-deftest hydra-format-4 ()
1039 (equal (hydra--format
1041 '(nil nil :hint nil)
1043 '(("j" nil) ("k" nil)))
1044 '(concat (format "%s,%s"
1045 #("j" 0 1 (face hydra-face-blue))
1046 #("k" 0 1 (face hydra-face-blue))) ""))))
1048 (ert-deftest hydra-format-with-sexp-1 ()
1050 (let ((hydra-fontify-head-function
1051 'hydra-fontify-head-greyscale))
1054 "\n_n_ narrow-or-widen-dwim %(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1055 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1056 '(concat (format "%s narrow-or-widen-dwim %Sasdf\n"
1059 (message "checking")
1060 (buffer-narrowed-p)))
1063 (ert-deftest hydra-format-with-sexp-2 ()
1065 (let ((hydra-fontify-head-function
1066 'hydra-fontify-head-greyscale))
1069 "\n_n_ narrow-or-widen-dwim %s(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1070 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1071 '(concat (format "%s narrow-or-widen-dwim %sasdf\n"
1074 (message "checking")
1075 (buffer-narrowed-p)))
1078 (ert-deftest hydra-compat-colors-2 ()
1082 '(defhydra hydra-test (:color amaranth)
1084 ("b" fun-b :color blue)
1085 ("c" fun-c :color blue)
1086 ("d" fun-d :color blue)
1087 ("e" fun-e :color blue)
1088 ("f" fun-f :color blue)))
1090 '(defhydra hydra-test (:color teal)
1091 ("a" fun-a :color red)
1098 (ert-deftest hydra-compat-colors-3 ()
1102 '(defhydra hydra-test ()
1104 ("b" fun-b :color blue)
1105 ("c" fun-c :color blue)
1106 ("d" fun-d :color blue)
1107 ("e" fun-e :color blue)
1108 ("f" fun-f :color blue)))
1110 '(defhydra hydra-test (:color blue)
1111 ("a" fun-a :color red)
1118 (ert-deftest hydra-compat-colors-4 ()
1122 '(defhydra hydra-test ()
1128 ("f" fun-f :exit t)))
1130 '(defhydra hydra-test (:exit t)
1131 ("a" fun-a :exit nil)
1138 (ert-deftest hydra--pad ()
1139 (should (equal (hydra--pad '(a b c) 3)
1141 (should (equal (hydra--pad '(a) 3)
1144 (ert-deftest hydra--matrix ()
1145 (should (equal (hydra--matrix '(a b c) 2 2)
1147 (should (equal (hydra--matrix '(a b c d e f g h i) 4 3)
1148 '((a b c d) (e f g h) (i nil nil nil)))))
1150 (ert-deftest hydra--cell ()
1151 (should (equal (hydra--cell "% -75s %%`%s" '(hydra-lv hydra-verbose))
1152 "When non-nil, `lv-message' (not `message') will be used to display hints. %`hydra-lv^^^^^
1153 When non-nil, hydra will issue some non essential style warnings. %`hydra-verbose")))
1155 (ert-deftest hydra--vconcat ()
1156 (should (equal (hydra--vconcat '("abc\ndef" "012\n34" "def\nabc"))
1157 "abc012def\ndef34abc")))
1159 (defhydradio hydra-tng ()
1160 (picard "_p_ Captain Jean Luc Picard:")
1161 (riker "_r_ Commander William Riker:")
1162 (data "_d_ Lieutenant Commander Data:")
1164 (la-forge "_f_ Geordi La Forge:")
1165 (troi "_t_ Deanna Troi:")
1166 (dr-crusher "_c_ Doctor Beverly Crusher:")
1167 (phaser "_h_ Set phasers to " [stun kill]))
1169 (ert-deftest hydra--table ()
1170 (let ((hydra-cell-format "% -30s %% -8`%s"))
1171 (should (equal (hydra--table hydra-tng/names 5 2)
1173 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard^^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1174 _r_ Commander William Riker: % -8`hydra-tng/riker^^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1175 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^
1176 _w_ Worf: % -8`hydra-tng/worf^^^^
1177 _f_ Geordi La Forge: % -8`hydra-tng/la-forge" 1)))
1178 (should (equal (hydra--table hydra-tng/names 4 3)
1180 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard _f_ Geordi La Forge: % -8`hydra-tng/la-forge^^
1181 _r_ Commander William Riker: % -8`hydra-tng/riker^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1182 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1183 _w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^" 1)))))
1185 (ert-deftest hydra--make-funcall ()
1186 (should (equal (let ((body-pre 'foo))
1187 (hydra--make-funcall body-pre)
1189 '(funcall (function foo)))))
1191 (defhydra hydra-simple-1 (global-map "C-c")
1196 (defhydra hydra-simple-2 (global-map "C-c" :color amaranth)
1197 ("c" self-insert-command)
1198 ("d" self-insert-command)
1201 (defhydra hydra-simple-3 (global-map "C-c")
1206 (defmacro hydra-with (in &rest body)
1207 `(let ((temp-buffer (generate-new-buffer " *temp*")))
1208 (save-window-excursion
1211 (switch-to-buffer temp-buffer)
1212 (transient-mark-mode 1)
1214 (goto-char (point-min))
1215 (when (search-forward "~" nil t)
1216 (backward-delete-char 1)
1218 (goto-char (point-max))
1219 (search-backward "|")
1221 (setq current-prefix-arg)
1224 (when (region-active-p)
1225 (exchange-point-and-mark)
1227 (buffer-substring-no-properties
1230 (and (buffer-name temp-buffer)
1231 (kill-buffer temp-buffer))))))
1233 (ert-deftest hydra-integration-1 ()
1234 (should (string= (hydra-with "|"
1236 (kbd "C-c aabbaaqaabbaa")))
1238 (should (string= (hydra-with "|"
1241 (kbd "C-c aabb C-g"))
1243 (execute-kbd-macro "aaqaabbaa"))
1246 (ert-deftest hydra-integration-2 ()
1247 (should (string= (hydra-with "|"
1249 (kbd "C-c c 1 c 2 d 4 c q")))
1251 (should (string= (hydra-with "|"
1253 (kbd "C-c c 1 c C-u d C-u 10 c q")))
1254 "ccddddcccccccccc|")))
1256 (ert-deftest hydra-integration-3 ()
1257 (should (string= (hydra-with "foo\nbar|"
1259 (kbd "C-c g 1 RET q")))
1262 (provide 'hydra-test)
1264 ;;; hydra-test.el ends here