[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org ab9c9732ea 1/7: Fix dependence on locale in org tes
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org ab9c9732ea 1/7: Fix dependence on locale in org testing facilities |
Date: |
Mon, 17 Jul 2023 06:59:26 -0400 (EDT) |
branch: externals/org
commit ab9c9732ea39db5456c0aee789a897dca4c5c839
Author: Ruijie Yu <ruijie@netyu.xyz>
Commit: Ihor Radchenko <yantar92@posteo.net>
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 d40939eb69..19d0c68ecf 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 2<point>2: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:<point>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 2<point>3: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 2<point>2: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:<point>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 2<point>3:30]--[2023-02-20 Mon 00:35] =>
1:05"
+ (org-clock-timestamps-change 'up 1)
+ (buffer-string))))))
(ert-deftest test-org-clok/org-clock-update-time-maybe ()
"Test `org-clock-update-time-maybe' specifications."
@@ -313,19 +318,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:
<point>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 08cda543ad..0886e9348c 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
@@ -2066,11 +2100,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 "\
@@ -2078,11 +2110,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 "\
@@ -2090,58 +2120,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><point>"
- (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><point>"
- (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><point>"
(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 "\
@@ -2149,23 +2170,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
@@ -5703,21 +5718,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<point>"
- (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<point>"
+ (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<point>"
(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"
@@ -5726,10 +5737,8 @@ Text.
DEADLINE: <2015-06-24 Wed>
Paragraph<point>"
(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"
@@ -5738,28 +5747,22 @@ Paragraph<point>"
DEADLINE: <2015-06-24 Wed>
Paragraph<point>"
(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<point>"
(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<point>"
(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 "\
@@ -5768,13 +5771,11 @@ Paragraph<point>"
Paragraph"
(org-test-with-temp-text "\
* H
- SCHEDULED: <2015-06-24 Wed>
+ SCHEDULED: <2015-06-24>
Paragraph<point>"
(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 "\
@@ -5783,13 +5784,11 @@ Paragraph<point>"
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<point>"
(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
@@ -5799,25 +5798,21 @@ Paragraph<point>"
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<point>"
(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<point>"
(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 "\
@@ -5825,22 +5820,18 @@ Paragraph<point>"
CLOSED: [2015-06-25 Thu]
Paragraph<point>"
(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<point>"
(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 "\
@@ -5848,10 +5839,8 @@ Paragraph<point>"
CLOSED: [2015-06-25 Thu]
Paragraph<point>"
(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 "\
@@ -5862,10 +5851,8 @@ Paragraph"
CLOSED: [2015-06-24 Wed]
Paragraph<point>"
(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"
@@ -5874,10 +5861,8 @@ Paragraph<point>"
SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
Paragraph<point>"
(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."
@@ -5887,19 +5872,15 @@ Paragraph<point>"
(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>"
@@ -5907,44 +5888,39 @@ Paragraph<point>"
(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"
@@ -5989,12 +5965,11 @@ Paragraph<point>"
(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"
@@ -6004,130 +5979,120 @@ Paragraph<point>"
(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 22ac606706..ced281e235 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
- [elpa] externals/org updated (a1ef64f3d1 -> 5b6268c29e), ELPA Syncer, 2023/07/17
- [elpa] externals/org ab9c9732ea 1/7: Fix dependence on locale in org testing facilities,
ELPA Syncer <=
- [elpa] externals/org 8739a95782 2/7: Let org-columns correctly detect string-widths in code, ELPA Syncer, 2023/07/17
- [elpa] externals/org 26440689aa 4/7: org-test-without-dow: Make name consistent with what the macro does, ELPA Syncer, 2023/07/17
- [elpa] externals/org c730caf512 5/7: org-babel-result-to-file: Fix when in indirect buffer, ELPA Syncer, 2023/07/17
- [elpa] externals/org 9730f408c2 3/7: testing/org-test.el: New helper function `org-test-get-day-name', ELPA Syncer, 2023/07/17
- [elpa] externals/org 3007511f3f 6/7: org-string-width: Reuse buffer when calculating string width, ELPA Syncer, 2023/07/17
- [elpa] externals/org 5b6268c29e 7/7: org-columns--truncate-below-width: Fix Emacs 27 compatibility, ELPA Syncer, 2023/07/17