;;; 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 (make-org-drill-card-state :last-interval 4.0 :repetitions 2 :ease 2.5 :failures 0 :meanq 5.0 :total-repeats 1) 5 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