;;; test-daily-prep-agenda.el --- ERT tests for daily-prep-agenda -*- lexical-binding: t; -*- ;; Run: emacs --batch -q -L .ai/scripts -l ert -l test-daily-prep-agenda.el \ ;; -f ert-run-tests-batch-and-exit (require 'ert) (require 'cl-lib) (require 'daily-prep-agenda) ;;; dp-iso-date -------------------------------------------------------------- (ert-deftest dp-iso-date-extracts-from-active-timestamp () (should (equal (dp-iso-date "<2026-04-25 Sat 16:00>") "2026-04-25"))) (ert-deftest dp-iso-date-extracts-from-inactive-timestamp () (should (equal (dp-iso-date "[2026-05-29 Fri]") "2026-05-29"))) (ert-deftest dp-iso-date-no-date-returns-nil () (should (null (dp-iso-date "no date in here")))) (ert-deftest dp-iso-date-nil-input-returns-nil () (should (null (dp-iso-date nil)))) ;;; dp-bucket -------------------------------------------------------------- ;; dp-today / dp-week-end are dynamic; pin them so bucketing is deterministic. (defmacro dp-test--with-clock (&rest body) `(let ((dp-today "2026-05-15") (dp-week-end "2026-05-22")) ,@body)) (ert-deftest dp-bucket-deadline-before-today-is-overdue () (dp-test--with-clock (should (eq (dp-bucket '(:deadline "2026-05-10")) 'overdue)))) (ert-deftest dp-bucket-deadline-today-is-today () (dp-test--with-clock (should (eq (dp-bucket '(:deadline "2026-05-15")) 'today)))) (ert-deftest dp-bucket-scheduled-today-is-today () (dp-test--with-clock (should (eq (dp-bucket '(:scheduled "2026-05-15")) 'today)))) (ert-deftest dp-bucket-scheduled-before-today-is-overdue () (dp-test--with-clock (should (eq (dp-bucket '(:scheduled "2026-05-12")) 'overdue)))) (ert-deftest dp-bucket-deadline-within-week-is-this-week () (dp-test--with-clock (should (eq (dp-bucket '(:deadline "2026-05-20")) 'this-week)))) (ert-deftest dp-bucket-priority-a-undated-is-pri-a () (dp-test--with-clock (should (eq (dp-bucket '(:priority ?A)) 'pri-a)))) (ert-deftest dp-bucket-priority-b-undated-is-pri-b () (dp-test--with-clock (should (eq (dp-bucket '(:priority ?B)) 'pri-b)))) (ert-deftest dp-bucket-no-date-no-priority-is-other () (dp-test--with-clock (should (eq (dp-bucket '(:heading "x")) 'other)))) ;;; dp-format-entry -------------------------------------------------------- (ert-deftest dp-format-entry-renders-heading-loc-deadline-body () (let ((out (dp-format-entry '(:state "TODO" :priority ?A :heading "Ship it" :file "/x/todo.org" :line 42 :deadline-raw "<2026-05-20 Wed>" :scheduled-raw nil :body "do the thing")))) (should (string-match-p "\\*\\* TODO \\[#A\\] Ship it" out)) (should (string-match-p ":LOC: todo.org:42" out)) (should (string-match-p "DEADLINE: <2026-05-20 Wed>" out)) (should (string-match-p " do the thing" out)))) (ert-deftest dp-format-entry-omits-priority-cookie-when-absent () (let ((out (dp-format-entry '(:state "TODO" :heading "No priority" :file "f.org" :line 1)))) (should (string-match-p "\\*\\* TODO No priority" out)) (should-not (string-match-p "\\[#" out)))) ;;; dp-collect (exercises dp-active-candidate-p + dp-entry-info) ------------ (ert-deftest dp-collect-picks-active-priority-and-dated-entries () (let ((tmp (make-temp-file "dp-test" nil ".org" (concat "* TODO [#A] urgent thing\n" "* TODO [#C] low prio no date\n" "* TODO scheduled thing\n" "SCHEDULED: <2026-05-20 Wed>\n" "* DONE [#A] finished\n")))) (unwind-protect (let ((headings (mapcar (lambda (e) (plist-get e :heading)) (dp-collect (list tmp))))) ;; [#A]-active and the SCHEDULED entry qualify; ;; the undated [#C] and the DONE entry do not. (should (member "urgent thing" headings)) (should (member "scheduled thing" headings)) (should-not (member "low prio no date" headings)) (should-not (member "finished" headings))) (delete-file tmp)))) (provide 'test-daily-prep-agenda) ;;; test-daily-prep-agenda.el ends here