emacs-diffs
[Top][All Lists]
Advanced

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

master a0d5de4 1/3: Add test for lm-website


From: Stefan Kangas
Subject: master a0d5de4 1/3: Add test for lm-website
Date: Sun, 26 Sep 2021 08:55:35 -0400 (EDT)

branch: master
commit a0d5de4fb9de82dfda741c5cf39d87cee955cc46
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Add test for lm-website
    
    * lisp/emacs-lisp/lisp-mnt.el (lm-website): Use rx.
    * test/lisp/emacs-lisp/lisp-mnt-tests.el
    (lm--tests-lm-website): New test.
---
 lisp/emacs-lisp/lisp-mnt.el            | 6 +++---
 test/lisp/emacs-lisp/lisp-mnt-tests.el | 8 ++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/lisp-mnt.el b/lisp/emacs-lisp/lisp-mnt.el
index b27c7e7..96ac054 100644
--- a/lisp/emacs-lisp/lisp-mnt.el
+++ b/lisp/emacs-lisp/lisp-mnt.el
@@ -501,9 +501,9 @@ absent, return nil."
 (defun lm-website (&optional file)
   "Return the website in file FILE, or current buffer if FILE is nil."
   (let ((page (lm-with-file file
-                (lm-header "\\(?:x-\\)?\\(?:url\\|homepage\\)"))))
-    (if (and page (string-match "^<.+>$" page))
-       (substring page 1 -1)
+                (lm-header (rx (? "x-") (or "url" "homepage"))))))
+    (if (and page (string-match (rx bol "<" (+ nonl) ">" eol) page))
+        (substring page 1 -1)
       page)))
 (defalias 'lm-homepage 'lm-website) ; for backwards-compatibility
 
diff --git a/test/lisp/emacs-lisp/lisp-mnt-tests.el 
b/test/lisp/emacs-lisp/lisp-mnt-tests.el
index 84cdc72..d77804f 100644
--- a/test/lisp/emacs-lisp/lisp-mnt-tests.el
+++ b/test/lisp/emacs-lisp/lisp-mnt-tests.el
@@ -32,5 +32,13 @@
                  '(("Bob Weiner" . "rsw@gnu.org")
                    ("Mats Lidell" . "matsl@gnu.org")))))
 
+(ert-deftest lm--tests-lm-website ()
+  (with-temp-buffer
+    (insert ";; URL: https://example.org/foo";)
+    (should (string= (lm-website) "https://example.org/foo";)))
+  (with-temp-buffer
+    (insert  ";; X-URL: <https://example.org/foo>")
+    (should (string= (lm-website) "https://example.org/foo";))))
+
 (provide 'lisp-mnt-tests)
 ;;; lisp-mnt-tests.el ends here



reply via email to

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