From d17e33802b0e53af131a2ab3f44d9ee3ecfb2a59 Mon Sep 17 00:00:00 2001 From: Ruijie Yu Date: Sat, 22 Apr 2023 20:36:18 +0800 Subject: [PATCH] [DRAFT] Fix dependence on locale in org testing facilities * testing/org-test.el org-test-day-of-weeks-seconds: add values of seconds that yield different days of week (by trial-and-error). org-test-day-of-weeks-abbrev: add a vector of abbreviated DoW names for testing. org-test-day-of-weeks-full: add a vector of full DoW names for testing. * testing/lisp/test-org-clock.el (test-org-clock/clock-drawer-dwim): make use of the pre-generated DoW names in the testing to remove assumptions on LANG=C. (test-org-clock/org-clock-timestamps-change): renamed from test-org-clok/org-clock-timestamps-change; used DoW pre-generated names. * testing/lisp/test-org.el (org-test-with-result): (org-test-without-dow): add two macros to combat the 40-time repetition of "do not add day-of-week, do something, and return buffer string". (test-org/clone-with-time-shift): (test-org/add-planning-info): (test-org/deadline): (test-org/schedule): rewrite the day-of-week-removal portion to avoid generating day-of-week names altogether, using the new macro `org-test-without-dow'. --- testing/lisp/test-org-clock.el | 64 ++--- testing/lisp/test-org.el | 415 +++++++++++++++------------------ testing/org-test.el | 25 ++ 3 files changed, 250 insertions(+), 254 deletions(-) diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el index 7d8123e1f..d4beb76e0 100644 --- a/testing/lisp/test-org-clock.el +++ b/testing/lisp/test-org-clock.el @@ -89,29 +89,34 @@ the buffer." ;; Remove clocktable. (delete-region (point) (search-forward "#+END:\n")))) -(ert-deftest test-org-clok/org-clock-timestamps-change () +(ert-deftest test-org-clock/org-clock-timestamps-change () "Test `org-clock-timestamps-change' specifications." - (should - (equal - "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19 Sun 23:35] => 2:05" - (org-test-with-temp-text - "CLOCK: [2023-02-19 Sun 22:30]--[2023-02-20 Mon 00:35] => 2:05" - (org-clock-timestamps-change 'down 1) - (buffer-string)))) - (should - (equal - "CLOCK: [2023-02-20 Mon 00:00]--[2023-02-20 Mon 00:40] => 0:40" - (org-test-with-temp-text - "CLOCK: [2023-02-19 Sun 23:55]--[2023-02-20 Mon 00:35] => 0:40" - (org-clock-timestamps-change 'up 1) - (buffer-string)))) - (should - (equal - "CLOCK: [2023-02-20 Mon 00:30]--[2023-02-20 Mon 01:35] => 1:05" - (org-test-with-temp-text - "CLOCK: [2023-02-19 Sun 23:30]--[2023-02-20 Mon 00:35] => 1:05" - (org-clock-timestamps-change 'up 1) - (buffer-string))))) + (let ((sun (aref org-test-day-of-weeks-abbrev 0)) + (mon (aref org-test-day-of-weeks-abbrev 1))) + (should + (equal + (format "CLOCK: [2023-02-19 %s 21:30]--[2023-02-19 %s 23:35] => 2:05" + sun sun) + (org-test-with-temp-text + "CLOCK: [2023-02-19 Sun 22:30]--[2023-02-20 Mon 00:35] => 2:05" + (org-clock-timestamps-change 'down 1) + (buffer-string)))) + (should + (equal + (format "CLOCK: [2023-02-20 %s 00:00]--[2023-02-20 %s 00:40] => 0:40" + mon mon) + (org-test-with-temp-text + "CLOCK: [2023-02-19 Sun 23:55]--[2023-02-20 Mon 00:35] => 0:40" + (org-clock-timestamps-change 'up 1) + (buffer-string)))) + (should + (equal + (format "CLOCK: [2023-02-20 %s 00:30]--[2023-02-20 %s 01:35] => 1:05" + mon mon) + (org-test-with-temp-text + "CLOCK: [2023-02-19 Sun 23:30]--[2023-02-20 Mon 00:35] => 1:05" + (org-clock-timestamps-change 'up 1) + (buffer-string)))))) ;;; Clock drawer @@ -299,19 +304,20 @@ the buffer." (ert-deftest test-org-clock/clock-drawer-dwim () "Test DWIM update of days for clocks in logbook drawers." - (should (equal "* Foo + (let ((thu (aref org-test-day-of-weeks-abbrev 4))) + (should (equal (format "* Foo :LOGBOOK: -CLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] => 0:01 +CLOCK: [2022-11-03 %s 06:00]--[2022-11-03 %s 06:01] => 0:01 :END: -" - (org-test-with-temp-text - "* Foo +" thu thu) + (org-test-with-temp-text + "* Foo :LOGBOOK: CLOCK: [2022-11-03 ??? 06:00]--[2022-11-03 ??? 06:01] => 0:01 :END: " - (org-ctrl-c-ctrl-c) - (buffer-string))))) + (org-ctrl-c-ctrl-c) + (buffer-string)))))) ;;; Clocktable diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index d7c801fe5..e5581f140 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -43,6 +43,40 @@ ,@body) (setenv "TZ" ,tz-saved))))) +(defmacro org-test-with-result (result &rest body) + "Evaluate BODY, and return buffer content based on RESULT. +RESULT is an sexp, and is processed according to the following +rules. + +If RESULT is the quoted symbol `buffer', return buffer string. + +If RESULT is the quoted symbol `buffer-no-properties', return +buffer string with no properties. + +If RESULT is a positive integer, return the RESULT-th line of the +buffer. + +Otherwise, evaluate RESULT as an sexp and return its result." + (declare (indent 1)) + `(progn ,@body + ,(pcase result + (''buffer-no-properties + '(buffer-substring-no-properties + (point-min) (point-max))) + (''buffer '(buffer-string)) + ((and (pred numberp) (pred cl-plusp)) + `(buffer-substring (line-beginning-position ,result) + (line-end-position ,result))) + (_ result)))) + +(defmacro org-test-without-dow (result &rest body) + "Eval BODY skipping day-of-week in timestamps. +See `org-test-with-result' for RESULT and the return value." + (declare (indent 1)) + `(let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M"))) + ;; ,(macroexpand-1 `(org-test-with-result ,result ,@body)) + (org-test-with-result ,result ,@body))) + ;;; Comments @@ -2013,11 +2047,9 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46" * H1\n<2015-06-21> * H1\n<2015-06-23> " - (org-test-with-temp-text "* H1\n<2015-06-21 Sun>" - (org-clone-subtree-with-time-shift 1 "+2d") - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string) - nil nil 1)))) + (org-test-with-temp-text "* H1\n<2015-06-21>" + (org-test-without-dow 'buffer + (org-clone-subtree-with-time-shift 1 "+2d"))))) ;; Clone repeating once. (should (equal "\ @@ -2025,11 +2057,9 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46" * H1\n<2015-06-23> * H1\n<2015-06-25 +1w> " - (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>" - (org-clone-subtree-with-time-shift 1 "+2d") - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string) - nil nil 1)))) + (org-test-with-temp-text "* H1\n<2015-06-21 +1w>" + (org-test-without-dow 'buffer + (org-clone-subtree-with-time-shift 1 "+2d"))))) ;; Clone repeating once in backward. (should (equal "\ @@ -2037,58 +2067,49 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46" * H1\n<2015-06-19> * H1\n<2015-06-17 +1w> " - (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>" - (org-clone-subtree-with-time-shift 1 "-2d") - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string) - nil nil 1)))) + (org-test-with-temp-text "* H1\n<2015-06-21 +1w>" + (org-test-without-dow 'buffer + (org-clone-subtree-with-time-shift 1 "-2d"))))) ;; Clone non-repeating zero times. (should (equal "\ * H1\n<2015-06-21> " - (org-test-with-temp-text "* H1\n<2015-06-21 Sun>" - (org-clone-subtree-with-time-shift 0 "+2d") - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string) - nil nil 1)))) + (org-test-with-temp-text "* H1\n<2015-06-21>" + (org-test-without-dow 'buffer + (org-clone-subtree-with-time-shift 0 "+2d"))))) ;; Clone repeating "zero" times. (should (equal "\ * H1\n<2015-06-21> * H1\n<2015-06-23 +1w> " - (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>" - (org-clone-subtree-with-time-shift 0 "+2d") - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string) - nil nil 1)))) + (org-test-with-temp-text "* H1\n<2015-06-21 +1w>" + (org-test-without-dow 'buffer + (org-clone-subtree-with-time-shift 0 "+2d"))))) ;; Clone with blank SHIFT argument. (should (string-prefix-p "* H <2012-03-29" (org-test-with-temp-text "* H <2012-03-29 Thu>" - (org-clone-subtree-with-time-shift 1 "") - (buffer-substring-no-properties (line-beginning-position 2) - (line-end-position 2))))) + (org-test-without-dow 2 + (org-clone-subtree-with-time-shift 1 ""))))) ;; Find time stamps before point. If SHIFT is not specified, ask ;; for a time shift. (should (string-prefix-p "* H <2012-03-30" (org-test-with-temp-text "* H <2012-03-29 Thu>" - (org-clone-subtree-with-time-shift 1 "+1d") - (buffer-substring-no-properties (line-beginning-position 2) - (line-end-position 2))))) + (org-test-without-dow 2 + (org-clone-subtree-with-time-shift 1 "+1d"))))) (should (string-prefix-p "* H <2014-03-05" (org-test-with-temp-text "* H <2014-03-04 Tue>" (cl-letf (((symbol-function 'read-from-minibuffer) - (lambda (&rest _args) "+1d"))) - (org-clone-subtree-with-time-shift 1)) - (buffer-substring-no-properties (line-beginning-position 2) - (line-end-position 2))))) + (lambda (&rest _args) "+1d"))) + (org-test-without-dow 2 + (org-clone-subtree-with-time-shift 1)))))) ;; Hour shift. (should (equal "\ @@ -2096,23 +2117,17 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46" * H1\n<2015-06-21 23:00> * H1\n<2015-06-22 02:00> " - (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>" - (org-clone-subtree-with-time-shift 2 "+3h") - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" "" - (buffer-substring-no-properties (point-min) (point-max)) - nil nil 1)))) + (org-test-with-temp-text "* H1\n<2015-06-21 20:00>" + (org-test-without-dow 'buffer + (org-clone-subtree-with-time-shift 2 "+3h"))))) (should (equal "\ * H1\n<2015-06-21 20:00> * H1\n<2015-06-21 18:00> " - (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>" - (org-clone-subtree-with-time-shift 1 "-2h") - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" "" - (buffer-substring-no-properties (point-min) (point-max)) - nil nil 1))))) + (org-test-with-temp-text "* H1\n<2015-06-21 20:00>" + (org-test-without-dow 'buffer + (org-clone-subtree-with-time-shift 1 "-2h")))))) ;;; Fixed-Width Areas @@ -5626,21 +5641,17 @@ Text. ;; Create deadline when `org-adapt-indentation' is non-nil. (should (equal "* H\n DEADLINE: <2015-06-25>\nParagraph" - (org-test-with-temp-text "* H\nParagraph" - (let ((org-adapt-indentation t)) - (org-add-planning-info 'deadline "<2015-06-25 Thu>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-with-temp-text "* H\nParagraph" + (let ((org-adapt-indentation t)) + (org-test-without-dow 'buffer + (org-add-planning-info 'deadline "<2015-06-25 Thu>")))))) ;; Create deadline when `org-adapt-indentation' is nil. (should (equal "* H\nDEADLINE: <2015-06-25>\nParagraph" (org-test-with-temp-text "* H\nParagraph" (let ((org-adapt-indentation nil)) - (org-add-planning-info 'deadline "<2015-06-25 Thu>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info 'deadline "<2015-06-25 Thu>")))))) ;; Update deadline when `org-adapt-indentation' is non-nil. (should (equal "* H\n DEADLINE: <2015-06-25>\nParagraph" @@ -5649,10 +5660,8 @@ Text. DEADLINE: <2015-06-24 Wed> Paragraph" (let ((org-adapt-indentation t)) - (org-add-planning-info 'deadline "<2015-06-25 Thu>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info 'deadline "<2015-06-25 Thu>")))))) ;; Update deadline when `org-adapt-indentation' is nil. (should (equal "* H\nDEADLINE: <2015-06-25>\nParagraph" @@ -5661,28 +5670,22 @@ Paragraph" DEADLINE: <2015-06-24 Wed> Paragraph" (let ((org-adapt-indentation nil)) - (org-add-planning-info 'deadline "<2015-06-25 Thu>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info 'deadline "<2015-06-25 Thu>")))))) ;; Schedule when `org-adapt-indentation' is non-nil. (should (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph" (org-test-with-temp-text "* H\nParagraph" (let ((org-adapt-indentation t)) - (org-add-planning-info 'scheduled "<2015-06-25 Thu>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info 'scheduled "<2015-06-25 Thu>")))))) ;; Schedule when `org-adapt-indentation' is nil. (should (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph" (org-test-with-temp-text "* H\nParagraph" (let ((org-adapt-indentation nil)) - (org-add-planning-info 'scheduled "<2015-06-25 Thu>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info 'scheduled "<2015-06-25 Thu>")))))) ;; Add deadline when scheduled. (should (equal "\ @@ -5691,13 +5694,11 @@ Paragraph" Paragraph" (org-test-with-temp-text "\ * H - SCHEDULED: <2015-06-24 Wed> + SCHEDULED: <2015-06-24> Paragraph" (let ((org-adapt-indentation t)) - (org-add-planning-info 'deadline "<2015-06-25 Thu>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info 'deadline "<2015-06-25 Thu>")))))) ;; Remove middle entry. (should (equal "\ @@ -5706,13 +5707,11 @@ Paragraph" Paragraph" (org-test-with-temp-text "\ * H - CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed> + CLOSED: [2015-06-24] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24> Paragraph" (let ((org-adapt-indentation t)) - (org-add-planning-info nil nil 'deadline)) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info nil nil 'deadline)))))) ;; Remove last entry and then middle entry (order should not ;; matter). (should @@ -5722,25 +5721,21 @@ Paragraph" Paragraph" (org-test-with-temp-text "\ * H - CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed> + CLOSED: [2015-06-24] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed> Paragraph" (let ((org-adapt-indentation t)) - (org-add-planning-info nil nil 'scheduled 'deadline)) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info nil nil 'scheduled 'deadline)))))) ;; Remove closed when `org-adapt-indentation' is non-nil. (should (equal "* H\n DEADLINE: <2015-06-25>\nParagraph" (org-test-with-temp-text "\ * H - CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu> + CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25> Paragraph" (let ((org-adapt-indentation t)) - (org-add-planning-info nil nil 'closed)) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info nil nil 'closed)))))) (should (equal "* H\n Paragraph" (org-test-with-temp-text "\ @@ -5748,22 +5743,18 @@ Paragraph" CLOSED: [2015-06-25 Thu] Paragraph" (let ((org-adapt-indentation t)) - (org-add-planning-info nil nil 'closed)) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info nil nil 'closed)))))) ;; Remove closed when `org-adapt-indentation' is nil. (should (equal "* H\nDEADLINE: <2015-06-25>\nParagraph" (org-test-with-temp-text "\ * H -CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu> +CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25> Paragraph" (let ((org-adapt-indentation nil)) - (org-add-planning-info nil nil 'closed)) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info nil nil 'closed)))))) (should (equal "* H\nParagraph" (org-test-with-temp-text "\ @@ -5771,10 +5762,8 @@ Paragraph" CLOSED: [2015-06-25 Thu] Paragraph" (let ((org-adapt-indentation nil)) - (org-add-planning-info nil nil 'closed)) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info nil nil 'closed)))))) ;; Remove closed entry and delete empty line. (should (equal "\ @@ -5785,10 +5774,8 @@ Paragraph" CLOSED: [2015-06-24 Wed] Paragraph" (let ((org-adapt-indentation t)) - (org-add-planning-info nil nil 'closed)) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-add-planning-info nil nil 'closed)))))) ;; Remove one entry and update another. (should (equal "* H\n DEADLINE: <2015-06-25>\nParagraph" @@ -5797,10 +5784,8 @@ Paragraph" SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed> Paragraph" (let ((org-adapt-indentation t)) - (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled)) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1))))) + (org-test-without-dow 'buffer + (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))))))) (ert-deftest test-org/deadline () "Test `org-deadline' specifications." @@ -5810,19 +5795,15 @@ Paragraph" (org-test-with-temp-text "* H" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) - (org-deadline nil "<2012-03-29 Tue>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-deadline nil "<2012-03-29 Tue>")))))) (should (equal "* H\nDEADLINE: <2014-03-04>" (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) - (org-deadline nil "<2014-03-04 Thu>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-without-dow 'buffer + (org-deadline nil "<2014-03-04 Thu>")))))) ;; Accept delta time, e.g., "+2d". (should (equal "* H\nDEADLINE: <2015-03-04>" @@ -5830,44 +5811,39 @@ Paragraph" (org-test-with-temp-text "* H" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) - (org-deadline nil "+1y")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))) + (org-test-without-dow 'buffer + (org-deadline nil "+1y"))))))) ;; Preserve repeater. (should (equal "* H\nDEADLINE: <2012-03-29 +2y>" (org-test-with-temp-text "* H" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) - (org-deadline nil "<2012-03-29 Tue +2y>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1)))) + (org-test-without-dow 'buffer + (org-deadline nil "<2012-03-29 Tue +2y>")))))) ;; Preserve warning period. (should (equal "* H\nDEADLINE: <2021-07-20 -1d>" (org-test-with-temp-text "* H" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) - (org-deadline nil "<2021-07-20 Tue -1d>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1)))) + (org-test-without-dow 'buffer + (org-deadline nil "<2021-07-20 Tue -1d>")))))) (should (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>" (org-test-with-temp-text "* H" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) - (org-deadline nil "<2021-07-20 Tue +1m -3d>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1)))) + (org-test-without-dow 'buffer + (org-deadline nil "<2021-07-20 Tue +1m -3d>")))))) ;; Remove CLOSED keyword, if any. (should (equal "* H\nDEADLINE: <2012-03-29>" (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) - (org-deadline nil "<2012-03-29 Tue>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))) + (org-test-without-dow 'buffer + (org-deadline nil "<2012-03-29 Tue>")))))) ;; With C-u argument, remove DEADLINE keyword. (should (equal "* H\n" @@ -5912,12 +5888,11 @@ Paragraph" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil) (org-loop-over-headlines-in-active-region t)) - (transient-mark-mode 1) + (transient-mark-mode 1) (push-mark (point) t t) (goto-char (point-max)) - (org-deadline nil "2012-03-29")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))) + (org-test-without-dow 'buffer + (org-deadline nil "2012-03-29")))))) (should-not (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>" (org-test-with-temp-text "* H1\n* H2" @@ -5927,130 +5902,120 @@ Paragraph" (transient-mark-mode 1) (push-mark (point) t t) (goto-char (point-max)) - (org-deadline nil "2012-03-29")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))) + (org-test-without-dow 'buffer + (org-deadline nil "2012-03-29"))))))) (ert-deftest test-org/schedule () "Test `org-schedule' specifications." ;; Insert a new value or replace existing one. (should (equal "* H\nSCHEDULED: <2012-03-29>" - (org-test-with-temp-text "* H" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule nil "<2012-03-29 Tue>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-with-temp-text "* H" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil)) + (org-test-without-dow 'buffer + (org-schedule nil "<2012-03-29 Tue>")))))) (should (equal "* H\nSCHEDULED: <2014-03-04>" - (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule nil "<2014-03-04 Thu>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) - nil nil 1)))) + (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil)) + (org-test-without-dow 'buffer + (org-schedule nil "<2014-03-04 Thu>")))))) ;; Accept delta time, e.g., "+2d". (should (equal "* H\nSCHEDULED: <2015-03-04>" - (org-test-at-time "2014-03-04" - (org-test-with-temp-text "* H" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule nil "+1y")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))) + (org-test-at-time "2014-03-04" + (org-test-with-temp-text "* H" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil)) + (org-test-without-dow 'buffer + (org-schedule nil "+1y"))))))) ;; Preserve repeater. (should (equal "* H\nSCHEDULED: <2012-03-29 +2y>" - (org-test-with-temp-text "* H" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule nil "<2012-03-29 Tue +2y>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1)))) + (org-test-with-temp-text "* H" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil)) + (org-test-without-dow 'buffer + (org-schedule nil "<2012-03-29 Tue +2y>")))))) ;; Remove CLOSED keyword, if any. (should (equal "* H\nSCHEDULED: <2012-03-29>" - (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule nil "<2012-03-29 Tue>")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))) + (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil)) + (org-test-without-dow 'buffer + (org-schedule nil "<2012-03-29 Tue>")))))) ;; With C-u argument, remove SCHEDULED keyword. (should (equal "* H\n" - (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule '(4))) - (buffer-string)))) + (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil)) + (org-schedule '(4))) + (buffer-string)))) (should (equal "* H" - (org-test-with-temp-text "* H" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule '(4))) - (buffer-string)))) + (org-test-with-temp-text "* H" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil)) + (org-schedule '(4))) + (buffer-string)))) ;; With C-u C-u argument, prompt for a delay cookie. (should (equal "* H\nSCHEDULED: <2012-03-29 -705d>" - (cl-letf (((symbol-function 'org-read-date) - (lambda (&rest _args) - (org-time-string-to-time "2014-03-04")))) - (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule '(16))) - (buffer-string))))) + (cl-letf (((symbol-function 'org-read-date) + (lambda (&rest _args) + (org-time-string-to-time "2014-03-04")))) + (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil)) + (org-schedule '(16))) + (buffer-string))))) (should-error (cl-letf (((symbol-function 'org-read-date) - (lambda (&rest _args) - (org-time-string-to-time "2014-03-04")))) + (lambda (&rest _args) + (org-time-string-to-time "2014-03-04")))) (org-test-with-temp-text "* H" (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule '(16))) + (org-last-inserted-timestamp nil)) + (org-schedule '(16))) (buffer-string)))) ;; When a region is active and ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the ;; same value in all headlines in region. (should (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>" - (org-test-with-temp-text "* H1\n* H2" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil) - (org-loop-over-headlines-in-active-region t)) - (transient-mark-mode 1) - (push-mark (point) t t) - (goto-char (point-max)) - (org-schedule nil "2012-03-29")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))) + (org-test-with-temp-text "* H1\n* H2" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil) + (org-loop-over-headlines-in-active-region t)) + (transient-mark-mode 1) + (push-mark (point) t t) + (goto-char (point-max)) + (org-test-without-dow 'buffer + (org-schedule nil "2012-03-29")))))) (should-not (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>" - (org-test-with-temp-text "* H1\n* H2" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil) - (org-loop-over-headlines-in-active-region nil)) - (transient-mark-mode 1) - (push-mark (point) t t) - (goto-char (point-max)) - (org-schedule nil "2012-03-29")) - (replace-regexp-in-string - "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))) + (org-test-with-temp-text "* H1\n* H2" + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil) + (org-loop-over-headlines-in-active-region nil)) + (transient-mark-mode 1) + (push-mark (point) t t) + (goto-char (point-max)) + (org-test-without-dow 'buffer + (org-schedule nil "2012-03-29")))))) (should ;; check if a repeater survives re-scheduling. - (string-match-p - "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n" + (equal + "* H\nSCHEDULED: <2017-02-01 ++7d>\n" (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n" - (let ((org-adapt-indentation nil) - (org-last-inserted-timestamp nil)) - (org-schedule nil "2017-02-01")) - (buffer-string))))) + (let ((org-adapt-indentation nil) + (org-last-inserted-timestamp nil)) + (org-test-without-dow 'buffer + (org-schedule nil "2017-02-01"))))))) ;;; Property API diff --git a/testing/org-test.el b/testing/org-test.el index 22ac60670..ced281e23 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -547,6 +547,31 @@ TIME can be a non-nil Lisp time value, or a string specifying a date and time." ,@body) (nreverse messages))) +(defconst org-test-day-of-weeks-seconds + [121223891 ; Sun + 30000000 ; Mon + 2222222 ; Tue + 500000 ; Wed + 1000 ; Thu + 89173 ; Fri + 666666666] ; Sat + "Epoch seconds for generating days of week strings. +Starts at Sunday, ends at Saturday.") + +(defconst org-test-day-of-weeks-abbrev + (apply #'vector + (seq-map (apply-partially #'format-time-string "%a") + org-test-day-of-weeks-seconds)) + "Vector of abbreviated names of days of week. +See `org-test-day-of-weeks-seconds'.") + +(defconst org-test-day-of-weeks-full + (apply #'vector + (seq-map (apply-partially #'format-time-string "%A") + org-test-day-of-weeks-seconds)) + "Vector of full names for days of week. +See `org-test-day-of-weeks-seconds'.") + (provide 'org-test) ;;; org-test.el ends here -- 2.40.0