[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/hyperbole 404577d: Stefans patch piece 2 (#109)
From: |
ELPA Syncer |
Subject: |
[elpa] externals/hyperbole 404577d: Stefans patch piece 2 (#109) |
Date: |
Sun, 8 Aug 2021 10:57:10 -0400 (EDT) |
branch: externals/hyperbole
commit 404577def93b583c593b5dad8ab9a77fd10d5f44
Author: Mats Lidell <mats.lidell@lidells.se>
Commit: GitHub <noreply@github.com>
Stefans patch piece 2 (#109)
* Add tests for hpath:substitute-value
* Use lexical scope, match-beginning and match-end
---
ChangeLog | 9 +++++++++
hpath.el | 11 ++++++-----
test/hpath-tests.el | 28 ++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 37cf35c..98d067c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-07-20 Mats Lidell <matsl@gnu.org>
+
+* hpath.el: Part two of patch from Stefan Monnier. Thank you Stefan. Use
+ lexical scope.
+ (hpath:substitute-value): Use match-beginning and match-end.
+
+* test/hpath-tests.el (hpath:subsitute-value-test): Add tests for
+ hpath:substitute-value.
+
2021-07-19 Mats Lidell <matsl@gnu.org>
* test/hmouse-drv-tests.el (hbut-etags-test): Rename test case due to name
diff --git a/hpath.el b/hpath.el
index 717bbed..834c445 100644
--- a/hpath.el
+++ b/hpath.el
@@ -1,10 +1,10 @@
-;;; hpath.el --- GNU Hyperbole support routines for handling POSIX and
MSWindows paths
+;;; hpath.el --- GNU Hyperbole support routines for handling POSIX and
MSWindows paths -*- lexical-binding: t; -*-
;;
;; Author: Bob Weiner
;;
;; Orig-Date: 1-Nov-91 at 00:44:23
;;
-;; Copyright (C) 1991-2020 Free Software Foundation, Inc.
+;; Copyright (C) 1991-2021 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
@@ -1517,13 +1517,14 @@ in-buffer path will not match."
(defun hpath:substitute-value (path)
"Substitute matching value for Emacs Lisp variables and environment
variables in PATH and return PATH."
- ;; Uses free variables `match' and `start' from `hypb:replace-match-string'.
(substitute-in-file-name
(hpath:substitute-match-value
"\\$@?\{\\([^\}]+\\)@?\}"
path
- (lambda (matched-str)
- (let* ((var-group (substring path match start))
+ (lambda (_matched_str)
+ (let* ((match (match-beginning 0))
+ (start (match-end 0))
+ (var-group (substring path match start))
(rest-of-path (substring path start))
(var-ext (substring path (match-beginning 1) (match-end 1)))
(var-name (if (= ?@ (aref var-ext (1- (length var-ext))))
diff --git a/test/hpath-tests.el b/test/hpath-tests.el
index 1d4224d..d9e1651 100644
--- a/test/hpath-tests.el
+++ b/test/hpath-tests.el
@@ -75,5 +75,33 @@
(hpath:find "-tutorial.el")
(should was-called))))
+(ert-deftest hpath:subsitute-value-test ()
+ "Environment and Lisp variables shall be substituted in a path."
+ (progn ()
+ (setq hypb:lc-var "lower")
+ (setq hypb:uc-var "UPPER")
+ (setenv "HYPB_TEST_ENV" "env")
+
+ (should (string= (hpath:substitute-value "/nothing/to/substitute")
"/nothing/to/substitute"))
+
+ (should (string= (hpath:substitute-value "${hypb:lc-var}")
hypb:lc-var))
+ (should (string= (hpath:substitute-value "${hypb:uc-var}")
hypb:uc-var))
+ (should (string= (hpath:substitute-value "$HYPB_TEST_ENV") (getenv
"HYPB_TEST_ENV")))
+ (should (string= (hpath:substitute-value "${HYPB_TEST_ENV}") (getenv
"HYPB_TEST_ENV")))
+
+ (should (string= (hpath:substitute-value
"prefix${hypb:lc-var}suffix") (concat "prefix" hypb:lc-var "suffix")))
+ (should (string= (hpath:substitute-value
"prefix/$HYPB_TEST_ENV/suffix") (concat "prefix/" (getenv "HYPB_TEST_ENV")
"/suffix")))
+ (should (string= (hpath:substitute-value
"prefix${HYPB_TEST_ENV}suffix") (concat "prefix" (getenv "HYPB_TEST_ENV")
"suffix")))
+
+ (should (string= (hpath:substitute-value
"${hypb:lc-var}${hypb:uc-var}") (concat hypb:lc-var hypb:uc-var)))
+ (should (string= (hpath:substitute-value
"$HYPB_TEST_ENV/$HYPB_TEST_ENV") (concat (getenv "HYPB_TEST_ENV") "/" (getenv
"HYPB_TEST_ENV"))))
+ (should (string= (hpath:substitute-value
"${HYPB_TEST_ENV}${HYPB_TEST_ENV}") (concat (getenv "HYPB_TEST_ENV") (getenv
"HYPB_TEST_ENV"))))
+
+ (should (string= (hpath:substitute-value
"prefix${hypb:lc-var}/$HYPB_TEST_ENV/suffix") (concat "prefix" hypb:lc-var "/"
(getenv "HYPB_TEST_ENV") "/suffix")))
+
+ (should (string= (hpath:substitute-value
"$UNDEFINED_IS_NOT_SUBSTITUTED") "$UNDEFINED_IS_NOT_SUBSTITUTED"))
+ (should (string= (hpath:substitute-value
"${UNDEFINED_IS_NOT_SUBSTITUTED}") "${UNDEFINED_IS_NOT_SUBSTITUTED}"))
+ ))
+
(provide 'hpath-tests)
;;; hpath-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/hyperbole 404577d: Stefans patch piece 2 (#109),
ELPA Syncer <=