emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 5d4b9f9089 5/6: Merge pull request #496 from jea


From: ELPA Syncer
Subject: [elpa] externals/denote 5d4b9f9089 5/6: Merge pull request #496 from jeanphilippegg/fix-tests
Date: Sat, 14 Dec 2024 03:57:58 -0500 (EST)

branch: externals/denote
commit 5d4b9f9089bbfe8de8bc58b5f87cd021c55ee830
Merge: 6613d3903d 779fe017dc
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #496 from jeanphilippegg/fix-tests
    
    Fix tests
---
 denote.el            | 18 +++++++++++-------
 tests/denote-test.el | 54 +++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 48 insertions(+), 24 deletions(-)

diff --git a/denote.el b/denote.el
index 40f776405f..296e02de78 100644
--- a/denote.el
+++ b/denote.el
@@ -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
@@ -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."
@@ -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)
diff --git a/tests/denote-test.el b/tests/denote-test.el
index 8dd2ba92b0..3a083abfe5 100644
--- a/tests/denote-test.el
+++ b/tests/denote-test.el
@@ -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"))
 
@@ -198,6 +200,7 @@ does not involve the time zone."
                                "date:       2023-06-05"
                                "tags:       one  two"
                                "identifier: 20230605T102234"
+                               "signature:  sig"
                                "---------------------------\n\n")
                              "\n"))))
 
@@ -207,6 +210,7 @@ does not involve the time zone."
                                      "#+date:       2024-01-01"
                                      "#+filetags:   "
                                      "#+identifier: "
+                                     "#+signature:  "
                                      "\n")
                                    "\n"))
 
@@ -219,6 +223,7 @@ does not involve the time zone."
                                "#+date:       2023-06-05"
                                "#+filetags:   :one:two:"
                                "#+identifier: 20230605T102234"
+                               "#+signature:  sig"
                                "\n")
                              "\n"))))
 
@@ -229,6 +234,7 @@ does not involve the time zone."
                                      "date:       2024-01-01"
                                      "tags:       []"
                                      "identifier: \"\""
+                                     "signature:  \"\""
                                      "---"
                                      "\n")
                                    "\n"))
@@ -243,6 +249,7 @@ does not involve the time zone."
                                "date:       2023-06-05"
                                "tags:       [\"one\", \"two\"]"
                                "identifier: \"20230605T102234\""
+                               "signature:  \"sig\""
                                "---"
                                "\n")
                              "\n"))))
@@ -254,6 +261,7 @@ does not involve the time zone."
                                      "date       = 2024-01-01"
                                      "tags       = []"
                                      "identifier = \"\""
+                                     "signature  = \"\""
                                      "+++"
                                      "\n")
                                    "\n"))
@@ -268,6 +276,7 @@ does not involve the time zone."
                                "date       = 2023-06-05"
                                "tags       = [\"one\", \"two\"]"
                                "identifier = \"20230605T102234\""
+                               "signature  = \"sig\""
                                "+++"
                                "\n")
                              "\n"))))))
@@ -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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]