Expand tests to also cover alphanumeric child sequences

This commit is contained in:
Protesilaos Stavrou 2025-01-12 10:19:44 +02:00
parent b642758ff9
commit a0188e7cba
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA

View file

@ -594,8 +594,9 @@ does not involve the time zone."
;; TODO 2024-12-31: Maybe we can share some state between tests? It
;; is expensive to create those files over and over.
(ert-deftest dt-denote-sequence--get-new-child ()
"Make sure `denote-sequence--get-new-child' gets the child of a sequence."
(ert-deftest dt-denote-sequence--get-new-child-numeric ()
"Make sure `denote-sequence--get-new-child' gets the child of a sequence.
This is done using the numeric `denote-sequence-scheme'."
(let* ((denote-directory (expand-file-name "denote-test" temporary-file-directory))
(files
(mapcar
@ -613,9 +614,7 @@ does not involve the time zone."
"20241230T075023==1=1=2--test__testing.txt"
"20241230T075023==1=2--test__testing.txt"
"20241230T075023==1=2=1--test__testing.txt"
"20241230T075023==2--test__testing.txt"
"20241230T075023==45--test__testing.txt"
"20241230T075023==45=1--test__testing.txt")))
"20241230T075023==2--test__testing.txt")))
(sequences (denote-sequence-get-all-sequences files)))
(let ((denote-sequence-scheme 'numeric))
(should
@ -625,8 +624,41 @@ does not involve the time zone."
(equal (denote-sequence--get-new-child "1=1=2" sequences) "1=1=2=1")
(equal (denote-sequence--get-new-child "1=2" sequences) "1=2=2")
(equal (denote-sequence--get-new-child "1=2=1" sequences) "1=2=1=1")
(equal (denote-sequence--get-new-child "2" sequences) "2=1")
(equal (denote-sequence--get-new-child "45" sequences) "45=2")))
(equal (denote-sequence--get-new-child "2" sequences) "2=1")))
(should-error (denote-sequence--get-new-child "3" sequences)))
(delete-directory denote-directory :delete-contents-as-well)))
(ert-deftest dt-denote-sequence--get-new-child-alphanumeric ()
"Make sure `denote-sequence--get-new-child' gets the child of a sequence.
This is done using the alphanumeric `denote-sequence-scheme'."
(let* ((denote-directory (expand-file-name "denote-test" temporary-file-directory))
(files
(mapcar
(lambda (file)
(let ((path (expand-file-name file (denote-directory))))
(if (file-exists-p path)
path
(with-current-buffer (find-file-noselect path)
(save-buffer)
(kill-buffer (current-buffer)))
path)))
'("20241230T075004==1--some-new-title__testing.txt"
"20241230T075023==1a--child-of-note__testing.txt"
"20241230T075023==1a1--test__testing.txt"
"20241230T075023==1a2--test__testing.txt"
"20241230T075023==1b--test__testing.txt"
"20241230T075023==1b1--test__testing.txt"
"20241230T075023==2--test__testing.txt")))
(sequences (denote-sequence-get-all-sequences files)))
(let ((denote-sequence-scheme 'alphanumeric))
(should
(and
(equal (denote-sequence--get-new-child "1" sequences) "1c")
(equal (denote-sequence--get-new-child "1a" sequences) "1a3")
(equal (denote-sequence--get-new-child "1a2" sequences) "1a2a")
(equal (denote-sequence--get-new-child "1b" sequences) "1b2")
(equal (denote-sequence--get-new-child "1b1" sequences) "1b1a")
(equal (denote-sequence--get-new-child "2" sequences) "2a")))
(should-error (denote-sequence--get-new-child "3" sequences)))
(delete-directory denote-directory :delete-contents-as-well)))