diff options
| author | Jim Porter | 2022-09-18 17:42:09 -0700 |
|---|---|---|
| committer | Jim Porter | 2022-11-03 11:44:41 -0700 |
| commit | d2a9dae40057ff16683d9c5f30a3b04500ebc4cf (patch) | |
| tree | cd34f064081354464eeac91b4ee2aa76a2a23982 | |
| parent | 39f5696921c1618f46358a5c189244d3993a1fca (diff) | |
| download | emacs-d2a9dae40057ff16683d9c5f30a3b04500ebc4cf.tar.gz emacs-d2a9dae40057ff16683d9c5f30a3b04500ebc4cf.zip | |
Only strip newlines when stringifying a value for Eshell
* lisp/eshell/esh-util.el (eshell-stringify): Use 'string-trim-right'
instead of stripping the last character of the result of
'pp-to-string' (bug#58810).
* test/lisp/eshell/esh-util-tests.el: New file.
| -rw-r--r-- | lisp/eshell/esh-util.el | 11 | ||||
| -rw-r--r-- | test/lisp/eshell/esh-util-tests.el | 57 |
2 files changed, 61 insertions, 7 deletions
diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el index f47373c115f..ecb6888651f 100644 --- a/lisp/eshell/esh-util.el +++ b/lisp/eshell/esh-util.el | |||
| @@ -350,16 +350,13 @@ Prepend remote identification of `default-directory', if any." | |||
| 350 | "Convert OBJECT into a string value." | 350 | "Convert OBJECT into a string value." |
| 351 | (cond | 351 | (cond |
| 352 | ((stringp object) object) | 352 | ((stringp object) object) |
| 353 | ((and (listp object) | ||
| 354 | (not (eq object nil))) | ||
| 355 | (let ((string (pp-to-string object))) | ||
| 356 | (substring string 0 (1- (length string))))) | ||
| 357 | ((numberp object) | 353 | ((numberp object) |
| 358 | (number-to-string object)) | 354 | (number-to-string object)) |
| 355 | ((and (eq object t) | ||
| 356 | (not eshell-stringify-t)) | ||
| 357 | nil) | ||
| 359 | (t | 358 | (t |
| 360 | (unless (and (eq object t) | 359 | (string-trim-right (pp-to-string object))))) |
| 361 | (not eshell-stringify-t)) | ||
| 362 | (pp-to-string object))))) | ||
| 363 | 360 | ||
| 364 | (defsubst eshell-stringify-list (args) | 361 | (defsubst eshell-stringify-list (args) |
| 365 | "Convert each element of ARGS into a string value." | 362 | "Convert each element of ARGS into a string value." |
diff --git a/test/lisp/eshell/esh-util-tests.el b/test/lisp/eshell/esh-util-tests.el new file mode 100644 index 00000000000..1cbd015999f --- /dev/null +++ b/test/lisp/eshell/esh-util-tests.el | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | ;;; esh-util-tests.el --- esh-util test suite -*- lexical-binding:t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2022 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Code: | ||
| 21 | |||
| 22 | (require 'ert) | ||
| 23 | (require 'esh-util) | ||
| 24 | |||
| 25 | ;;; Tests: | ||
| 26 | |||
| 27 | (ert-deftest esh-util-test/eshell-stringify/string () | ||
| 28 | "Test that `eshell-stringify' preserves the value of strings." | ||
| 29 | (should (equal (eshell-stringify "hello") "hello"))) | ||
| 30 | |||
| 31 | (ert-deftest esh-util-test/eshell-stringify/number () | ||
| 32 | "Test that `eshell-stringify' converts numbers to strings." | ||
| 33 | (should (equal (eshell-stringify 42) "42")) | ||
| 34 | (should (equal (eshell-stringify 4.2) "4.2"))) | ||
| 35 | |||
| 36 | (ert-deftest esh-util-test/eshell-stringify/t () | ||
| 37 | "Test that `eshell-stringify' treats `t' according to `eshell-stringify-t'." | ||
| 38 | (let ((eshell-stringify-t t)) | ||
| 39 | (should (equal (eshell-stringify t) "t"))) | ||
| 40 | (let ((eshell-stringify-t nil)) | ||
| 41 | (should (equal (eshell-stringify t) nil)))) | ||
| 42 | |||
| 43 | (ert-deftest esh-util-test/eshell-stringify/nil () | ||
| 44 | "Test that `eshell-stringify' converts nil to a string." | ||
| 45 | (should (equal (eshell-stringify nil) "nil"))) | ||
| 46 | |||
| 47 | (ert-deftest esh-util-test/eshell-stringify/list () | ||
| 48 | "Test that `eshell-stringify' correctly stringifies lists." | ||
| 49 | (should (equal (eshell-stringify '(1 2 3)) "(1 2 3)")) | ||
| 50 | (should (equal (eshell-stringify '((1 2) (3 . 4))) | ||
| 51 | "((1 2)\n (3 . 4))"))) | ||
| 52 | |||
| 53 | (ert-deftest esh-util-test/eshell-stringify/complex () | ||
| 54 | "Test that `eshell-stringify' correctly stringifies complex objects." | ||
| 55 | (should (equal (eshell-stringify (list 'quote 'hello)) "'hello"))) | ||
| 56 | |||
| 57 | ;;; esh-util-tests.el ends here | ||