From 60483cb282b2b6eb40585decb781f2ae2bed44a0 Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Tue, 31 Mar 2015 14:38:52 +0200 Subject: [PATCH] Add integration testing * hydra-test.el (hydra-simple): Add example hydra that will be run. (hydra-with): New defmacro. (hydra-integration-1): Add test. Re #101 --- hydra-test.el | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/hydra-test.el b/hydra-test.el index bea2740..c101e2b 100644 --- a/hydra-test.el +++ b/hydra-test.el @@ -968,6 +968,48 @@ _w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to body-pre) '(funcall (function foo))))) +(defhydra hydra-simple (global-map "C-c") + ("a" (insert "j")) + ("b" (insert "k")) + ("q" nil)) + +(defmacro hydra-with (in &rest body) + `(let ((temp-buffer (generate-new-buffer " *temp*"))) + (save-window-excursion + (unwind-protect + (progn + (switch-to-buffer temp-buffer) + (transient-mark-mode 1) + (insert ,in) + (goto-char (point-min)) + (when (search-forward "~" nil t) + (backward-delete-char 1) + (set-mark (point))) + (goto-char (point-max)) + (search-backward "|") + (delete-char 1) + (setq current-prefix-arg) + ,@body + (insert "|") + (when (region-active-p) + (exchange-point-and-mark) + (insert "~")) + (buffer-substring-no-properties + (point-min) + (point-max))) + (and (buffer-name temp-buffer) + (kill-buffer temp-buffer)))))) + +(ert-deftest hydra-integration-1 () + (should (string= (hydra-with "|" + (execute-kbd-macro + (kbd "C-c aabbaaqaabbaa"))) + "jjkkjjaabbaa|")) + (should (string= (hydra-with "|" + (execute-kbd-macro + (kbd "C-c aabb C-g aaqaabbaa"))) + "jjkkaaqaabbaa|"))) + (provide 'hydra-test) ;;; hydra-test.el ends here