blob: 21b67c69bd1b41077d4ee1115169907aa0c9c1eb (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
;;; test-org-drill-small-branch-coverage.el --- Tests for small branch coverage -*- lexical-binding: t; -*-
;;; Commentary:
;; Small branch-coverage gaps that don't fit a thematic file: SM5
;; interval with random-noise enabled, the `--read-key-sequence' input-
;; method dance, and `goto-drill-entry-heading''s error branch.
;;; Code:
(require 'ert)
(require 'cl-lib)
(require 'org)
(require 'org-drill)
;;;; SM5 interval with random-noise enabled
(ert-deftest test-determine-next-interval-sm5-with-random-noise ()
"When the random-noise flag is t, the SM5 next-interval is multiplied by
the dispersal factor."
(let ((org-drill-add-random-noise-to-intervals-p t))
(cl-letf (((symbol-function 'org-drill-random-dispersal-factor)
(lambda () 1.5)))
(let* ((result (org-drill-determine-next-interval-sm5
4.0 2 2.5 5 0 5.0 1
org-drill-sm5-optimal-factor-matrix))
(next (nth 0 result)))
(should (numberp next))
(should (> next 0))))))
;;;; --read-key-sequence input-method dance
(ert-deftest test-read-key-sequence-deactivates-and-reactivates-input-method ()
"If an input method is active, --read-key-sequence deactivates it for the
read and re-activates it on the way out."
(let ((current-input-method 'pretend-im)
(deactivated nil)
(reactivated nil))
(cl-letf (((symbol-function 'deactivate-input-method)
(lambda () (setq deactivated t)))
((symbol-function 'activate-input-method)
(lambda (im) (setq reactivated im)))
((symbol-function 'read-key-sequence)
(lambda (&rest _) "x")))
(org-drill--read-key-sequence "p"))
(should deactivated)
(should (eq 'pretend-im reactivated))))
(ert-deftest test-read-key-sequence-no-input-method-skips-deactivate ()
"With no input method active, neither deactivate nor activate is called."
(let ((current-input-method nil)
(deactivated nil)
(reactivated nil))
(cl-letf (((symbol-function 'deactivate-input-method)
(lambda () (setq deactivated t)))
((symbol-function 'activate-input-method)
(lambda (_) (setq reactivated t)))
((symbol-function 'read-key-sequence)
(lambda (&rest _) "x")))
(org-drill--read-key-sequence "p"))
(should-not deactivated)
(should-not reactivated)))
;;;; goto-drill-entry-heading error branch
(ert-deftest test-goto-drill-entry-heading-no-drill-parent-errors ()
"When no ancestor heading carries the drill tag, the function errors."
(with-temp-buffer
(insert "* Plain :tagged-but-not-drill:\n** Child\nbody\n")
(org-mode)
(goto-char (point-max))
(cl-letf (((symbol-function 'org-drill-part-of-drill-entry-p)
(lambda (&rest _) t))
;; Force entry-p false at every level so the while loop walks
;; up until org-up-heading-safe returns nil.
((symbol-function 'org-drill-entry-p) (lambda (&rest _) nil)))
(should-error (org-drill-goto-drill-entry-heading)))))
;;;; org-drill-test-display (developer helper)
(ert-deftest test-org-drill-test-display-toggles-zysygy-tag ()
"The dev helper toggles a `zysygy' tag on, runs entry-f, then toggles off."
(with-temp-buffer
(insert "* Item\nbody\n")
(org-mode)
(goto-char (point-min))
(let ((entry-f-called nil))
(cl-letf (((symbol-function 'org-drill-entry-f)
(lambda (&rest _) (setq entry-f-called t)))
((symbol-function 'org-drill-test-display-rescheduler) #'ignore))
(org-drill-test-display))
(should entry-f-called)
;; Tag was toggled off in the unwind-protect cleanup, so the
;; entry should not be tagged.
(should-not (member "zysygy" (org-get-tags))))))
(ert-deftest test-org-drill-test-display-rescheduler-runs-hook-and-reads-key ()
"The rescheduler runs the answer hook and waits on read-key-sequence."
(let ((hook-ran nil)
(key-read nil))
(let ((org-drill-display-answer-hook
(list (lambda () (setq hook-ran t)))))
(cl-letf (((symbol-function 'read-key-sequence)
(lambda (&rest _) (setq key-read t) "x")))
(org-drill-test-display-rescheduler nil)))
(should hook-ran)
(should key-read)))
;;;; org-drill-mode cloze-face flag branches
(ert-deftest test-org-drill-mode-with-flag-installs-cloze-keywords ()
"When `org-drill-use-visible-cloze-face-p' is t, enabling `org-drill-mode'
installs the cloze keyword spec buffer-locally."
(with-temp-buffer
(org-mode)
(let ((org-drill-use-visible-cloze-face-p t))
(org-drill-mode 1)
(should org-drill--installed-cloze-keywords))))
(ert-deftest test-org-drill-mode-without-flag-installs-nothing ()
"When the flag is nil, enabling `org-drill-mode' installs no cloze keywords."
(with-temp-buffer
(org-mode)
(let ((org-drill-use-visible-cloze-face-p nil))
(org-drill-mode 1)
(should (null org-drill--installed-cloze-keywords)))))
(provide 'test-org-drill-small-branch-coverage)
;;; test-org-drill-small-branch-coverage.el ends here
|