X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/3f035ad4f8ef0bf6b8e60a819ec97d6f7f6ea5b5..23a624ca1d40fa9cefd7229ac6152b79278a6517:/packages/hydra/hydra-test.el diff --git a/packages/hydra/hydra-test.el b/packages/hydra/hydra-test.el index b908ac0c8..f876e361b 100644 --- a/packages/hydra/hydra-test.el +++ b/packages/hydra/hydra-test.el @@ -25,6 +25,7 @@ ;;; Code: (require 'ert) +(require 'hydra) (ert-deftest hydra-red-error () (should @@ -48,6 +49,7 @@ The body can be accessed via `hydra-error/body'. Call the head: `first-error'." (interactive) + (hydra-default-pre) (hydra-disable) (catch (quote hydra-disable) (condition-case err (prog1 t (call-interactively (function first-error))) @@ -100,6 +102,7 @@ The body can be accessed via `hydra-error/body'. Call the head: `next-error'." (interactive) + (hydra-default-pre) (hydra-disable) (catch (quote hydra-disable) (condition-case err (prog1 t (call-interactively (function next-error))) @@ -152,6 +155,7 @@ The body can be accessed via `hydra-error/body'. Call the head: `previous-error'." (interactive) + (hydra-default-pre) (hydra-disable) (catch (quote hydra-disable) (condition-case err (prog1 t (call-interactively (function previous-error))) @@ -220,6 +224,7 @@ Call the head: `previous-error'." The body can be accessed via `hydra-error/body'." (interactive) + (hydra-default-pre) (hydra-disable) (catch (quote hydra-disable) (when hydra-is-helpful (hydra-error/hint)) @@ -269,7 +274,7 @@ The body can be accessed via `hydra-error/body'." ("a" abbrev-mode "abbrev") ("q" nil "cancel"))) '(progn - (defun hydra-toggle/toggle-truncate-lines nil "Create a hydra with no body and the heads: + (defun hydra-toggle/toggle-truncate-lines-and-exit nil "Create a hydra with no body and the heads: \"t\": `toggle-truncate-lines', \"f\": `auto-fill-mode', @@ -280,11 +285,12 @@ The body can be accessed via `hydra-toggle/body'. Call the head: `toggle-truncate-lines'." (interactive) + (hydra-default-pre) (hydra-disable) (hydra-cleanup) (catch (quote hydra-disable) (call-interactively (function toggle-truncate-lines)))) - (defun hydra-toggle/auto-fill-mode nil "Create a hydra with no body and the heads: + (defun hydra-toggle/auto-fill-mode-and-exit nil "Create a hydra with no body and the heads: \"t\": `toggle-truncate-lines', \"f\": `auto-fill-mode', @@ -295,11 +301,12 @@ The body can be accessed via `hydra-toggle/body'. Call the head: `auto-fill-mode'." (interactive) + (hydra-default-pre) (hydra-disable) (hydra-cleanup) (catch (quote hydra-disable) (call-interactively (function auto-fill-mode)))) - (defun hydra-toggle/abbrev-mode nil "Create a hydra with no body and the heads: + (defun hydra-toggle/abbrev-mode-and-exit nil "Create a hydra with no body and the heads: \"t\": `toggle-truncate-lines', \"f\": `auto-fill-mode', @@ -310,6 +317,7 @@ The body can be accessed via `hydra-toggle/body'. Call the head: `abbrev-mode'." (interactive) + (hydra-default-pre) (hydra-disable) (hydra-cleanup) (catch (quote hydra-disable) @@ -325,6 +333,7 @@ The body can be accessed via `hydra-toggle/body'. Call the head: `nil'." (interactive) + (hydra-default-pre) (hydra-disable) (hydra-cleanup) (catch (quote hydra-disable))) @@ -346,6 +355,7 @@ Call the head: `nil'." The body can be accessed via `hydra-toggle/body'." (interactive) + (hydra-default-pre) (hydra-disable) (catch (quote hydra-disable) (when hydra-is-helpful (hydra-toggle/hint)) @@ -354,9 +364,9 @@ The body can be accessed via `hydra-toggle/body'." (setq hydra-curr-map (quote (keymap (7 . hydra-keyboard-quit) (113 . hydra-toggle/nil) - (97 . hydra-toggle/abbrev-mode) - (102 . hydra-toggle/auto-fill-mode) - (116 . hydra-toggle/toggle-truncate-lines) + (97 . hydra-toggle/abbrev-mode-and-exit) + (102 . hydra-toggle/auto-fill-mode-and-exit) + (116 . hydra-toggle/toggle-truncate-lines-and-exit) (switch-frame . hydra--handle-switch-frame) (kp-subtract . hydra--negative-argument) (kp-9 . hydra--digit-argument) @@ -399,7 +409,7 @@ The body can be accessed via `hydra-toggle/body'." ("k" previous-line) ("q" nil "quit"))) '(progn - (defun hydra-vi/hydra-keyboard-quit nil "Create a hydra with no body and the heads: + (defun hydra-vi/hydra-keyboard-quit-and-exit nil "Create a hydra with no body and the heads: \"\": `hydra-keyboard-quit', \"j\": `next-line', @@ -410,6 +420,7 @@ The body can be accessed via `hydra-vi/body'. Call the head: `hydra-keyboard-quit'." (interactive) + (hydra-default-pre) (set-cursor-color "#e52b50") (hydra-disable) (hydra-cleanup) @@ -427,6 +438,7 @@ The body can be accessed via `hydra-vi/body'. Call the head: `next-line'." (interactive) + (hydra-default-pre) (set-cursor-color "#e52b50") (hydra-disable) (catch (quote hydra-disable) @@ -447,7 +459,7 @@ Call the head: `next-line'." (113 . hydra-vi/nil) (107 . hydra-vi/previous-line) (106 . hydra-vi/next-line) - (7 . hydra-vi/hydra-keyboard-quit) + (7 . hydra-vi/hydra-keyboard-quit-and-exit) (switch-frame . hydra--handle-switch-frame) (kp-subtract . hydra--negative-argument) (kp-9 . hydra--digit-argument) @@ -484,6 +496,7 @@ The body can be accessed via `hydra-vi/body'. Call the head: `previous-line'." (interactive) + (hydra-default-pre) (set-cursor-color "#e52b50") (hydra-disable) (catch (quote hydra-disable) @@ -504,7 +517,7 @@ Call the head: `previous-line'." (113 . hydra-vi/nil) (107 . hydra-vi/previous-line) (106 . hydra-vi/next-line) - (7 . hydra-vi/hydra-keyboard-quit) + (7 . hydra-vi/hydra-keyboard-quit-and-exit) (switch-frame . hydra--handle-switch-frame) (kp-subtract . hydra--negative-argument) (kp-9 . hydra--digit-argument) @@ -541,6 +554,7 @@ The body can be accessed via `hydra-vi/body'. Call the head: `nil'." (interactive) + (hydra-default-pre) (set-cursor-color "#e52b50") (hydra-disable) (hydra-cleanup) @@ -562,6 +576,7 @@ Call the head: `nil'." The body can be accessed via `hydra-vi/body'." (interactive) + (hydra-default-pre) (set-cursor-color "#e52b50") (hydra-disable) (catch (quote hydra-disable) @@ -577,7 +592,7 @@ The body can be accessed via `hydra-vi/body'." (113 . hydra-vi/nil) (107 . hydra-vi/previous-line) (106 . hydra-vi/next-line) - (7 . hydra-vi/hydra-keyboard-quit) + (7 . hydra-vi/hydra-keyboard-quit-and-exit) (switch-frame . hydra--handle-switch-frame) (kp-subtract . hydra--negative-argument) (kp-9 . hydra--digit-argument) @@ -705,7 +720,7 @@ The body can be accessed via `hydra-vi/body'." ("l" text-scale-decrease "out") ("q" nil "quit")))))) -(ert-deftest hydra-format () +(ert-deftest hydra-format-1 () (should (equal (let ((hydra-fontify-head-function 'hydra-fontify-head-greyscale)) @@ -728,7 +743,41 @@ _f_ auto-fill-mode: %`auto-fill-function %s auto-fill-mode: %S " "{a}" abbrev-mode "{d}" debug-on-error "{f}" auto-fill-function) "[[q]]: quit")))) -(ert-deftest hydra-format-with-sexp () +(ert-deftest hydra-format-2 () + (should (equal + (let ((hydra-fontify-head-function + 'hydra-fontify-head-greyscale)) + (hydra--format + 'bar + nil + "\n bar %s`foo\n" + '(("a" (quote t) "" :cmd-name bar/lambda-a) + ("q" nil "" :cmd-name bar/nil)))) + '(concat (format " bar %s\n" foo) "{a}, [q]")))) + +(ert-deftest hydra-format-3 () + (should (equal + (let ((hydra-fontify-head-function + 'hydra-fontify-head-greyscale)) + (hydra--format + 'bar + nil + "\n__ ^^ace jump\n" + '(("" ace-jump-char-mode nil :cmd-name bar/ace-jump-char-mode)))) + '(concat (format "%s ace jump\n" "{}") "")))) + +(ert-deftest hydra-format-4 () + (should + (equal (hydra--format + nil + '(nil nil :hint nil) + "\n_j_,_k_" + '(("j" nil) ("k" nil))) + '(concat (format "%s,%s" + #("j" 0 1 (face hydra-face-blue)) + #("k" 0 1 (face hydra-face-blue))) "")))) + +(ert-deftest hydra-format-with-sexp-1 () (should (equal (let ((hydra-fontify-head-function 'hydra-fontify-head-greyscale)) @@ -743,6 +792,21 @@ _f_ auto-fill-mode: %`auto-fill-function (buffer-narrowed-p))) "[[q]]: cancel")))) +(ert-deftest hydra-format-with-sexp-2 () + (should (equal + (let ((hydra-fontify-head-function + 'hydra-fontify-head-greyscale)) + (hydra--format + 'hydra-toggle nil + "\n_n_ narrow-or-widen-dwim %s(progn (message \"checking\")(buffer-narrowed-p))asdf\n" + '(("n" narrow-to-region nil) ("q" nil "cancel")))) + '(concat (format "%s narrow-or-widen-dwim %sasdf\n" + "{n}" + (progn + (message "checking") + (buffer-narrowed-p))) + "[[q]]: cancel")))) + (ert-deftest hydra-compat-colors-1 () (should (equal (hydra--head-color '("e" (message "Exiting now") "blue") @@ -756,6 +820,10 @@ _f_ auto-fill-mode: %`auto-fill-function '("e" (message "Exiting now") "blue") '(nil nil :exit t)) 'blue)) + (should (equal (hydra--head-color + '("j" next-line "" :exit t) + '(nil nil)) + 'blue)) (should (equal (hydra--head-color '("c" (message "Continuing") "red" :exit nil) '(nil nil :exit t)) @@ -849,6 +917,7 @@ The body can be accessed via `hydra-zoom/body'. Call the head: `(text-scale-set 0)'." (interactive) + (hydra-default-pre) (hydra-disable) (catch (quote hydra-disable) (condition-case err (prog1 t (call-interactively (function (lambda nil (interactive) @@ -883,12 +952,12 @@ Call the head: `(text-scale-set 0)'." (52 . hydra--digit-argument) (51 . hydra--digit-argument) (50 . hydra--digit-argument) - (49 . hydra-zoom/lambda-0) - (48 . hydra-zoom/lambda-0) + (49 . hydra-zoom/lambda-0-and-exit) + (48 . hydra-zoom/lambda-0-and-exit) (45 . hydra--negative-argument) (21 . hydra--universal-argument)))) t (lambda nil (hydra-cleanup)))))) - (defun hydra-zoom/lambda-0 nil "Create a hydra with no body and the heads: + (defun hydra-zoom/lambda-0-and-exit nil "Create a hydra with no body and the heads: \"r\": `(text-scale-set 0)', \"0\": `(text-scale-set 0)', @@ -898,6 +967,7 @@ The body can be accessed via `hydra-zoom/body'. Call the head: `(text-scale-set 0)'." (interactive) + (hydra-default-pre) (hydra-disable) (hydra-cleanup) (catch (quote hydra-disable) @@ -916,6 +986,7 @@ Call the head: `(text-scale-set 0)'." The body can be accessed via `hydra-zoom/body'." (interactive) + (hydra-default-pre) (hydra-disable) (catch (quote hydra-disable) (when hydra-is-helpful (hydra-zoom/hint)) @@ -944,8 +1015,8 @@ The body can be accessed via `hydra-zoom/body'." (52 . hydra--digit-argument) (51 . hydra--digit-argument) (50 . hydra--digit-argument) - (49 . hydra-zoom/lambda-0) - (48 . hydra-zoom/lambda-0) + (49 . hydra-zoom/lambda-0-and-exit) + (48 . hydra-zoom/lambda-0-and-exit) (45 . hydra--negative-argument) (21 . hydra--universal-argument)))) t (lambda nil (hydra-cleanup)))) @@ -971,6 +1042,7 @@ The body can be accessed via `hydra-zoom/body'. Call the head: `(text-scale-set 0)'." (interactive) + (hydra-default-pre) (hydra-disable) (catch (quote hydra-disable) (condition-case err (prog1 t (call-interactively (function (lambda nil (interactive) @@ -1006,11 +1078,11 @@ Call the head: `(text-scale-set 0)'." (51 . hydra--digit-argument) (50 . hydra--digit-argument) (49 . hydra-zoom/lambda-r) - (48 . hydra-zoom/lambda-0) + (48 . hydra-zoom/lambda-0-and-exit) (45 . hydra--negative-argument) (21 . hydra--universal-argument)))) t (lambda nil (hydra-cleanup)))))) - (defun hydra-zoom/lambda-0 nil "Create a hydra with no body and the heads: + (defun hydra-zoom/lambda-0-and-exit nil "Create a hydra with no body and the heads: \"r\": `(text-scale-set 0)', \"0\": `(text-scale-set 0)', @@ -1020,6 +1092,7 @@ The body can be accessed via `hydra-zoom/body'. Call the head: `(text-scale-set 0)'." (interactive) + (hydra-default-pre) (hydra-disable) (hydra-cleanup) (catch (quote hydra-disable) @@ -1038,6 +1111,7 @@ Call the head: `(text-scale-set 0)'." The body can be accessed via `hydra-zoom/body'." (interactive) + (hydra-default-pre) (hydra-disable) (catch (quote hydra-disable) (when hydra-is-helpful (hydra-zoom/hint)) @@ -1067,7 +1141,7 @@ The body can be accessed via `hydra-zoom/body'." (51 . hydra--digit-argument) (50 . hydra--digit-argument) (49 . hydra-zoom/lambda-r) - (48 . hydra-zoom/lambda-0) + (48 . hydra-zoom/lambda-0-and-exit) (45 . hydra--negative-argument) (21 . hydra--universal-argument)))) t (lambda nil (hydra-cleanup)))) @@ -1120,6 +1194,12 @@ _r_ Commander William Riker: % -8`hydra-tng/riker^ _t_ Deanna Troi: _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher _w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^" 1))))) +(ert-deftest hydra--make-funcall () + (should (equal (let ((body-pre 'foo)) + (hydra--make-funcall body-pre) + body-pre) + '(funcall (function foo))))) + (provide 'hydra-test) ;;; hydra-test.el ends here