From b890687ec6732eaf90d4aa03c6ab450504a5988a Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Sun, 29 Dec 2024 00:48:35 -0800 Subject: [PATCH 1/2] org-datetree: Add unit tests for incorrect sorting * testing/lisp/test-org-datetree.el (test-org-datetree/find-date-create): Add test that a subtree is inserted in the correct location, even if there exists another subtree that looks like a datetree. (test-org-datetree/find-iso-week-create): Add test that days within a week spanning 2 years are sorted correctly. --- testing/lisp/test-org-datetree.el | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/testing/lisp/test-org-datetree.el b/testing/lisp/test-org-datetree.el index bd06462f2..620a916df 100644 --- a/testing/lisp/test-org-datetree.el +++ b/testing/lisp/test-org-datetree.el @@ -108,6 +108,30 @@ (ert-deftest test-org-datetree/find-date-create () (let ((org-datetree-add-timestamp nil)) (org-datetree-find-date-create '(3 29 2012))) (org-trim (buffer-string))))) + ;; Insert at correct location, even if some other heading has a + ;; subtree that looks like a datetree + (should + (string-match + "\\`\\* Dummy heading + +\\*\\* 2012 + +\\* 2012 + +\\*\\* 2012-03 March + +\\*\\*\\* 2012-03-29 .*\\'" + (org-test-with-temp-text "\ +* Dummy heading + +** 2012 + +* 2012 + +** 2012-03 March" + (let ((org-datetree-add-timestamp nil)) + (org-datetree-find-date-create '(3 29 2012))) + (org-trim (buffer-string))))) ;; Always leave point at beginning of day entry. (should (string-match @@ -188,6 +212,21 @@ (ert-deftest test-org-datetree/find-iso-week-create () (org-datetree-find-iso-week-create '(9 1 2015)) (org-datetree-find-iso-week-create '(12 31 2014))) (org-trim (buffer-string))))) + ;; Sort new entry in correct order within its week when + ;; iso-week-year is not calendar year + (should + (string-match + "\\`\\* 2015 + +\\*\\* 2015-W01 + +\\*\\*\\* 2014-12-31 .* +\\*\\*\\* 2015-01-01 .*" + (org-test-with-temp-text "* 2015" + (let ((org-datetree-add-timestamp nil)) + (org-datetree-find-iso-week-create '(1 1 2015)) + (org-datetree-find-iso-week-create '(12 31 2014))) + (org-trim (buffer-string))))) ;; When `org-datetree-add-timestamp' is non-nil, insert a timestamp ;; in entry. When set to `inactive', insert an inactive one. (should -- 2.47.1