aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-27 21:09:29 -0500
committerCraig Jennings <c@cjennings.net>2026-05-27 21:09:29 -0500
commit88e248bcc4db4d47850a8eca914ffd4c6eb0249c (patch)
tree32fd120882ad79ea800dffd0647706128164ed2e /tests
parent39d01b75ac679410821ce5e16c09ec6b7799f791 (diff)
downloadorg-drill-88e248bcc4db4d47850a8eca914ffd4c6eb0249c.tar.gz
org-drill-88e248bcc4db4d47850a8eca914ffd4c6eb0249c.zip
feat: add org-drill-on-timeout-action to drop unfinished cards at the time limit
Implements upstream #56. When org-drill-maximum-duration is reached, the session used to keep presenting the in-progress card and the again-queue until they drained, so the only way out was to finish them or interrupt. I added the defcustom org-drill-on-timeout-action with a discard-current value that ends the session as soon as the limit is hit, leaving the dropped cards untouched: they keep their existing scheduling and turn up again next session. The default, finish-current, preserves the old behavior. The gate lives in org-drill-entries-pending-p, the single predicate the drill loop checks between cards. Under discard-current past the limit, the in-progress and again items stop counting as pending, so the loop ends instead of draining them.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-org-drill-session-state.el42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test-org-drill-session-state.el b/tests/test-org-drill-session-state.el
index 1fe58d2..3f99a8e 100644
--- a/tests/test-org-drill-session-state.el
+++ b/tests/test-org-drill-session-state.el
@@ -77,6 +77,48 @@ session look long-expired."
(eieio-oset session slot (list (make-marker-at 1)))
(should (org-drill-entries-pending-p session)))))
+;;;; org-drill-on-timeout-action — discard-current
+
+(ert-deftest test-org-drill-entries-pending-p-discard-current-times-out-drops-again ()
+ "With `discard-current' and the duration reached, the again-queue no longer
+keeps the session pending — time is up, so the re-drill items are dropped."
+ (let ((session (org-drill-session))
+ (org-drill-on-timeout-action 'discard-current)
+ (org-drill-maximum-duration 1)) ; 1-minute limit
+ (oset session start-time (- (float-time (current-time)) 3600)) ; started an hour ago
+ (oset session again-entries (list (make-marker-at 1)))
+ (should-not (org-drill-entries-pending-p session))))
+
+(ert-deftest test-org-drill-entries-pending-p-discard-current-times-out-drops-current-item ()
+ "With `discard-current' and the duration reached, a leftover current-item is
+dropped rather than forcing the session to continue."
+ (let ((session (org-drill-session))
+ (org-drill-on-timeout-action 'discard-current)
+ (org-drill-maximum-duration 1))
+ (oset session start-time (- (float-time (current-time)) 3600))
+ (oset session current-item (make-marker-at 1))
+ (should-not (org-drill-entries-pending-p session))))
+
+(ert-deftest test-org-drill-entries-pending-p-finish-current-times-out-keeps-again ()
+ "Default `finish-current' preserves the old behavior: the again-queue keeps
+the session pending even past the duration limit."
+ (let ((session (org-drill-session))
+ (org-drill-on-timeout-action 'finish-current)
+ (org-drill-maximum-duration 1))
+ (oset session start-time (- (float-time (current-time)) 3600))
+ (oset session again-entries (list (make-marker-at 1)))
+ (should (org-drill-entries-pending-p session))))
+
+(ert-deftest test-org-drill-entries-pending-p-discard-current-before-timeout-is-normal ()
+ "Before the duration is reached, `discard-current' behaves normally — queued
+items still count as pending."
+ (let ((session (org-drill-session))
+ (org-drill-on-timeout-action 'discard-current)
+ (org-drill-maximum-duration 20))
+ (oset session start-time (float-time (current-time))) ; just started
+ (oset session again-entries (list (make-marker-at 1)))
+ (should (org-drill-entries-pending-p session))))
+
;;;; org-drill-pending-entry-count
(ert-deftest test-org-drill-pending-entry-count-empty-session-zero ()