|
@@ -18,8 +18,6 @@
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
-;;; Comments:
|
|
|
-
|
|
|
;; Template test file for Org tests
|
|
|
|
|
|
;;; Code:
|
|
@@ -5244,9 +5242,224 @@ Paragraph<point>"
|
|
|
"* T<point>est :foo:bar:"
|
|
|
(org-get-tags-at)))))
|
|
|
|
|
|
+
|
|
|
+;;; TODO keywords
|
|
|
+
|
|
|
+(ert-deftest test-org/auto-repeat-maybe ()
|
|
|
+ "Test `org-auto-repeat-maybe' specifications."
|
|
|
+ ;; Do not auto repeat when there is no valid time stamp with
|
|
|
+ ;; a repeater in the entry.
|
|
|
+ (should-not
|
|
|
+ (string-prefix-p
|
|
|
+ "* TODO H"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ (should-not
|
|
|
+ (string-prefix-p
|
|
|
+ "* TODO H"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ ;; When switching to DONE state, switch back to first TODO keyword
|
|
|
+ ;; in sequence, or the same keyword if they have different types.
|
|
|
+ (should
|
|
|
+ (string-prefix-p
|
|
|
+ "* TODO H"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ (should
|
|
|
+ (string-prefix-p
|
|
|
+ "* KWD1 H"
|
|
|
+ (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
|
|
|
+ (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ (should
|
|
|
+ (string-prefix-p
|
|
|
+ "* KWD2 H"
|
|
|
+ (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
|
|
|
+ (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ ;; If there was no TODO keyword in the first place, do not insert
|
|
|
+ ;; any either.
|
|
|
+ (should
|
|
|
+ (string-prefix-p
|
|
|
+ "* H"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ ;; Revert to REPEAT_TO_STATE, if set.
|
|
|
+ (should
|
|
|
+ (string-prefix-p
|
|
|
+ "* KWD2 H"
|
|
|
+ (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "* KWD2 H
|
|
|
+:PROPERTIES:
|
|
|
+:REPEAT_TO_STATE: KWD2
|
|
|
+:END:
|
|
|
+<2012-03-29 Thu +2y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ ;; When switching to DONE state, update base date. If there are
|
|
|
+ ;; multiple repeated time stamps, update them all.
|
|
|
+ (should
|
|
|
+ (string-match-p
|
|
|
+ "<2014-03-29 .* \\+2y>"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ (should
|
|
|
+ (string-match-p
|
|
|
+ "<2015-03-04 .* \\+1y>"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ ;; Throw an error if repeater unit is the hour and no time is
|
|
|
+ ;; provided in the time-stamp.
|
|
|
+ (should-error
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string))))
|
|
|
+ ;; Do not repeat commented time stamps.
|
|
|
+ (should-not
|
|
|
+ (string-prefix-p
|
|
|
+ "<2015-03-04 .* \\+1y>"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ (should-not
|
|
|
+ (string-prefix-p
|
|
|
+ "<2015-03-04 .* \\+1y>"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "* TODO H
|
|
|
+<2012-03-29 Thu. +2y>
|
|
|
+#+BEGIN_EXAMPLE
|
|
|
+<2014-03-04 Tue +1y>
|
|
|
+#+END_EXAMPLE"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string)))))
|
|
|
+ ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
|
|
|
+ ;; entry, record time of last repeat.
|
|
|
+ (should-not
|
|
|
+ (string-match-p
|
|
|
+ ":LAST_REPEAT:"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE")))
|
|
|
+ (org-log-repeat nil))
|
|
|
+ (cl-letf (((symbol-function 'org-add-log-setup)
|
|
|
+ (lambda (&rest args) nil)))
|
|
|
+ (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string))))))
|
|
|
+ (should
|
|
|
+ (string-match-p
|
|
|
+ ":LAST_REPEAT:"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE")))
|
|
|
+ (org-log-repeat t))
|
|
|
+ (cl-letf (((symbol-function 'org-add-log-setup)
|
|
|
+ (lambda (&rest args) nil)))
|
|
|
+ (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string))))))
|
|
|
+ (should
|
|
|
+ (string-match-p
|
|
|
+ ":LAST_REPEAT:"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (cl-letf (((symbol-function 'org-add-log-setup)
|
|
|
+ (lambda (&rest args) nil)))
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "* TODO H\n<2012-03-29 Thu. +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string))))))
|
|
|
+ ;; When a SCHEDULED entry has no repeater, remove it upon repeating
|
|
|
+ ;; the entry as it is no longer relevant.
|
|
|
+ (should-not
|
|
|
+ (string-match-p
|
|
|
+ "^SCHEDULED:"
|
|
|
+ (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
|
|
|
+ (org-todo "DONE")
|
|
|
+ (buffer-string))))))
|
|
|
+
|
|
|
|
|
|
;;; Timestamps API
|
|
|
|
|
|
+(ert-deftest test-org/at-timestamp-p ()
|
|
|
+ "Test `org-at-timestamp-p' specifications."
|
|
|
+ (should
|
|
|
+ (org-test-with-temp-text "<2012-03-29 Thu>"
|
|
|
+ (org-at-timestamp-p)))
|
|
|
+ (should-not
|
|
|
+ (org-test-with-temp-text "2012-03-29 Thu"
|
|
|
+ (org-at-timestamp-p)))
|
|
|
+ ;; Test return values.
|
|
|
+ (should
|
|
|
+ (eq 'bracket
|
|
|
+ (org-test-with-temp-text "<2012-03-29 Thu>"
|
|
|
+ (org-at-timestamp-p))))
|
|
|
+ (should
|
|
|
+ (eq 'year
|
|
|
+ (org-test-with-temp-text "<<point>2012-03-29 Thu>"
|
|
|
+ (org-at-timestamp-p))))
|
|
|
+ (should
|
|
|
+ (eq 'month
|
|
|
+ (org-test-with-temp-text "<2012-<point>03-29 Thu>"
|
|
|
+ (org-at-timestamp-p))))
|
|
|
+ (should
|
|
|
+ (eq 'day
|
|
|
+ (org-test-with-temp-text "<2012-03-<point>29 Thu>"
|
|
|
+ (org-at-timestamp-p))))
|
|
|
+ (should
|
|
|
+ (eq 'day
|
|
|
+ (org-test-with-temp-text "<2012-03-29 T<point>hu>"
|
|
|
+ (org-at-timestamp-p))))
|
|
|
+ (should
|
|
|
+ (wholenump
|
|
|
+ (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
|
|
|
+ (org-at-timestamp-p))))
|
|
|
+ (should
|
|
|
+ (eq 'bracket
|
|
|
+ (org-test-with-temp-text "<2012-03-29 Thu<point>>"
|
|
|
+ (org-at-timestamp-p))))
|
|
|
+ (should
|
|
|
+ (eq 'after
|
|
|
+ (org-test-with-temp-text "<2012-03-29 Thu><point>»"
|
|
|
+ (org-at-timestamp-p))))
|
|
|
+ ;; Test optional argument.
|
|
|
+ (should
|
|
|
+ (org-test-with-temp-text "[2012-03-29 Thu]"
|
|
|
+ (org-at-timestamp-p t)))
|
|
|
+ (should-not
|
|
|
+ (org-test-with-temp-text "[2012-03-29 Thu]"
|
|
|
+ (org-at-timestamp-p)))
|
|
|
+ ;; Unlike `org-element-context', recognize time-stamps in planning
|
|
|
+ ;; info line, property drawers and clocks.
|
|
|
+ (should
|
|
|
+ (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
|
|
|
+ (org-at-timestamp-p)))
|
|
|
+ (should
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
|
|
|
+ (org-at-timestamp-p)))
|
|
|
+ (should
|
|
|
+ (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
|
|
|
+ (org-at-timestamp-p t))))
|
|
|
+
|
|
|
(ert-deftest test-org/time-stamp ()
|
|
|
"Test `org-time-stamp' specifications."
|
|
|
;; Insert chosen time stamp at point.
|