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

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

[elpa] externals/denote 73dfc1f1bc 8/8: Write some unit tests (WORK-IN-P


From: ELPA Syncer
Subject: [elpa] externals/denote 73dfc1f1bc 8/8: Write some unit tests (WORK-IN-PROGRESS)
Date: Mon, 22 May 2023 15:58:00 -0400 (EDT)

branch: externals/denote
commit 73dfc1f1bcee1d50ef97ac230fc803981a7dd069
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Write some unit tests (WORK-IN-PROGRESS)
    
    I wrote those during a live stream (which is recorded for posterity):
    
<https://protesilaos.com/codelog/2023-05-22-live-stream-emacs-denote-ert-tests/>
---
 tests/denote-test.el | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 163 insertions(+)

diff --git a/tests/denote-test.el b/tests/denote-test.el
new file mode 100644
index 0000000000..371ffed9b0
--- /dev/null
+++ b/tests/denote-test.el
@@ -0,0 +1,163 @@
+;;; denote.el --- Unit tests for Denote -*- lexical-binding: t -*-
+
+;; Copyright (C) 2023  Free Software Foundation, Inc.
+
+;; Author: Protesilaos Stavrou <info@protesilaos.com>
+;; Maintainer: Denote Development <~protesilaos/denote@lists.sr.ht>
+;; URL: https://git.sr.ht/~protesilaos/denote
+;; Mailing-List: https://lists.sr.ht/~protesilaos/denote
+
+;; This file is NOT part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; WORK-IN-PROGRESS
+
+;;; Code:
+
+(require 'ert)
+(require 'denote)
+
+;; TODO 2023-05-22: Incorporate an actual silo in this test directory
+;; and modify the test accordingly.
+(ert-deftest denote-test-denote--default-directory-is-silo-p ()
+  "Test that `denote--default-directory-is-silo-p' returns a path."
+  (let ((path (denote--default-directory-is-silo-p)))
+    (should (or (null path)
+                (and (stringp path)
+                     (file-exists-p path)
+                     (file-directory-p path))))))
+
+(ert-deftest denote-test--denote--make-denote-directory ()
+  "Test that `denote--make-denote-directory' creates the directory."
+  (should (null (denote--make-denote-directory))))
+
+(ert-deftest denote-test--denote-directory ()
+  "Test that `denote-directory' returns an absolute directory name."
+  (let ((path (denote-directory)))
+    (should (and (file-directory-p path)
+                 (file-name-absolute-p path)))))
+
+(ert-deftest denote-test--denote--slug-no-punct ()
+  "Test that `denote--slug-no-punct' removes punctuation from the string.
+Concretely, replace with spaces anything that matches the
+`denote-excluded-punctuation-regexp' and
+`denote-excluded-punctuation-extra-regexp'."
+  (should (equal (denote--slug-no-punct "This is !@# test")
+                 "This is  test")))
+
+(ert-deftest denote-test--denote--slug-hyphenate ()
+  "Test that `denote--slug-hyphenate' hyphenates the string.
+Also replace multiple hyphens with a single one and remove any
+leading and trailing hyphen."
+  (should (equal (denote--slug-hyphenate "__  This is   a    test  __  ")
+                 "This-is-a-test")))
+
+(ert-deftest denote-test--denote-sluggify ()
+  "Test that `denote-sluggify' sluggifies the string.
+To sluggify is to (i) downcase, (ii) hyphenate, (iii) de-punctuate, and (iv) 
remove spaces from the string."
+  (should (equal (denote-sluggify " ___ !~!!$%^ This iS a tEsT ++ ?? ")
+                 "this-is-a-test")))
+
+(ert-deftest denote-test--denote--slug-put-equals ()
+  "Test that `denote--slug-put-equals' replaces spaces/underscores with =.
+Otherwise do the same as what is described in
+`denote-test--denote--slug-hyphenate'.
+
+The use of the equals sign is for the SIGNATURE field of the
+Denote file name."
+  (should (equal (denote--slug-put-equals "__  This is   a    test  __  ")
+                 "This=is=a=test")))
+
+(ert-deftest denote-test--denote-sluggify-signature ()
+  "Test that `denote-sluggify-signature' sluggifies the string for file 
signatures.
+This is like `denote-test--denote-sluggify', except that it also
+accounts for what we describe in `denote-test--denote--slug-put-equals'."
+  (should (equal (denote-sluggify-signature " ___ !~!!$%^ This iS a tEsT ++ ?? 
")
+                 "this=is=a=test")))
+
+(ert-deftest denote-test--denote-sluggify-and-join ()
+  "Test that `denote-sluggify-and-join' sluggifies the string while joining 
words.
+In this context, to join words is to elimitate any space or
+delimiter between them.
+
+Otherwise, this is like `denote-test--denote-sluggify'."
+  (should (equal (denote-sluggify-and-join " ___ !~!!$%^ This iS a tEsT ++ ?? 
")
+                 "thisisatest")))
+
+(ert-deftest denote-test--denote-sluggify-keywords ()
+  "Test that `denote-sluggify-keywords' sluggifies a list of strings.
+The function also account for the value of the user option
+`denote-allow-multi-word-keywords'."
+  (should
+   (let ((denote-allow-multi-word-keywords nil))
+     (equal (denote-sluggify-keywords '("one !@# one" "   two" "__  three  
__"))
+            '("oneone" "two" "three"))))
+  (should
+   (let ((denote-allow-multi-word-keywords t))
+     (equal (denote-sluggify-keywords '("one !@# one" "   two" "__  three  
__"))
+            '("one-one" "two" "three")))))
+
+(ert-deftest denote-test--denote-desluggify ()
+  "Test that `denote-desluggify' upcases first character and de-hyphenates 
string."
+  (should (equal (denote-desluggify "this-is-a-test") "This is a test"))
+  (should (null (equal (denote-desluggify "this=is=a=test") "This is a 
test"))))
+
+(ert-deftest denote-test--denote--file-empty-p ()
+  "Test that `denote--file-empty-p' returns non-nil on empty file."
+  ;; (should (null (denote--file-empty-p user-init-file))
+  (should (let ((file (make-temp-file "denote-test")))
+            (prog1
+                (denote--file-empty-p file)
+              (delete-file file)))))
+
+;; FIXME 2023-05-22: It does not return non-nil even though I am
+;; giving it what should be a file in `denote-directory'.
+;; (ert-deftest denote-test--denote-file-is-note-p ()
+
+;;   "Test that `denote-file-is-note-p' checks that files is a Denote note.
+;; For our purposes, a note must note be a directory, must satisfy
+;; `file-regular-p', its path must be part of the variable
+;; `denote-directory', it must have a Denote identifier in its name,
+;; and use one of the extensions implied by `denote-file-type'."
+;;   (should (let* ((tmp (temporary-file-directory))
+;;                  (denote-directory tmp)
+;;                  (file (concat tmp "20230522T154900--test__keyword.txt")))
+;;             (prog1
+;;                 (denote-file-is-note-p file)
+;;               (delete-file file)))))
+
+(ert-deftest denote-test--denote-file-has-identifier-p ()
+  "Test that `denote-file-has-identifier-p' checks for a Denote identifier."
+  (should
+   (denote-file-has-identifier-p "20230522T154900--test__keyword.txt")))
+
+(ert-deftest denote-test--denote-file-has-signature-p ()
+  "Test that `denote-file-has-signature-p' checks for a Denote signature."
+  (should
+   (denote-file-has-signature-p "20230522T154900==sig--test__keyword.txt")))
+
+;; TODO 2023-05-22: Check the solution to the FIXME above and proceed
+;; accordingly.
+
+;; (ert-deftest denote-test--denote-file-directory-p ()
+;;   "Test that `denote-file-directory-p' returns non-nil on a directory.
+;; The function should return nil if the directory it checks for is
+;; matched by the user option `denote-excluded-directories-regexp'."
+;;   (should
+
+(provide 'denote-test)
+;;; denote-test.el ends here



reply via email to

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