aboutsummaryrefslogtreecommitdiff
path: root/tests/test-org-config-keymap-ownership.el
blob: dd7d314daf88a326b20809da5f2833cea454c3bd (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
;;; test-org-config-keymap-ownership.el --- Tests for Org keymap ownership -*- lexical-binding: t; -*-

;;; Commentary:

;; Ensure org-config owns C-; O through one keymap.

;;; Code:

(require 'ert)

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(setq load-prefer-newer t)

(defun org-appear-mode (&optional _arg)
  "Stub `org-appear-mode' for loading org-config in batch tests.")
(provide 'org-appear)

(require 'org-config)

(ert-deftest test-org-config-keymap-ownership-normal-org-prefix-uses-org-map ()
  "C-; O should be mounted through `cj/org-map'."
  (should (eq (keymap-lookup cj/custom-keymap "O")
              cj/org-map)))

(ert-deftest test-org-config-keymap-ownership-normal-clear-cache-on-org-map ()
  "The Org prefix should expose one cache-clear command on c."
  (should (eq (keymap-lookup cj/org-map "c")
              #'cj/org-clear-element-cache)))

(ert-deftest test-org-config-keymap-ownership-regression-no-duplicate-org-keymap ()
  "The old duplicate `cj/org-keymap' binding should not exist."
  (should-not (boundp 'cj/org-keymap)))

(ert-deftest test-org-config-keymap-ownership-normal-clear-cache-defaults-all ()
  "Cache clear should reset all Org buffers by default."
  (let ((current-prefix-arg nil)
        (calls nil))
    (cl-letf (((symbol-function 'org-element-cache-reset)
               (lambda (&optional arg) (push arg calls))))
      (cj/org-clear-element-cache))
    (should (equal calls '(all)))))

(ert-deftest test-org-config-keymap-ownership-normal-prefix-clears-current-buffer ()
  "Cache clear should reset only the current Org buffer with a prefix."
  (let ((current-prefix-arg '(4))
        (calls nil))
    (cl-letf (((symbol-function 'org-element-cache-reset)
               (lambda (&optional arg) (push arg calls))))
      (with-temp-buffer
        (setq major-mode 'org-mode)
        (cj/org-clear-element-cache)))
    (should (equal calls '(nil)))))

(provide 'test-org-config-keymap-ownership)
;;; test-org-config-keymap-ownership.el ends here