Fix string-replace error data

* lisp/subr.el (string-replace): Signal an error with data that is a
list, and whose contents are consistent with other uses of
wrong-length-argument.
* test/lisp/subr-tests.el (string-replace): Test for this.
(subr-test-define-prefix-command): Pacify byte-compiler warnings.
This commit is contained in:
Basil L. Contovounesios 2021-03-07 14:55:15 +00:00
parent 564b6391f8
commit 8558ecd65f
2 changed files with 7 additions and 2 deletions

View file

@ -4784,7 +4784,7 @@ Unless optional argument INPLACE is non-nil, return a new string."
"Replace FROMSTRING with TOSTRING in INSTRING each time it occurs."
(declare (pure t) (side-effect-free t))
(when (equal fromstring "")
(signal 'wrong-length-argument fromstring))
(signal 'wrong-length-argument '(0)))
(let ((start 0)
(result nil)
pos)

View file

@ -78,10 +78,14 @@
(ert-deftest subr-test-define-prefix-command ()
(define-prefix-command 'foo-prefix-map)
(defvar foo-prefix-map)
(declare-function foo-prefix-map "subr-tests")
(should (keymapp foo-prefix-map))
(should (fboundp #'foo-prefix-map))
;; With optional argument.
(define-prefix-command 'bar-prefix 'bar-prefix-map)
(defvar bar-prefix-map)
(declare-function bar-prefix "subr-tests")
(should (keymapp bar-prefix-map))
(should (fboundp #'bar-prefix))
;; Returns the symbol.
@ -531,7 +535,8 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
(should (equal (string-replace "a" "aa" "aaa") "aaaaaa"))
(should (equal (string-replace "abc" "defg" "abc") "defg"))
(should-error (string-replace "" "x" "abc")))
(should (equal (should-error (string-replace "" "x" "abc"))
'(wrong-length-argument 0))))
(ert-deftest subr-replace-regexp-in-string ()
(should (equal (replace-regexp-in-string "a+" "xy" "abaabbabaaba")