* [PATCH] Testing: Add tests for `org-tags-sort-function'
@ 2024-06-15 15:27 Morgan Smith
2024-09-01 13:33 ` Ihor Radchenko
0 siblings, 1 reply; 3+ messages in thread
From: Morgan Smith @ 2024-06-15 15:27 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Morgan Smith
* testing/lisp/test-org-agenda.el (test-org-agenda/tags-sorting): New
test.
---
Hello!
I just recently sent in a patch to add a new possible value for
`org-tags-sort-function'. To ease discussion there, I thought I'd add a nice
little test here so I can later show off the feature I'm trying to add.
Do notice that TODO I put in the comment though. Not sure what the solution to
that should be.
It would be nice to accept this patch even with the TODO so I can make patches
in the other discussion that extend this test. Or I suppose I could try being
patient. That doesn't sound as fun though.
Thanks,
Morgan
testing/lisp/test-org-agenda.el | 49 +++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el
index 778f91e8e..c1092df3b 100644
--- a/testing/lisp/test-org-agenda.el
+++ b/testing/lisp/test-org-agenda.el
@@ -655,6 +655,55 @@ Sunday 7 January 2024
(buffer-string))))))
(org-test-agenda--kill-all-agendas))))
+(ert-deftest test-org-agenda/tags-sorting ()
+ "Test if `org-agenda' sorts tags according to `org-tags-sort-function'."
+ (let ((org-agenda-custom-commands
+ '(("f" "no fluff" todo ""
+ ((org-agenda-todo-keyword-format "")
+ (org-agenda-overriding-header "")
+ (org-agenda-prefix-format "")
+ (org-agenda-remove-tags t)
+ (org-agenda-sorting-strategy '(tag-up))))))
+ ;; Sorting doesn't care about `org-tag-alist'. This is only
+ ;; here for later when we add sorting methods that do
+ (org-tag-alist
+ '((:startgrouptag)
+ ("group_a")
+ (:grouptags)
+ ("tag_a_1")
+ ("tag_a_2")
+ (:endgrouptag)
+ (:startgroup)
+ ("tag_b_1")
+ ("tag_b_2")
+ (:endgroup)
+ ("groupless")
+ ("lonely"))))
+ (org-test-agenda-with-agenda
+ (string-join
+ '("* TODO group_a :group_a:"
+ "* TODO tag_a_1 :tag_a_1:"
+ "* TODO tag_a_2 :tag_a_2:"
+ "* TODO tag_b_1 :tag_b_1:"
+ "* TODO tag_b_2 :tag_b_2:"
+ "* TODO groupless :groupless:"
+ "* TODO lonely :lonely:")
+ "\n")
+ (dolist (org-tags-sort-function '(nil org-string< org-string>))
+ (should
+ (string-equal
+ (progn
+ (org-agenda nil "f")
+ (substring-no-properties (buffer-string)))
+ (pcase org-tags-sort-function
+ ;; TODO: a value of `nil' sorts it! That's not what the
+ ;; customize menu of `org-tags-sort-function' says! It
+ ;; says "No sorting".
+ ((or 'nil 'org-string<)
+ "group_a\ngroupless\nlonely\ntag_a_1\ntag_a_2\ntag_b_1\ntag_b_2\n")
+ ('org-string>
+ "tag_b_2\ntag_b_1\ntag_a_2\ntag_a_1\nlonely\ngroupless\ngroup_a\n"))))))))
+
(ert-deftest test-org-agenda/goto-date ()
"Test `org-agenda-goto-date'."
(unwind-protect
--
2.45.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Testing: Add tests for `org-tags-sort-function'
2024-06-15 15:27 [PATCH] Testing: Add tests for `org-tags-sort-function' Morgan Smith
@ 2024-09-01 13:33 ` Ihor Radchenko
2024-09-02 18:36 ` Morgan Smith
0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2024-09-01 13:33 UTC (permalink / raw)
To: Morgan Smith; +Cc: emacs-orgmode
Morgan Smith <Morgan.J.Smith@outlook.com> writes:
> diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el
> index 778f91e8e..c1092df3b 100644
> --- a/testing/lisp/test-org-agenda.el
> +++ b/testing/lisp/test-org-agenda.el
Thanks for the patch!
> + ;; Sorting doesn't care about `org-tag-alist'. This is only
> + ;; here for later when we add sorting methods that do
> ....
Then, please refrain from setting alist in this patch and add it later,
when testing the relevant methods.
> + (org-test-agenda-with-agenda
> + (string-join
> + '("* TODO group_a :group_a:"
> + "* TODO tag_a_1 :tag_a_1:"
> + "* TODO tag_a_2 :tag_a_2:"
> + "* TODO tag_b_1 :tag_b_1:"
> + "* TODO tag_b_2 :tag_b_2:"
> + "* TODO groupless :groupless:"
> + "* TODO lonely :lonely:")
> + "\n")
> + (dolist (org-tags-sort-function '(nil org-string< org-string>))
> + (should
> + (string-equal
> + (progn
> + (org-agenda nil "f")
> + (substring-no-properties (buffer-string)))
> + (pcase org-tags-sort-function
> + ;; TODO: a value of `nil' sorts it! That's not what the
> + ;; customize menu of `org-tags-sort-function' says! It
> + ;; says "No sorting".
Right. When sort function is not set agenda specifically (but not other
users of org-tags-sort-function) falls back to alphabetical sorting.
In fact, the docstring does not at all mention that
`org-tags-sort-function' is honored at all:
(defcustom org-agenda-sorting-strategy ...
...
tag-up Sort alphabetically by last tag, A-Z.
tag-down Sort alphabetically by last tag, Z-A.
We need to fix this docstring documenting `org-tags-sort-function', I think.
> + ((or 'nil 'org-string<)
> + "group_a\ngroupless\nlonely\ntag_a_1\ntag_a_2\ntag_b_1\ntag_b_2\n")
> + ('org-string>
> + "tag_b_2\ntag_b_1\ntag_a_2\ntag_a_1\nlonely\ngroupless\ngroup_a\n"))))))))
Nitpick: it would be more readable to use `string-join' here as well.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Testing: Add tests for `org-tags-sort-function'
2024-09-01 13:33 ` Ihor Radchenko
@ 2024-09-02 18:36 ` Morgan Smith
0 siblings, 0 replies; 3+ messages in thread
From: Morgan Smith @ 2024-09-02 18:36 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2442 bytes --]
I've attached an updated patch.
This one has a test where we actually don't sort tags by using the
`ignore' function.
Ihor Radchenko <yantar92@posteo.net> writes:
>> + ;; Sorting doesn't care about `org-tag-alist'. This is only
>> + ;; here for later when we add sorting methods that do
>> ....
>
> Then, please refrain from setting alist in this patch and add it later,
> when testing the relevant methods.
Done. Now my tag names don't really make sense but I suppose that's not
a big issue.
>> + (org-test-agenda-with-agenda
>> + (string-join
>> + '("* TODO group_a :group_a:"
>> + "* TODO tag_a_1 :tag_a_1:"
>> + "* TODO tag_a_2 :tag_a_2:"
>> + "* TODO tag_b_1 :tag_b_1:"
>> + "* TODO tag_b_2 :tag_b_2:"
>> + "* TODO groupless :groupless:"
>> + "* TODO lonely :lonely:")
>> + "\n")
>> + (dolist (org-tags-sort-function '(nil org-string< org-string>))
>> + (should
>> + (string-equal
>> + (progn
>> + (org-agenda nil "f")
>> + (substring-no-properties (buffer-string)))
>> + (pcase org-tags-sort-function
>> + ;; TODO: a value of `nil' sorts it! That's not what the
>> + ;; customize menu of `org-tags-sort-function' says! It
>> + ;; says "No sorting".
>
> Right. When sort function is not set agenda specifically (but not other
> users of org-tags-sort-function) falls back to alphabetical sorting.
As far as I can tell the only place where it doesn't fall back is in
`org-set-tags'.
> In fact, the docstring does not at all mention that
> `org-tags-sort-function' is honored at all:
>
> (defcustom org-agenda-sorting-strategy ...
> ...
> tag-up Sort alphabetically by last tag, A-Z.
> tag-down Sort alphabetically by last tag, Z-A.
>
> We need to fix this docstring documenting `org-tags-sort-function', I think.
I don't understand what is happening in `org-entries-lessp' or how it
even manages to use `org-agenda-sorting-strategy' so I'm going to
refrain from trying to document things I don't understand.
>> + ((or 'nil 'org-string<)
>> + "group_a\ngroupless\nlonely\ntag_a_1\ntag_a_2\ntag_b_1\ntag_b_2\n")
>> + ('org-string>
>> + "tag_b_2\ntag_b_1\ntag_a_2\ntag_a_1\nlonely\ngroupless\ngroup_a\n"))))))))
>
> Nitpick: it would be more readable to use `string-join' here as well.
Done
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Testing-Add-tests-for-org-tags-sort-function.patch --]
[-- Type: text/x-patch, Size: 2587 bytes --]
From 04fe8d44aba77b79a3a0f6ad332a0fb07bdb21a2 Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Sat, 15 Jun 2024 11:27:34 -0400
Subject: [PATCH] Testing: Add tests for `org-tags-sort-function'
* testing/lisp/test-org-agenda.el (test-org-agenda/tags-sorting): New
test.
---
testing/lisp/test-org-agenda.el | 44 +++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el
index 778f91e8e..a06d02064 100644
--- a/testing/lisp/test-org-agenda.el
+++ b/testing/lisp/test-org-agenda.el
@@ -655,6 +655,50 @@ Sunday 7 January 2024
(buffer-string))))))
(org-test-agenda--kill-all-agendas))))
+(ert-deftest test-org-agenda/tags-sorting ()
+ "Test if `org-agenda' sorts tags according to `org-tags-sort-function'."
+ (let ((org-agenda-custom-commands
+ '(("f" "no fluff" todo ""
+ ((org-agenda-todo-keyword-format "")
+ (org-agenda-overriding-header "")
+ (org-agenda-prefix-format "")
+ (org-agenda-remove-tags t)
+ (org-agenda-sorting-strategy '(tag-up)))))))
+ (org-test-agenda-with-agenda
+ (string-join
+ '("* TODO group_a :group_a:"
+ "* TODO tag_a_1 :tag_a_1:"
+ "* TODO tag_a_2 :tag_a_2:"
+ "* TODO tag_b_1 :tag_b_1:"
+ "* TODO tag_b_2 :tag_b_2:"
+ "* TODO groupless :groupless:"
+ "* TODO lonely :lonely:")
+ "\n")
+ (dolist (org-tags-sort-function '(nil org-string< org-string> ignore))
+ (should
+ (string-equal
+ (string-trim
+ (progn
+ (org-agenda nil "f")
+ (substring-no-properties (buffer-string))))
+ (pcase org-tags-sort-function
+ ;; Not sorted
+ ('ignore
+ (string-join
+ '("group_a" "tag_a_1" "tag_a_2" "tag_b_1" "tag_b_2" "groupless" "lonely")
+ "\n"))
+ ;; TODO: a value of `nil' sorts it! That's not what the
+ ;; customize menu of `org-tags-sort-function' says! It
+ ;; says "No sorting".
+ ((or 'nil 'org-string< 'always)
+ (string-join
+ '("group_a" "groupless" "lonely" "tag_a_1" "tag_a_2" "tag_b_1" "tag_b_2")
+ "\n"))
+ ('org-string>
+ (string-join
+ '("tag_b_2" "tag_b_1" "tag_a_2" "tag_a_1" "lonely" "groupless" "group_a")
+ "\n")))))))))
+
(ert-deftest test-org-agenda/goto-date ()
"Test `org-agenda-goto-date'."
(unwind-protect
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-02 18:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-15 15:27 [PATCH] Testing: Add tests for `org-tags-sort-function' Morgan Smith
2024-09-01 13:33 ` Ihor Radchenko
2024-09-02 18:36 ` Morgan Smith
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).