diff options
| -rw-r--r-- | tests/test-org-drill-resume-nil-session.el | 46 | ||||
| -rw-r--r-- | tests/test-org-drill-route-rating-result.el | 50 |
2 files changed, 96 insertions, 0 deletions
diff --git a/tests/test-org-drill-resume-nil-session.el b/tests/test-org-drill-resume-nil-session.el index fd64faf..a2b2e7c 100644 --- a/tests/test-org-drill-resume-nil-session.el +++ b/tests/test-org-drill-resume-nil-session.el @@ -34,6 +34,52 @@ not an obscure eieio type error." (let ((org-drill-last-session nil)) (should-error (org-drill-resume) :type 'user-error))) +;;;; org-drill-resume — happy paths + +(ert-deftest test-org-drill-resume-with-pending-entries-resumes () + "When the prior session has pending entries, resume calls org-drill with resume-p=t." + (let* ((session (org-drill-session)) + (org-drill-last-session session) + (resume-args nil)) + (cl-letf (((symbol-function 'org-drill-entries-pending-p) (lambda (_) t)) + ((symbol-function 'org-drill) + (lambda (&rest args) (setq resume-args args)))) + (org-drill-resume)) + (should resume-args) + (should (nth 2 resume-args)))) + +(ert-deftest test-org-drill-resume-finished-with-no-pending-says-finished () + "When the session is done with no remaining pending count, prints the +'finished' message." + (let* ((session (org-drill-session)) + (org-drill-last-session session) + (messages nil)) + (cl-letf (((symbol-function 'message) + (lambda (fmt &rest args) + (when fmt (push (apply #'format fmt args) messages))))) + (org-drill-resume)) + (should (cl-some (lambda (m) (string-match-p "finished" m)) messages)))) + +(ert-deftest test-org-drill-resume-finished-with-y-starts-new () + "When session is done but pending count is positive and user answers y, +org-drill-again runs." + (let* ((session (org-drill-session)) + (org-drill-last-session session) + (m (let ((mk (make-marker))) (set-marker mk 1) mk)) + (again-called nil)) + ;; Done-entries non-empty + new-entries non-empty + done-entries reaches limit + ;; tricky to set up cleanly. Easier: stub the predicates. + (cl-letf (((symbol-function 'org-drill-entries-pending-p) + (lambda (_) nil)) + ((symbol-function 'org-drill-pending-entry-count) + (lambda (_) 5)) + ((symbol-function 'y-or-n-p) (lambda (&rest _) t)) + ((symbol-function 'org-drill-again) + (lambda (&rest _) (setq again-called t))) + ((symbol-function 'message) #'ignore)) + (org-drill-resume)) + (should again-called))) + (provide 'test-org-drill-resume-nil-session) ;;; test-org-drill-resume-nil-session.el ends here diff --git a/tests/test-org-drill-route-rating-result.el b/tests/test-org-drill-route-rating-result.el index 5469bc8..5ea29b7 100644 --- a/tests/test-org-drill-route-rating-result.el +++ b/tests/test-org-drill-route-rating-result.el @@ -67,5 +67,55 @@ (org-drill--route-rating-result session m1 0)) (should shuffle-called))) +;;;; org-drill--pick-next-marker + +(ert-deftest test-pick-next-marker-not-resuming-pops-from-queue () + "Without resuming-p, the result is the popped pending entry." + (let ((session (org-drill-session))) + (cl-letf (((symbol-function 'org-drill-pop-next-pending-entry) + (lambda (_) 'popped-marker))) + (let ((result (org-drill--pick-next-marker session nil))) + (should (equal '(popped-marker . nil) result)))))) + +(ert-deftest test-pick-next-marker-resuming-with-current-item-keeps-it () + "When resuming-p is t and current-item is a live drill entry, return it +and flip resume-p to nil so subsequent ticks don't repeat the same entry." + (let ((session (org-drill-session))) + (with-temp-buffer + (insert "* Drill :drill:\nbody\n") + (org-mode) + (goto-char (point-min)) + (let ((m (point-marker))) + (oset session current-item m) + (let ((result (org-drill--pick-next-marker session t))) + (should (eq m (car result))) + (should (null (cdr result)))))))) + +(ert-deftest test-pick-next-marker-resuming-with-nil-current-item-pops-fresh () + "When resuming-p is t but current-item is nil, fall through to popping a +fresh entry from the pending queue." + (let ((session (org-drill-session))) + (oset session current-item nil) + (cl-letf (((symbol-function 'org-drill-pop-next-pending-entry) + (lambda (_) 'fresh-marker))) + (let ((result (org-drill--pick-next-marker session t))) + (should (eq 'fresh-marker (car result))) + ;; resuming-p still flowing through. + (should (eq t (cdr result))))))) + +(ert-deftest test-pick-next-marker-resuming-with-non-drill-current-item-pops-fresh () + "When current-item is set but no longer points at a drill entry, fall +through to popping a fresh entry." + (let ((session (org-drill-session))) + (with-temp-buffer + (insert "Plain text — not a drill heading.\n") + (org-mode) + (goto-char (point-min)) + (oset session current-item (point-marker)) + (cl-letf (((symbol-function 'org-drill-pop-next-pending-entry) + (lambda (_) 'fresh-marker))) + (let ((result (org-drill--pick-next-marker session t))) + (should (eq 'fresh-marker (car result)))))))) + (provide 'test-org-drill-route-rating-result) ;;; test-org-drill-route-rating-result.el ends here |
