Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #496

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions denote.el
Original file line number Diff line number Diff line change
Expand Up @@ -1196,11 +1196,12 @@ For our purposes, a note must satisfy `file-regular-p' and
This tests the rules of Denote's file-naming scheme. Sluggification is
ignored. It is done by removing all file name components and validating
what remains."
(let ((filename (file-name-nondirectory file))
(title (denote-retrieve-filename-title file))
(keywords-string (denote-retrieve-filename-keywords file))
(signature (denote-retrieve-filename-signature file))
(identifier (denote-retrieve-filename-identifier file)))
(let* ((initial-filename (file-name-nondirectory file))
(filename initial-filename)
(title (denote-retrieve-filename-title file))
(keywords-string (denote-retrieve-filename-keywords file))
(signature (denote-retrieve-filename-signature file))
(identifier (denote-retrieve-filename-identifier file)))
(when title
(setq filename (replace-regexp-in-string (concat "\\(--" (regexp-quote title) "\\).*\\'") "" filename nil nil 1)))
(when keywords-string
Expand All @@ -1212,8 +1213,9 @@ what remains."
(setq filename (replace-regexp-in-string (concat "\\(@@" (regexp-quote identifier) "\\).*\\'") "" filename nil nil 1))
(setq filename (replace-regexp-in-string (concat "\\(" (regexp-quote identifier) "\\).*\\'") "" filename nil nil 1))))
;; What remains should be the empty string or the file extension.
(or (string-empty-p filename)
(string-prefix-p "." filename))))
(and (not (string-prefix-p "." initial-filename))
(or (string-empty-p filename)
(string-prefix-p "." filename)))))

(defun denote-file-has-signature-p (file)
"Return non-nil if FILE has a Denote identifier."
Expand Down Expand Up @@ -2227,6 +2229,8 @@ which case it is not added to the base file name."
(setq file-name (concat file-name "__" (denote-keywords-combine (denote-sluggify-keywords keywords)))))
((and (eq component 'signature) signature (not (string-empty-p signature)))
(setq file-name (concat file-name "==" (denote-sluggify 'signature signature))))))
(when (string-empty-p file-name)
(error "There should be at least one file name component"))
(setq file-name (concat file-name extension))
;; Do not prepend identifier with @@ if it is the first component and has the format 00000000T000000.
(when (and (string-prefix-p "@@" file-name)
Expand Down
54 changes: 37 additions & 17 deletions tests/denote-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ Extend what we do in `denote-test--denote-file-type-extensions'."
"Test that `denote--format-front-matter' formats front matter correctly.
To make the test reproducible, set `denote-date-format' to a value that
does not involve the time zone."
(let ((denote-date-format "%Y-%m-%d"))
(let ((denote-date-format "%Y-%m-%d")
(denote-front-matter-components-present-even-if-empty-value '(title keywords signature date identifier)))
(should (and (equal (denote--format-front-matter "" (date-to-time "20240101T120000") '("") "" "" 'text)
(mapconcat #'identity
'("title: "
"date: 2024-01-01"
"tags: "
"identifier: "
"signature: "
"---------------------------\n\n")
"\n"))

Expand All @@ -198,6 +200,7 @@ does not involve the time zone."
"date: 2023-06-05"
"tags: one two"
"identifier: 20230605T102234"
"signature: sig"
"---------------------------\n\n")
"\n"))))

Expand All @@ -207,6 +210,7 @@ does not involve the time zone."
"#+date: 2024-01-01"
"#+filetags: "
"#+identifier: "
"#+signature: "
"\n")
"\n"))

Expand All @@ -219,6 +223,7 @@ does not involve the time zone."
"#+date: 2023-06-05"
"#+filetags: :one:two:"
"#+identifier: 20230605T102234"
"#+signature: sig"
"\n")
"\n"))))

Expand All @@ -229,6 +234,7 @@ does not involve the time zone."
"date: 2024-01-01"
"tags: []"
"identifier: \"\""
"signature: \"\""
"---"
"\n")
"\n"))
Expand All @@ -243,6 +249,7 @@ does not involve the time zone."
"date: 2023-06-05"
"tags: [\"one\", \"two\"]"
"identifier: \"20230605T102234\""
"signature: \"sig\""
"---"
"\n")
"\n"))))
Expand All @@ -254,6 +261,7 @@ does not involve the time zone."
"date = 2024-01-01"
"tags = []"
"identifier = \"\""
"signature = \"\""
"+++"
"\n")
"\n"))
Expand All @@ -268,6 +276,7 @@ does not involve the time zone."
"date = 2023-06-05"
"tags = [\"one\", \"two\"]"
"identifier = \"20230605T102234\""
"signature = \"sig\""
"+++"
"\n")
"\n"))))))
Expand Down Expand Up @@ -304,27 +313,38 @@ does not involve the time zone."

(should-error (denote-format-file-name
(denote-directory)
""
nil
kws
title
(denote--file-extension 'org)
""))

(should-error (denote-format-file-name
(denote-directory)
""
kws
title
(denote--file-extension 'org)
""))

(should-error (denote-format-file-name
(denote-directory)
"0123456"
kws
title
(denote--file-extension 'org)
""))
(should (equal (denote-format-file-name
(denote-directory)
nil
kws
title
(denote--file-extension 'org)
"")
"/tmp/test-denote/--some-test__one_two.org"))

(should (equal (denote-format-file-name
(denote-directory)
""
kws
title
(denote--file-extension 'org)
"")
"/tmp/test-denote/--some-test__one_two.org"))

(should (equal (denote-format-file-name
(denote-directory)
"0123456"
kws
title
(denote--file-extension 'org)
"")
"/tmp/test-denote/@@0123456--some-test__one_two.org"))

(should (equal (denote-format-file-name
(denote-directory)
Expand Down