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/>.
29 (message "Emacs version: %s" emacs-version)
31 (ert-deftest hydra-red-error ()
35 '(defhydra hydra-error (global-map "M-g")
37 ("h" first-error "first")
38 ("j" next-error "next")
39 ("k" previous-error "prev")
40 ("SPC" hydra-repeat "rep" :bind nil)))
43 (defvar hydra-error/keymap nil
44 "Keymap for hydra-error.")
48 (107 . hydra-error/previous-error)
49 (106 . hydra-error/next-error)
50 (104 . hydra-error/first-error)
51 (kp-subtract . hydra--negative-argument)
52 (kp-9 . hydra--digit-argument)
53 (kp-8 . hydra--digit-argument)
54 (kp-7 . hydra--digit-argument)
55 (kp-6 . hydra--digit-argument)
56 (kp-5 . hydra--digit-argument)
57 (kp-4 . hydra--digit-argument)
58 (kp-3 . hydra--digit-argument)
59 (kp-2 . hydra--digit-argument)
60 (kp-1 . hydra--digit-argument)
61 (kp-0 . hydra--digit-argument)
62 (57 . hydra--digit-argument)
63 (56 . hydra--digit-argument)
64 (55 . hydra--digit-argument)
65 (54 . hydra--digit-argument)
66 (53 . hydra--digit-argument)
67 (52 . hydra--digit-argument)
68 (51 . hydra--digit-argument)
69 (50 . hydra--digit-argument)
70 (49 . hydra--digit-argument)
71 (48 . hydra--digit-argument)
72 (45 . hydra--negative-argument)
73 (21 . hydra--universal-argument))))
75 (defvar hydra-error/heads nil
76 "Heads for hydra-error.")
96 (defvar hydra-error/hint nil
97 "Dynamic hint for hydra-error.")
100 #("error: [h]: first, [j]: next, [k]: prev, [SPC]: rep."
101 8 9 (face hydra-face-red)
102 20 21 (face hydra-face-red)
103 31 32 (face hydra-face-red)
104 42 45 (face hydra-face-red)))))
105 (defun hydra-error/first-error nil
106 "Create a hydra with a \"M-g\" body and the heads:
108 \"h\": `first-error',
110 \"k\": `previous-error',
111 \"SPC\": `hydra-repeat'
113 The body can be accessed via `hydra-error/body'.
115 Call the head: `first-error'."
118 (let ((hydra--ignore t))
119 (hydra-keyboard-quit))
125 (function first-error)))
128 (unless hydra-lv (sit-for 0.8))))
129 (when hydra-is-helpful
132 (eval hydra-error/hint))
134 (eval hydra-error/hint))))
135 (hydra-set-transient-map
138 (hydra-keyboard-quit)
141 (defun hydra-error/next-error nil
142 "Create a hydra with a \"M-g\" body and the heads:
144 \"h\": `first-error',
146 \"k\": `previous-error',
147 \"SPC\": `hydra-repeat'
149 The body can be accessed via `hydra-error/body'.
151 Call the head: `next-error'."
154 (let ((hydra--ignore t))
155 (hydra-keyboard-quit))
161 (function next-error)))
164 (unless hydra-lv (sit-for 0.8))))
165 (when hydra-is-helpful
168 (eval hydra-error/hint))
170 (eval hydra-error/hint))))
171 (hydra-set-transient-map
174 (hydra-keyboard-quit)
177 (defun hydra-error/previous-error nil
178 "Create a hydra with a \"M-g\" body and the heads:
180 \"h\": `first-error',
182 \"k\": `previous-error',
183 \"SPC\": `hydra-repeat'
185 The body can be accessed via `hydra-error/body'.
187 Call the head: `previous-error'."
190 (let ((hydra--ignore t))
191 (hydra-keyboard-quit))
195 (quote previous-error))
197 (function previous-error)))
200 (unless hydra-lv (sit-for 0.8))))
201 (when hydra-is-helpful
204 (eval hydra-error/hint))
206 (eval hydra-error/hint))))
207 (hydra-set-transient-map
210 (hydra-keyboard-quit)
217 (define-key global-map (kbd "M-g")
219 (define-key global-map [134217831 104]
221 hydra-error/first-error))
222 (define-key global-map [134217831 106]
224 hydra-error/next-error))
225 (define-key global-map [134217831 107]
227 hydra-error/previous-error))
228 (defun hydra-error/body nil
229 "Create a hydra with a \"M-g\" body and the heads:
231 \"h\": `first-error',
233 \"k\": `previous-error',
234 \"SPC\": `hydra-repeat'
236 The body can be accessed via `hydra-error/body'."
239 (let ((hydra--ignore nil))
240 (hydra-keyboard-quit))
241 (when hydra-is-helpful
244 (eval hydra-error/hint))
246 (eval hydra-error/hint))))
247 (hydra-set-transient-map
250 (hydra-keyboard-quit)
254 current-prefix-arg))))))
256 (ert-deftest hydra-blue-toggle ()
260 '(defhydra hydra-toggle (:color blue)
262 ("t" toggle-truncate-lines "truncate")
263 ("f" auto-fill-mode "fill")
264 ("a" abbrev-mode "abbrev")
268 (defvar hydra-toggle/keymap nil
269 "Keymap for hydra-toggle.")
272 (113 . hydra-toggle/nil)
273 (97 . hydra-toggle/abbrev-mode-and-exit)
274 (102 . hydra-toggle/auto-fill-mode-and-exit)
275 (116 . hydra-toggle/toggle-truncate-lines-and-exit)
276 (kp-subtract . hydra--negative-argument)
277 (kp-9 . hydra--digit-argument)
278 (kp-8 . hydra--digit-argument)
279 (kp-7 . hydra--digit-argument)
280 (kp-6 . hydra--digit-argument)
281 (kp-5 . hydra--digit-argument)
282 (kp-4 . hydra--digit-argument)
283 (kp-3 . hydra--digit-argument)
284 (kp-2 . hydra--digit-argument)
285 (kp-1 . hydra--digit-argument)
286 (kp-0 . hydra--digit-argument)
287 (57 . hydra--digit-argument)
288 (56 . hydra--digit-argument)
289 (55 . hydra--digit-argument)
290 (54 . hydra--digit-argument)
291 (53 . hydra--digit-argument)
292 (52 . hydra--digit-argument)
293 (51 . hydra--digit-argument)
294 (50 . hydra--digit-argument)
295 (49 . hydra--digit-argument)
296 (48 . hydra--digit-argument)
297 (45 . hydra--negative-argument)
298 (21 . hydra--universal-argument))))
300 (defvar hydra-toggle/heads nil
301 "Heads for hydra-toggle.")
304 toggle-truncate-lines
315 ("q" nil "cancel" :exit t))))
317 (defvar hydra-toggle/hint nil
318 "Dynamic hint for hydra-toggle.")
321 #("toggle: [t]: truncate, [f]: fill, [a]: abbrev, [q]: cancel."
322 9 10 (face hydra-face-blue)
323 24 25 (face hydra-face-blue)
324 35 36 (face hydra-face-blue)
325 48 49 (face hydra-face-blue)))))
326 (defun hydra-toggle/toggle-truncate-lines-and-exit nil
327 "Create a hydra with no body and the heads:
329 \"t\": `toggle-truncate-lines',
330 \"f\": `auto-fill-mode',
331 \"a\": `abbrev-mode',
334 The body can be accessed via `hydra-toggle/body'.
336 Call the head: `toggle-truncate-lines'."
339 (hydra-keyboard-quit)
342 (quote toggle-truncate-lines))
345 toggle-truncate-lines))))
346 (defun hydra-toggle/auto-fill-mode-and-exit nil
347 "Create a hydra with no body and the heads:
349 \"t\": `toggle-truncate-lines',
350 \"f\": `auto-fill-mode',
351 \"a\": `abbrev-mode',
354 The body can be accessed via `hydra-toggle/body'.
356 Call the head: `auto-fill-mode'."
359 (hydra-keyboard-quit)
362 (quote auto-fill-mode))
364 (function auto-fill-mode))))
365 (defun hydra-toggle/abbrev-mode-and-exit nil
366 "Create a hydra with no body and the heads:
368 \"t\": `toggle-truncate-lines',
369 \"f\": `auto-fill-mode',
370 \"a\": `abbrev-mode',
373 The body can be accessed via `hydra-toggle/body'.
375 Call the head: `abbrev-mode'."
378 (hydra-keyboard-quit)
383 (function abbrev-mode))))
384 (defun hydra-toggle/nil nil
385 "Create a hydra with no body and the heads:
387 \"t\": `toggle-truncate-lines',
388 \"f\": `auto-fill-mode',
389 \"a\": `abbrev-mode',
392 The body can be accessed via `hydra-toggle/body'.
394 Call the head: `nil'."
397 (hydra-keyboard-quit))
398 (defun hydra-toggle/body nil
399 "Create a hydra with no body and the heads:
401 \"t\": `toggle-truncate-lines',
402 \"f\": `auto-fill-mode',
403 \"a\": `abbrev-mode',
406 The body can be accessed via `hydra-toggle/body'."
409 (let ((hydra--ignore nil))
410 (hydra-keyboard-quit))
411 (when hydra-is-helpful
414 (eval hydra-toggle/hint))
416 (eval hydra-toggle/hint))))
417 (hydra-set-transient-map
420 (hydra-keyboard-quit)
424 current-prefix-arg))))))
426 (ert-deftest hydra-amaranth-vi ()
432 (set-cursor-color "#e52b50")
434 (set-cursor-color "#ffffff")
442 (defvar hydra-vi/keymap nil
443 "Keymap for hydra-vi.")
447 (107 . hydra-vi/previous-line)
448 (106 . hydra-vi/next-line)
449 (kp-subtract . hydra--negative-argument)
450 (kp-9 . hydra--digit-argument)
451 (kp-8 . hydra--digit-argument)
452 (kp-7 . hydra--digit-argument)
453 (kp-6 . hydra--digit-argument)
454 (kp-5 . hydra--digit-argument)
455 (kp-4 . hydra--digit-argument)
456 (kp-3 . hydra--digit-argument)
457 (kp-2 . hydra--digit-argument)
458 (kp-1 . hydra--digit-argument)
459 (kp-0 . hydra--digit-argument)
460 (57 . hydra--digit-argument)
461 (56 . hydra--digit-argument)
462 (55 . hydra--digit-argument)
463 (54 . hydra--digit-argument)
464 (53 . hydra--digit-argument)
465 (52 . hydra--digit-argument)
466 (51 . hydra--digit-argument)
467 (50 . hydra--digit-argument)
468 (49 . hydra--digit-argument)
469 (48 . hydra--digit-argument)
470 (45 . hydra--negative-argument)
471 (21 . hydra--universal-argument))))
473 (defvar hydra-vi/heads nil
474 "Heads for hydra-vi.")
476 (("j" next-line "" :exit nil)
481 ("q" nil "quit" :exit t))))
483 (defvar hydra-vi/hint nil
484 "Dynamic hint for hydra-vi.")
487 #("vi: j, k, [q]: quit."
488 4 5 (face hydra-face-amaranth)
489 7 8 (face hydra-face-amaranth)
490 11 12 (face hydra-face-teal)))))
491 (defun hydra-vi/next-line nil
492 "Create a hydra with no body and the heads:
495 \"k\": `previous-line',
498 The body can be accessed via `hydra-vi/body'.
500 Call the head: `next-line'."
503 (set-cursor-color "#e52b50")
504 (let ((hydra--ignore t))
505 (hydra-keyboard-quit))
511 (function next-line)))
514 (unless hydra-lv (sit-for 0.8))))
515 (when hydra-is-helpful
518 (eval hydra-vi/hint))
519 (message (eval hydra-vi/hint))))
520 (hydra-set-transient-map
523 (hydra-keyboard-quit)
524 (set-cursor-color "#ffffff"))
526 (defun hydra-vi/previous-line nil
527 "Create a hydra with no body and the heads:
530 \"k\": `previous-line',
533 The body can be accessed via `hydra-vi/body'.
535 Call the head: `previous-line'."
538 (set-cursor-color "#e52b50")
539 (let ((hydra--ignore t))
540 (hydra-keyboard-quit))
544 (quote previous-line))
546 (function previous-line)))
549 (unless hydra-lv (sit-for 0.8))))
550 (when hydra-is-helpful
553 (eval hydra-vi/hint))
554 (message (eval hydra-vi/hint))))
555 (hydra-set-transient-map
558 (hydra-keyboard-quit)
559 (set-cursor-color "#ffffff"))
561 (defun hydra-vi/nil nil
562 "Create a hydra with no body and the heads:
565 \"k\": `previous-line',
568 The body can be accessed via `hydra-vi/body'.
570 Call the head: `nil'."
573 (set-cursor-color "#e52b50")
574 (hydra-keyboard-quit))
575 (defun hydra-vi/body nil
576 "Create a hydra with no body and the heads:
579 \"k\": `previous-line',
582 The body can be accessed via `hydra-vi/body'."
585 (set-cursor-color "#e52b50")
586 (let ((hydra--ignore nil))
587 (hydra-keyboard-quit))
588 (when hydra-is-helpful
591 (eval hydra-vi/hint))
592 (message (eval hydra-vi/hint))))
593 (hydra-set-transient-map
596 (hydra-keyboard-quit)
597 (set-cursor-color "#ffffff"))
600 current-prefix-arg))))))
602 (ert-deftest hydra-zoom-duplicate-1 ()
606 '(defhydra hydra-zoom ()
608 ("r" (text-scale-set 0) "reset")
609 ("0" (text-scale-set 0) :bind nil :exit t)
610 ("1" (text-scale-set 0) nil :bind nil :exit t)))
613 (defvar hydra-zoom/keymap nil
614 "Keymap for hydra-zoom.")
617 (114 . hydra-zoom/lambda-r)
618 (kp-subtract . hydra--negative-argument)
619 (kp-9 . hydra--digit-argument)
620 (kp-8 . hydra--digit-argument)
621 (kp-7 . hydra--digit-argument)
622 (kp-6 . hydra--digit-argument)
623 (kp-5 . hydra--digit-argument)
624 (kp-4 . hydra--digit-argument)
625 (kp-3 . hydra--digit-argument)
626 (kp-2 . hydra--digit-argument)
627 (kp-1 . hydra--digit-argument)
628 (kp-0 . hydra--digit-argument)
629 (57 . hydra--digit-argument)
630 (56 . hydra--digit-argument)
631 (55 . hydra--digit-argument)
632 (54 . hydra--digit-argument)
633 (53 . hydra--digit-argument)
634 (52 . hydra--digit-argument)
635 (51 . hydra--digit-argument)
636 (50 . hydra--digit-argument)
637 (49 . hydra-zoom/lambda-0-and-exit)
638 (48 . hydra-zoom/lambda-0-and-exit)
639 (45 . hydra--negative-argument)
640 (21 . hydra--universal-argument))))
642 (defvar hydra-zoom/heads nil
643 "Heads for hydra-zoom.")
660 (defvar hydra-zoom/hint nil
661 "Dynamic hint for hydra-zoom.")
664 #("zoom: [r 0]: reset."
665 7 8 (face hydra-face-red)
666 9 10 (face hydra-face-blue)))))
667 (defun hydra-zoom/lambda-r nil
668 "Create a hydra with no body and the heads:
670 \"r\": `(text-scale-set 0)',
671 \"0\": `(text-scale-set 0)',
672 \"1\": `(text-scale-set 0)'
674 The body can be accessed via `hydra-zoom/body'.
676 Call the head: `(text-scale-set 0)'."
679 (let ((hydra--ignore t))
680 (hydra-keyboard-quit))
686 (text-scale-set 0))))
689 (unless hydra-lv (sit-for 0.8))))
690 (when hydra-is-helpful
693 (eval hydra-zoom/hint))
695 (eval hydra-zoom/hint))))
696 (hydra-set-transient-map
699 (hydra-keyboard-quit)
702 (defun hydra-zoom/lambda-0-and-exit nil
703 "Create a hydra with no body and the heads:
705 \"r\": `(text-scale-set 0)',
706 \"0\": `(text-scale-set 0)',
707 \"1\": `(text-scale-set 0)'
709 The body can be accessed via `hydra-zoom/body'.
711 Call the head: `(text-scale-set 0)'."
714 (hydra-keyboard-quit)
719 (text-scale-set 0)))))
720 (defun hydra-zoom/body nil
721 "Create a hydra with no body and the heads:
723 \"r\": `(text-scale-set 0)',
724 \"0\": `(text-scale-set 0)',
725 \"1\": `(text-scale-set 0)'
727 The body can be accessed via `hydra-zoom/body'."
730 (let ((hydra--ignore nil))
731 (hydra-keyboard-quit))
732 (when hydra-is-helpful
735 (eval hydra-zoom/hint))
737 (eval hydra-zoom/hint))))
738 (hydra-set-transient-map
741 (hydra-keyboard-quit)
745 current-prefix-arg))))))
747 (ert-deftest hydra-zoom-duplicate-2 ()
751 '(defhydra hydra-zoom ()
753 ("r" (text-scale-set 0) "reset")
754 ("0" (text-scale-set 0) :bind nil :exit t)
755 ("1" (text-scale-set 0) nil :bind nil)))
758 (defvar hydra-zoom/keymap nil
759 "Keymap for hydra-zoom.")
762 (114 . hydra-zoom/lambda-r)
763 (kp-subtract . hydra--negative-argument)
764 (kp-9 . hydra--digit-argument)
765 (kp-8 . hydra--digit-argument)
766 (kp-7 . hydra--digit-argument)
767 (kp-6 . hydra--digit-argument)
768 (kp-5 . hydra--digit-argument)
769 (kp-4 . hydra--digit-argument)
770 (kp-3 . hydra--digit-argument)
771 (kp-2 . hydra--digit-argument)
772 (kp-1 . hydra--digit-argument)
773 (kp-0 . hydra--digit-argument)
774 (57 . hydra--digit-argument)
775 (56 . hydra--digit-argument)
776 (55 . hydra--digit-argument)
777 (54 . hydra--digit-argument)
778 (53 . hydra--digit-argument)
779 (52 . hydra--digit-argument)
780 (51 . hydra--digit-argument)
781 (50 . hydra--digit-argument)
782 (49 . hydra-zoom/lambda-r)
783 (48 . hydra-zoom/lambda-0-and-exit)
784 (45 . hydra--negative-argument)
785 (21 . hydra--universal-argument))))
787 (defvar hydra-zoom/heads nil
788 "Heads for hydra-zoom.")
805 (defvar hydra-zoom/hint nil
806 "Dynamic hint for hydra-zoom.")
809 #("zoom: [r 0]: reset."
810 7 8 (face hydra-face-red)
811 9 10 (face hydra-face-blue)))))
812 (defun hydra-zoom/lambda-r nil
813 "Create a hydra with no body and the heads:
815 \"r\": `(text-scale-set 0)',
816 \"0\": `(text-scale-set 0)',
817 \"1\": `(text-scale-set 0)'
819 The body can be accessed via `hydra-zoom/body'.
821 Call the head: `(text-scale-set 0)'."
824 (let ((hydra--ignore t))
825 (hydra-keyboard-quit))
831 (text-scale-set 0))))
834 (unless hydra-lv (sit-for 0.8))))
835 (when hydra-is-helpful
838 (eval hydra-zoom/hint))
840 (eval hydra-zoom/hint))))
841 (hydra-set-transient-map
844 (hydra-keyboard-quit)
847 (defun hydra-zoom/lambda-0-and-exit nil
848 "Create a hydra with no body and the heads:
850 \"r\": `(text-scale-set 0)',
851 \"0\": `(text-scale-set 0)',
852 \"1\": `(text-scale-set 0)'
854 The body can be accessed via `hydra-zoom/body'.
856 Call the head: `(text-scale-set 0)'."
859 (hydra-keyboard-quit)
864 (text-scale-set 0)))))
865 (defun hydra-zoom/body nil
866 "Create a hydra with no body and the heads:
868 \"r\": `(text-scale-set 0)',
869 \"0\": `(text-scale-set 0)',
870 \"1\": `(text-scale-set 0)'
872 The body can be accessed via `hydra-zoom/body'."
875 (let ((hydra--ignore nil))
876 (hydra-keyboard-quit))
877 (when hydra-is-helpful
880 (eval hydra-zoom/hint))
882 (eval hydra-zoom/hint))))
883 (hydra-set-transient-map
886 (hydra-keyboard-quit)
890 current-prefix-arg))))))
892 (ert-deftest defhydradio ()
895 '(defhydradio hydra-test ()
896 (num "Num" [0 1 2 3 4 5 6 7 8 9 10])
897 (str "Str" ["foo" "bar" "baz"])))
899 (defvar hydra-test/num 0
901 (put 'hydra-test/num 'range [0 1 2 3 4 5 6 7 8 9 10])
902 (defun hydra-test/num ()
903 (hydra--cycle-radio 'hydra-test/num))
904 (defvar hydra-test/str "foo"
906 (put 'hydra-test/str 'range ["foo" "bar" "baz"])
907 (defun hydra-test/str ()
908 (hydra--cycle-radio 'hydra-test/str))
909 (defvar hydra-test/names '(hydra-test/num hydra-test/str))))))
911 (ert-deftest hydra-blue-compat ()
915 '(defhydra hydra-toggle (:color blue)
917 ("t" toggle-truncate-lines "truncate")
918 ("f" auto-fill-mode "fill")
919 ("a" abbrev-mode "abbrev")
922 '(defhydra hydra-toggle (:exit t)
924 ("t" toggle-truncate-lines "truncate")
925 ("f" auto-fill-mode "fill")
926 ("a" abbrev-mode "abbrev")
927 ("q" nil "cancel"))))))
929 (ert-deftest hydra-amaranth-compat ()
935 (set-cursor-color "#e52b50")
937 (set-cursor-color "#ffffff")
946 (set-cursor-color "#e52b50")
948 (set-cursor-color "#ffffff")
953 ("q" nil "quit"))))))
955 (ert-deftest hydra-pink-compat ()
959 '(defhydra hydra-zoom (global-map "<f2>"
962 ("g" text-scale-increase "in")
963 ("l" text-scale-decrease "out")
966 '(defhydra hydra-zoom (global-map "<f2>"
969 ("g" text-scale-increase "in")
970 ("l" text-scale-decrease "out")
971 ("q" nil "quit"))))))
973 (ert-deftest hydra-teal-compat ()
977 '(defhydra hydra-zoom (global-map "<f2>"
980 ("g" text-scale-increase "in")
981 ("l" text-scale-decrease "out")
984 '(defhydra hydra-zoom (global-map "<f2>"
988 ("g" text-scale-increase "in")
989 ("l" text-scale-decrease "out")
990 ("q" nil "quit"))))))
992 (ert-deftest hydra-format-1 ()
994 (let ((hydra-fontify-head-function
995 'hydra-fontify-head-greyscale))
1000 _a_ abbrev-mode: %`abbrev-mode
1001 _d_ debug-on-error: %`debug-on-error
1002 _f_ auto-fill-mode: %`auto-fill-function
1003 " '(("a" abbrev-mode nil)
1004 ("d" toggle-debug-on-error nil)
1005 ("f" auto-fill-mode nil)
1006 ("g" golden-ratio-mode nil)
1007 ("t" toggle-truncate-lines nil)
1008 ("w" whitespace-mode nil)
1010 '(concat (format "%s abbrev-mode: %S
1011 %s debug-on-error: %S
1012 %s auto-fill-mode: %S
1013 " "{a}" abbrev-mode "{d}" debug-on-error "{f}" auto-fill-function) "[{q}]: quit"))))
1015 (ert-deftest hydra-format-2 ()
1017 (let ((hydra-fontify-head-function
1018 'hydra-fontify-head-greyscale))
1023 '(("a" (quote t) "" :cmd-name bar/lambda-a :exit nil)
1024 ("q" nil "" :cmd-name bar/nil :exit t))))
1025 '(concat (format " bar %s\n" foo) "{a}, [q]"))))
1027 (ert-deftest hydra-format-3 ()
1029 (let ((hydra-fontify-head-function
1030 'hydra-fontify-head-greyscale))
1034 "\n_<SPC>_ ^^ace jump\n"
1035 '(("<SPC>" ace-jump-char-mode nil :cmd-name bar/ace-jump-char-mode))))
1036 '(concat (format "%s ace jump\n" "{<SPC>}") ""))))
1038 (ert-deftest hydra-format-4 ()
1040 (equal (hydra--format
1042 '(nil nil :hint nil)
1044 '(("j" nil nil :exit t) ("k" nil nil :exit t)))
1045 '(concat (format "%s,%s"
1046 #("j" 0 1 (face hydra-face-blue))
1047 #("k" 0 1 (face hydra-face-blue))) ""))))
1049 (ert-deftest hydra-format-5 ()
1051 (equal (hydra--format
1052 nil nil "\n_-_: mark _u_: unmark\n"
1053 '(("-" Buffer-menu-mark)
1054 ("u" Buffer-menu-unmark)))
1057 "%s: mark %s: unmark\n"
1058 #("-" 0 1 (face hydra-face-red))
1059 #("u" 0 1 (face hydra-face-red)))
1062 (ert-deftest hydra-format-with-sexp-1 ()
1064 (let ((hydra-fontify-head-function
1065 'hydra-fontify-head-greyscale))
1068 "\n_n_ narrow-or-widen-dwim %(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1069 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1070 '(concat (format "%s narrow-or-widen-dwim %Sasdf\n"
1073 (message "checking")
1074 (buffer-narrowed-p)))
1077 (ert-deftest hydra-format-with-sexp-2 ()
1079 (let ((hydra-fontify-head-function
1080 'hydra-fontify-head-greyscale))
1083 "\n_n_ narrow-or-widen-dwim %s(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1084 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1085 '(concat (format "%s narrow-or-widen-dwim %sasdf\n"
1088 (message "checking")
1089 (buffer-narrowed-p)))
1092 (ert-deftest hydra-compat-colors-2 ()
1096 '(defhydra hydra-test (:color amaranth)
1098 ("b" fun-b :color blue)
1099 ("c" fun-c :color blue)
1100 ("d" fun-d :color blue)
1101 ("e" fun-e :color blue)
1102 ("f" fun-f :color blue)))
1104 '(defhydra hydra-test (:color teal)
1105 ("a" fun-a :color red)
1112 (ert-deftest hydra-compat-colors-3 ()
1116 '(defhydra hydra-test ()
1118 ("b" fun-b :color blue)
1119 ("c" fun-c :color blue)
1120 ("d" fun-d :color blue)
1121 ("e" fun-e :color blue)
1122 ("f" fun-f :color blue)))
1124 '(defhydra hydra-test (:color blue)
1125 ("a" fun-a :color red)
1132 (ert-deftest hydra-compat-colors-4 ()
1136 '(defhydra hydra-test ()
1142 ("f" fun-f :exit t)))
1144 '(defhydra hydra-test (:exit t)
1145 ("a" fun-a :exit nil)
1152 (ert-deftest hydra--pad ()
1153 (should (equal (hydra--pad '(a b c) 3)
1155 (should (equal (hydra--pad '(a) 3)
1158 (ert-deftest hydra--matrix ()
1159 (should (equal (hydra--matrix '(a b c) 2 2)
1161 (should (equal (hydra--matrix '(a b c d e f g h i) 4 3)
1162 '((a b c d) (e f g h) (i nil nil nil)))))
1164 (ert-deftest hydra--cell ()
1165 (should (equal (hydra--cell "% -75s %%`%s" '(hydra-lv hydra-verbose))
1166 "When non-nil, `lv-message' (not `message') will be used to display hints. %`hydra-lv^^^^^
1167 When non-nil, hydra will issue some non essential style warnings. %`hydra-verbose")))
1169 (ert-deftest hydra--vconcat ()
1170 (should (equal (hydra--vconcat '("abc\ndef" "012\n34" "def\nabc"))
1171 "abc012def\ndef34abc")))
1173 (defhydradio hydra-tng ()
1174 (picard "_p_ Captain Jean Luc Picard:")
1175 (riker "_r_ Commander William Riker:")
1176 (data "_d_ Lieutenant Commander Data:")
1178 (la-forge "_f_ Geordi La Forge:")
1179 (troi "_t_ Deanna Troi:")
1180 (dr-crusher "_c_ Doctor Beverly Crusher:")
1181 (phaser "_h_ Set phasers to " [stun kill]))
1183 (ert-deftest hydra--table ()
1184 (let ((hydra-cell-format "% -30s %% -8`%s"))
1185 (should (equal (hydra--table hydra-tng/names 5 2)
1187 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard^^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1188 _r_ Commander William Riker: % -8`hydra-tng/riker^^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1189 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^
1190 _w_ Worf: % -8`hydra-tng/worf^^^^
1191 _f_ Geordi La Forge: % -8`hydra-tng/la-forge" 1)))
1192 (should (equal (hydra--table hydra-tng/names 4 3)
1194 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard _f_ Geordi La Forge: % -8`hydra-tng/la-forge^^
1195 _r_ Commander William Riker: % -8`hydra-tng/riker^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1196 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1197 _w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^" 1)))))
1199 (ert-deftest hydra--make-funcall ()
1200 (should (equal (let ((body-pre 'foo))
1201 (hydra--make-funcall body-pre)
1203 '(funcall (function foo)))))
1205 (defhydra hydra-simple-1 (global-map "C-c")
1210 (defhydra hydra-simple-2 (global-map "C-c" :color amaranth)
1211 ("c" self-insert-command)
1212 ("d" self-insert-command)
1215 (defhydra hydra-simple-3 (global-map "C-c")
1220 (defmacro hydra-with (in &rest body)
1221 `(let ((temp-buffer (generate-new-buffer " *temp*")))
1222 (save-window-excursion
1225 (switch-to-buffer temp-buffer)
1226 (transient-mark-mode 1)
1228 (goto-char (point-min))
1229 (when (search-forward "~" nil t)
1230 (backward-delete-char 1)
1232 (goto-char (point-max))
1233 (search-backward "|")
1235 (setq current-prefix-arg)
1238 (when (region-active-p)
1239 (exchange-point-and-mark)
1241 (buffer-substring-no-properties
1244 (and (buffer-name temp-buffer)
1245 (kill-buffer temp-buffer))))))
1247 (ert-deftest hydra-integration-1 ()
1248 (should (string= (hydra-with "|"
1250 (kbd "C-c aabbaaqaabbaa")))
1252 (should (string= (hydra-with "|"
1255 (kbd "C-c aabb C-g"))
1257 (execute-kbd-macro "aaqaabbaa"))
1260 (ert-deftest hydra-integration-2 ()
1261 (should (string= (hydra-with "|"
1263 (kbd "C-c c 1 c 2 d 4 c q")))
1265 (should (string= (hydra-with "|"
1267 (kbd "C-c c 1 c C-u d C-u 10 c q")))
1268 "ccddddcccccccccc|")))
1270 (ert-deftest hydra-integration-3 ()
1271 (should (string= (hydra-with "foo\nbar|"
1273 (kbd "C-c g 1 RET q")))
1276 (provide 'hydra-test)
1278 ;;; hydra-test.el ends here