blob: 198055c50a931b7443ffedb6311566d3b8301be5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
;;; hyperbole-tests.el --- tests for hyperbole.el -*- lexical-binding: t; -*-
;;
;; Author: Mats Lidell <matsl@gnu.org>
;;
;; Orig-Date: 8-Jan-22 at 23:40:00
;; Last-Mod: 13-May-23 at 10:10:52 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2022 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
;;; Commentary:
;;
;; Tests for "../hyperbole.el"
;;; Code:
(require 'ert)
(require 'hyperbole)
;; The reason verify-keybinding in these tests is a macro instead of a
;; function is that in the event of a failure, it makes the keybinding
;; that failed show up in ERT's output. -- Copied from edebug-tests.el
(defun hyperbole-key-bindings (set)
"If SET is t, verify keys are bound and if nil, verify they are unbound."
(let ((hyperbole-mode-map (make-sparse-keymap))
(hkey-init set))
(cl-letf (((symbol-function 'where-is-internal) (lambda (_func &optional _map) nil))
((symbol-function 'hyperb:window-system) (lambda () t)))
(hkey-initialize)
(cl-macrolet ((verify-keybinding (verify key binding)
`(if ,verify
(should (eq (lookup-key hyperbole-mode-map ,key)
,binding))
(should-not (eq (lookup-key hyperbole-mode-map ,key)
,binding)))))
(verify-keybinding set "\C-c@" #'hycontrol-windows-grid)
(verify-keybinding set "\C-c\C-m" #'hui-select-thing)
(verify-keybinding set "\C-c\\" #'hycontrol-enable-windows-mode)
(verify-keybinding set "\C-c/" #'hui-search-web)
(verify-keybinding set "\C-c." #'hui-select-goto-matching-delimiter)
(mapc (lambda (key) (verify-keybinding set key #'hkey-either))
'("\M-\C-m"
;; Todo: How to verify these bindings.
;;"ESC RET" "M-RET" "ESC <return>" "M-<return>"
))
(verify-keybinding set "\C-hA" #'hkey-help)
(verify-keybinding set "\M-o" #'hkey-operate)))))
(ert-deftest hyperbole-keymap-tests ()
"Verify all key bindings are set."
(hyperbole-key-bindings t))
(ert-deftest hyperbole-hkey-init-controls-tests ()
"Verify all key bindings are set."
(hyperbole-key-bindings nil))
(ert-deftest hyperbole-global-key-binding-tests ()
"Verify the global keys are bound."
(let ((hyperbole-mode-map (make-sparse-keymap))
(hkey-init t))
(hkey-initialize)
(cl-macrolet ((verify-keybinding (key binding)
`(should (eq (lookup-key global-map ,key) ,binding))))
(verify-keybinding "\C-hh" #'hyperbole))))
(provide 'hyperbole-tests)
;;; hyperbole-tests.el ends here
|