From b2c295f0fdca97734716fec18a30b49f4c30e81c Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 6 Apr 2021 23:16:51 -0400 Subject: [PATCH] ADD tests for project status --- .../lib/org-x/test/org-x-test-buffer-state.el | 185 +++++++++++++++++- local/lib/org-x/test/org-x-test-common.el | 5 +- 2 files changed, 188 insertions(+), 2 deletions(-) diff --git a/local/lib/org-x/test/org-x-test-buffer-state.el b/local/lib/org-x/test/org-x-test-buffer-state.el index 29a1c9e..06ed67f 100644 --- a/local/lib/org-x/test/org-x-test-buffer-state.el +++ b/local/lib/org-x/test/org-x-test-buffer-state.el @@ -53,7 +53,10 @@ Forms are denoted like %(FORM)%." "Call `org-ml--with-org-env' with BODY and STRING as the buffer." (let ((s (->> (if (listp string) (s-join "\n" string) string) (org-x-test-parse-forms)))) - `(org-ml--with-org-env (insert ,s) ,@body))) + `(org-ml--with-org-env + (insert ,s) + (goto-char (point-min)) + ,@body))) (defmacro org-x--test-buffer-strings (name test &rest specs) "Run TEST form for SPECS called by toplevel NAME." @@ -152,5 +155,185 @@ Forms are denoted like %(FORM)%." ":END:") => :active) +;; NOTE the silly thing about this function is that headlines need not actually +;; be projects :/ +(org-x--test-buffer-strings "Project status" + (org-x-get-project-status) + + "scheduled" + ("* TODO project" + "SCHEDULED: %(org-x-gen-ts 0)%") + => :scheduled-project + + "held" + ("* HOLD project") + => :held + + ;; ASSUME the inert code paths are fully tested elsewhere + "inert" + ("* HOLD project" + ":PROPERTIES:" + ":CREATED: %(org-x-gen-ts (- (* (1+ org-x-inert-delay-days) 24 60 60)))%" + ":END:") + => :inert + + "invalid todo (NEXT)" + ("* NEXT project") + => :invalid-todostate + + "invalid todo (WAIT)" + ("* WAIT project") + => :invalid-todostate + + "canceled (complete)" + ("* CANC project") + => :complete + + "canceled (archivable)" + ("* CANC project" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%") + => :archivable + + "complete (subtask complete)" + ("* DONE project" + "CLOSED: %(org-x-gen-ts 0)%" + "** DONE task 1" + "CLOSED: %(org-x-gen-ts 0)%") + => :complete + + ;; TODO this should be :complete + "complete (subtask archivable)" + ("* DONE project" + "CLOSED: %(org-x-gen-ts 0)%" + "** DONE task 1" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%") + => :archivable + + "archivable" + ("* DONE project" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%" + "** DONE task 1" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%") + => :archivable + + "done-incomplete (subtask TODO)" + ("* DONE project" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%" + "** TODO task 1") + => :done-incomplete + + "done-incomplete (subtask TODO)" + ("* DONE project" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%" + "** TODO task 1") + => :done-incomplete + + ;; TODO this should be an error + "done-incomplete (subtask done-unclosed)" + ("* DONE project" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%" + "** DONE task 1") + => :complete + + ;; TODO this should be :complete + "complete (subtask archivable nested)" + ("* DONE project" + "CLOSED: %(org-x-gen-ts 0)%" + "** DONE task 1" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%" + "*** DONE task 2" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%") + => :archivable + + "archivable (nested)" + ("* DONE project" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%" + "** DONE task 1" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%" + "*** DONE task 2" + "CLOSED: %(org-x-gen-ts (- (* (1+ org-x-archive-delay) 24 60 60)))%") + => :archivable + + ;; TODO there are many other paths to test for the DONE toplevel keyword + + ;; TODO this seems error-prone + "active (singleton...???)" + ("* TODO project") + => :stuck + + "active (subtask)" + ("* TODO project" + "** NEXT task") + => :active + + "wait (subtask)" + ("* TODO project" + "** WAIT task") + => :wait + + "held (subtask)" + ("* TODO project" + "** HOLD task") + => :held + + "inert (subtask)" + ("* TODO project" + "** TODO task" + ":PROPERTIES:" + ":CREATED: %(org-x-gen-ts (- (* (1+ org-x-inert-delay-days) 24 60 60)))%" + ":END:") + => :inert + + "undone-complete (subtask)" + ("* TODO project" + "** DONE TASK" + "CLOSED: (org-x-gen-ts 0)") + => :undone-complete + + "stuck (subtask)" + ("* TODO project" + "** TODO TASK") + => :stuck + + "active (subtask 2)" + ("* TODO project" + "** TODO task 1 " + "*** NEXT task 2") + => :active + + "wait (subtask 2)" + ("* TODO project" + "** TODO task 1 " + "*** WAIT task 2") + => :wait + + "held (subtask 2)" + ("* TODO project" + "** TODO task 1" + "*** HOLD task 2") + => :held + + "inert (subtask 2)" + ("* TODO project" + "** TODO task 1" + "*** TODO task 2" + ":PROPERTIES:" + ":CREATED: %(org-x-gen-ts (- (* (1+ org-x-inert-delay-days) 24 60 60)))%" + ":END:") + => :inert + + "undone-complete (subtask 2)" + ("* TODO project" + "** TODO task 1" + "*** DONE task 2" + "CLOSED: (org-x-gen-ts 0)") + => :undone-complete + + "stuck (subtask 2)" + ("* TODO project" + "** TODO task 1" + "*** TODO task 2") + => :stuck) + (provide 'org-x-test-buffer-state) ;;; org-x-test-buffer-state.el ends here diff --git a/local/lib/org-x/test/org-x-test-common.el b/local/lib/org-x/test/org-x-test-common.el index 4d576e5..4abc81b 100644 --- a/local/lib/org-x/test/org-x-test-common.el +++ b/local/lib/org-x/test/org-x-test-common.el @@ -27,7 +27,10 @@ (defmacro org-ml--with-org-env (&rest body) "Execute BODY in a standardized Org-mode buffer." `(let ((org-tags-column 20) - (org-todo-keywords '((sequence "TODO" "DONE"))) + (org-todo-keywords + ;; shamelessly copies from me + '((sequence "TODO(t/!)" "NEXT(n/!)" "|" "DONE(d/!)") + (sequence "WAIT(w@/!)" "HOLD(h@/!)" "|" "CANC(c@/!)"))) (org-archive-tag "ARCHIVE") (org-lowest-priority ?C) (org-highest-priority ?A)