ADD tests for project status

This commit is contained in:
Nathan Dwarshuis 2021-04-06 23:16:51 -04:00
parent f000e0df23
commit b2c295f0fd
2 changed files with 188 additions and 2 deletions

View File

@ -53,7 +53,10 @@ Forms are denoted like %(FORM)%."
"Call `org-ml--with-org-env' with BODY and STRING as the buffer." "Call `org-ml--with-org-env' with BODY and STRING as the buffer."
(let ((s (->> (if (listp string) (s-join "\n" string) string) (let ((s (->> (if (listp string) (s-join "\n" string) string)
(org-x-test-parse-forms)))) (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) (defmacro org-x--test-buffer-strings (name test &rest specs)
"Run TEST form for SPECS called by toplevel NAME." "Run TEST form for SPECS called by toplevel NAME."
@ -152,5 +155,185 @@ Forms are denoted like %(FORM)%."
":END:") ":END:")
=> :active) => :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) (provide 'org-x-test-buffer-state)
;;; org-x-test-buffer-state.el ends here ;;; org-x-test-buffer-state.el ends here

View File

@ -27,7 +27,10 @@
(defmacro org-ml--with-org-env (&rest body) (defmacro org-ml--with-org-env (&rest body)
"Execute BODY in a standardized Org-mode buffer." "Execute BODY in a standardized Org-mode buffer."
`(let ((org-tags-column 20) `(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-archive-tag "ARCHIVE")
(org-lowest-priority ?C) (org-lowest-priority ?C)
(org-highest-priority ?A) (org-highest-priority ?A)