emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Ruijie Yu <ruijie@netyu.xyz>
Cc: Axel Kielhorn <org-mode@axelkielhorn.de>, emacs-orgmode@gnu.org
Subject: Re: [DRAFT PATCH v5] Decouple LANG= and testing (was: Test failure due to LANG)
Date: Wed, 26 Apr 2023 08:44:07 +0000	[thread overview]
Message-ID: <87cz3rowx4.fsf@localhost> (raw)
In-Reply-To: <sdvfs8os6es.fsf@netyu.xyz>

Ruijie Yu <ruijie@netyu.xyz> writes:

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> (let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M")))
>>      (org-element-timestamp-interpreter timestamp nil))
>
> Thanks for the pointer.  I have made this into a macro and redid my
> changes accordingly.  Please also let me know if more work should be
> dedicated to avoid code duplication in tests (I see a lot of duplication
> in the portions I touched in testing/lisp/test-org.el).

Thanks!
Some comments below.

> +(defmacro org-test-with-result (result &rest body)
...
> +             (_ 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)))

When reading the test code, this `org-test-without-dow' is quite
confusing - the name suggests "day of week"-related, but RESULTS='buffer
argument is doing something completely different.

IMHO, it would be cleaner to:
1. (let ((org-time-stamp-formats ...)) ...) around the whole test.
2. Use `org-test-with-result' explicitly inside individual test clauses.

> +(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'.")

These constants make it necessary to write incantations like

   (sun (aref org-test-day-of-weeks-abbrev 0))

Why not creating a function like (org-test-translate-dow "Mon")
or (org-test-translate-dow "Monday") that will do the same?
It will be a lot more readable as well. You can then use an alist
instead of vectors.

-- 
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>


  parent reply	other threads:[~2023-04-26  8:42 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-22  7:11 Test failure due to LANG Axel Kielhorn
2023-04-22  9:51 ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 10:15   ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 12:37     ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 13:01       ` [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG) Ruijie Yu via General discussions about Org-mode.
2023-04-22 13:51         ` Ruijie Yu via General discussions about Org-mode.
2023-04-23 10:54           ` Ihor Radchenko
     [not found]             ` <sdvjzy2rhne.fsf@netyu.xyz>
2023-04-23 11:19               ` Ihor Radchenko
2023-04-23 14:30                 ` Ruijie Yu via General discussions about Org-mode.
2023-04-23 15:03                   ` Ihor Radchenko
2023-04-23 15:15                     ` Ruijie Yu via General discussions about Org-mode.
2023-04-25 10:11                       ` Ihor Radchenko
2023-04-25 15:14                         ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 14:50         ` Axel Kielhorn
2023-04-22 15:03           ` Ruijie Yu via General discussions about Org-mode.
2023-04-23  1:47             ` [DRAFT PATCH v3] " Ruijie Yu via General discussions about Org-mode.
2023-04-23  5:36               ` Axel Kielhorn
2023-04-23  6:46                 ` [DRAFT PATCH v4] " Ruijie Yu via General discussions about Org-mode.
2023-04-23 11:17                   ` Ihor Radchenko
2023-04-23 13:57                     ` Ruijie Yu via General discussions about Org-mode.
2023-04-23 15:07                       ` Ihor Radchenko
2023-04-25  8:02                         ` [DRAFT PATCH v5] " Ruijie Yu via General discussions about Org-mode.
2023-04-25 15:19                           ` [DRAFT PATCH v6] " Ruijie Yu via General discussions about Org-mode.
2023-04-26  9:05                             ` Ihor Radchenko
2023-04-26  8:44                           ` Ihor Radchenko [this message]
2023-07-17  8:58                             ` [DRAFT PATCH v5] " Ihor Radchenko
2023-04-22 14:28       ` Test failure due to LANG Axel Kielhorn
2023-04-22 12:35 ` Ihor Radchenko
2023-04-22 13:00   ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 14:21   ` Max Nikulin
2023-04-22 14:35     ` Ihor Radchenko
2023-04-22 14:40     ` Axel Kielhorn
2023-04-22 16:14       ` Max Nikulin
2023-04-22 14:36   ` Axel Kielhorn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87cz3rowx4.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=org-mode@axelkielhorn.de \
    --cc=ruijie@netyu.xyz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).