From 73f77558ccd5f0d83af294676eedfce3aa1bb4cb Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 22 Sep 2020 16:20:05 +0200 Subject: Fix off-by-one error in eldoc--handle-docs * lisp/emacs-lisp/eldoc.el (eldoc--handle-docs): We have one extra line to use if we don't show the truncation message (bug#43543). --- lisp/emacs-lisp/eldoc.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el index 8fc8db62220..9e38e5908ed 100644 --- a/lisp/emacs-lisp/eldoc.el +++ b/lisp/emacs-lisp/eldoc.el @@ -510,6 +510,10 @@ Honor most of `eldoc-echo-area-use-multiline-p'." (> (+ (length single-doc) (length single-doc-sym) 2) width)) single-doc) ((> available 1) + ;; The message takes one extra line, so if we don't + ;; display that, we have one extra line to use. + (unless eldoc-display-truncation-message + (setq available (1+ available))) (with-current-buffer (eldoc-doc-buffer) (cl-loop initially -- cgit v1.2.3 From 10696d0ac51b9a92359ab7cb2c2e0a28d186dd52 Mon Sep 17 00:00:00 2001 From: martin rudalics Date: Tue, 22 Sep 2020 16:44:15 +0200 Subject: Make delete-pair only delete pairs that are part of insert-pair-alist * lisp/emacs-lisp/lisp.el (delete-pair): Only delete pairs that are part of `insert-pair-alist' (bug#4136). --- lisp/emacs-lisp/lisp.el | 37 +++++++++++++++++++++++++++++++------ test/lisp/emacs-lisp/lisp-tests.el | 3 +-- 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 8c18557c79a..ac4ba788972 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -735,12 +735,37 @@ This command assumes point is not in a string or comment." (insert-pair arg ?\( ?\))) (defun delete-pair (&optional arg) - "Delete a pair of characters enclosing ARG sexps following point. -A negative ARG deletes a pair of characters around preceding ARG sexps." - (interactive "p") - (unless arg (setq arg 1)) - (save-excursion (forward-sexp arg) (delete-char (if (> arg 0) -1 1))) - (delete-char (if (> arg 0) 1 -1))) + "Delete a pair of characters enclosing ARG sexps that follow point. +A negative ARG deletes a pair around the preceding ARG sexps instead." + (interactive "P") + (if arg + (setq arg (prefix-numeric-value arg)) + (setq arg 1)) + (if (< arg 0) + (save-excursion + (skip-chars-backward " \t") + (save-excursion + (let ((close-char (char-before))) + (forward-sexp arg) + (unless (member (list (char-after) close-char) + (mapcar (lambda (p) + (if (= (length p) 3) (cdr p) p)) + insert-pair-alist)) + (error "Not after matching pair")) + (delete-char 1))) + (delete-char -1)) + (save-excursion + (skip-chars-forward " \t") + (save-excursion + (let ((open-char (char-after))) + (forward-sexp arg) + (unless (member (list open-char (char-before)) + (mapcar (lambda (p) + (if (= (length p) 3) (cdr p) p)) + insert-pair-alist)) + (error "Not before matching pair")) + (delete-char -1))) + (delete-char 1)))) (defun raise-sexp (&optional arg) "Raise ARG sexps higher up the tree." diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el index a2b8304c96a..1476574552f 100644 --- a/test/lisp/emacs-lisp/lisp-tests.el +++ b/test/lisp/emacs-lisp/lisp-tests.el @@ -136,8 +136,7 @@ (text-mode) (insert "\"foo\"") (goto-char (point-min)) - (delete-pair) - (should (string-equal "fo\"" (buffer-string))))) + (should-error (delete-pair)))) (ert-deftest lisp-delete-pair-quotes-text-mode-syntax-table () "Test \\[delete-pair] with modified Text Mode syntax for #15014." -- cgit v1.2.3 From df0f32f04850e7ed106a225addfa82f1b5b91f45 Mon Sep 17 00:00:00 2001 From: Mattias Engdegård Date: Fri, 18 Sep 2020 12:49:33 +0200 Subject: Don't signal scan-error when moving by sexp interactively * lisp/emacs-lisp/lisp.el (forward-sexp, backward-sexp, forward-list) (backward-list, down-list, up-list, mark-sexp, kill-sexp) (backward-kill-sexp): Remove unsightly scan-error when running interactively and no further movement by sexp can be made (bug#43489). --- lisp/emacs-lisp/lisp.el | 140 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 45 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index ac4ba788972..ba78d7f9b39 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -55,7 +55,7 @@ This affects `insert-parentheses' and `insert-pair'." "If non-nil, `forward-sexp' delegates to this function. Should take the same arguments and behave similarly to `forward-sexp'.") -(defun forward-sexp (&optional arg) +(defun forward-sexp (&optional arg user-error) "Move forward across one balanced expression (sexp). With ARG, do it that many times. Negative arg -N means move backward across N balanced expressions. This command assumes @@ -64,23 +64,32 @@ point is not in a string or comment. Calls If unable to move over a sexp, signal `scan-error' with three arguments: a message, the start of the obstacle (usually a parenthesis or list marker of some kind), and end of the -obstacle." - (interactive "^p") - (or arg (setq arg 1)) - (if forward-sexp-function - (funcall forward-sexp-function arg) - (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) - (if (< arg 0) (backward-prefix-chars)))) - -(defun backward-sexp (&optional arg) +obstacle. If USER-ERROR is non-nil, as it is interactively, +report errors as appropriate for an interactive command." + (interactive "^p\nd") + (if user-error + (condition-case _ + (forward-sexp arg nil) + (scan-error (user-error (if (> arg 0) + "No next sexp" + "No previous sexp")))) + (or arg (setq arg 1)) + (if forward-sexp-function + (funcall forward-sexp-function arg) + (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) + (if (< arg 0) (backward-prefix-chars))))) + +(defun backward-sexp (&optional arg user-error) "Move backward across one balanced expression (sexp). With ARG, do it that many times. Negative arg -N means move forward across N balanced expressions. This command assumes point is not in a string or comment. -Uses `forward-sexp' to do the work." - (interactive "^p") +Uses `forward-sexp' to do the work. +If USER-ERROR is non-nil, as it is interactively, +report errors as appropriate for an interactive command." + (interactive "^p\nd") (or arg (setq arg 1)) - (forward-sexp (- arg))) + (forward-sexp (- arg) user-error)) (defun mark-sexp (&optional arg allow-extend) "Set mark ARG sexps from point. @@ -99,50 +108,78 @@ This command assumes point is not in a string or comment." (set-mark (save-excursion (goto-char (mark)) - (forward-sexp arg) + (condition-case error + (forward-sexp arg) + (scan-error + (user-error (if (equal (cadr error) + "Containing expression ends prematurely") + "No more sexp to select" + (cadr error))))) (point)))) (t (push-mark (save-excursion - (forward-sexp (prefix-numeric-value arg)) + (condition-case error + (forward-sexp (prefix-numeric-value arg)) + (scan-error + (user-error (if (equal (cadr error) + "Containing expression ends prematurely") + "No sexp to select" + (cadr error))))) (point)) nil t)))) -(defun forward-list (&optional arg) +(defun forward-list (&optional arg user-error) "Move forward across one balanced group of parentheses. This command will also work on other parentheses-like expressions defined by the current language mode. With ARG, do it that many times. Negative arg -N means move backward across N groups of parentheses. -This command assumes point is not in a string or comment." - (interactive "^p") - (or arg (setq arg 1)) - (goto-char (or (scan-lists (point) arg 0) (buffer-end arg)))) - -(defun backward-list (&optional arg) +This command assumes point is not in a string or comment. +If USER-ERROR is non-nil, as it is interactively, +report errors as appropriate for an interactive command." + (interactive "^p\nd") + (if user-error + (condition-case _ + (forward-list arg nil) + (scan-error (user-error (if (> arg 0) + "No next group" + "No previous group")))) + (or arg (setq arg 1)) + (goto-char (or (scan-lists (point) arg 0) (buffer-end arg))))) + +(defun backward-list (&optional arg user-error) "Move backward across one balanced group of parentheses. This command will also work on other parentheses-like expressions defined by the current language mode. With ARG, do it that many times. Negative arg -N means move forward across N groups of parentheses. -This command assumes point is not in a string or comment." - (interactive "^p") +This command assumes point is not in a string or comment. +If USER-ERROR is non-nil, as it is interactively, +report errors as appropriate for an interactive command." + (interactive "^p\nd") (or arg (setq arg 1)) - (forward-list (- arg))) + (forward-list (- arg) user-error)) -(defun down-list (&optional arg) +(defun down-list (&optional arg user-error) "Move forward down one level of parentheses. This command will also work on other parentheses-like expressions defined by the current language mode. With ARG, do this that many times. A negative argument means move backward but still go down a level. -This command assumes point is not in a string or comment." - (interactive "^p") - (or arg (setq arg 1)) - (let ((inc (if (> arg 0) 1 -1))) - (while (/= arg 0) - (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) - (setq arg (- arg inc))))) +This command assumes point is not in a string or comment. +If USER-ERROR is non-nil, as it is interactively, +report errors as appropriate for an interactive command." + (interactive "^p\nd") + (if user-error + (condition-case _ + (down-list arg nil) + (scan-error (user-error "At bottom level"))) + (or arg (setq arg 1)) + (let ((inc (if (> arg 0) 1 -1))) + (while (/= arg 0) + (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) + (setq arg (- arg inc)))))) (defun backward-up-list (&optional arg escape-strings no-syntax-crossing) "Move backward out of one level of parentheses. @@ -229,26 +266,39 @@ point is unspecified." (or (< inc 0) (forward-comment 1)) (setf arg (+ arg inc))) - (signal (car err) (cdr err)))))) + (if no-syntax-crossing + ;; Assume called interactively; don't signal an error. + (user-error "At top level") + (signal (car err) (cdr err))))))) (setq arg (- arg inc))))) -(defun kill-sexp (&optional arg) +(defun kill-sexp (&optional arg user-error) "Kill the sexp (balanced expression) following point. With ARG, kill that many sexps after point. Negative arg -N means kill N sexps before point. -This command assumes point is not in a string or comment." - (interactive "p") - (let ((opoint (point))) - (forward-sexp (or arg 1)) - (kill-region opoint (point)))) - -(defun backward-kill-sexp (&optional arg) +This command assumes point is not in a string or comment. +If USER-ERROR is non-nil, as it is interactively, +report errors as appropriate for an interactive command." + (interactive "p\nd") + (if user-error + (condition-case _ + (kill-sexp arg nil) + (scan-error (user-error (if (> arg 0) + "No next sexp" + "No previous sexp")))) + (let ((opoint (point))) + (forward-sexp (or arg 1)) + (kill-region opoint (point))))) + +(defun backward-kill-sexp (&optional arg user-error) "Kill the sexp (balanced expression) preceding point. With ARG, kill that many sexps before point. Negative arg -N means kill N sexps after point. -This command assumes point is not in a string or comment." - (interactive "p") - (kill-sexp (- (or arg 1)))) +This command assumes point is not in a string or comment. +If USER-ERROR is non-nil, as it is interactively, +report errors as appropriate for an interactive command." + (interactive "p\nd") + (kill-sexp (- (or arg 1)) user-error)) ;; After Zmacs: (defun kill-backward-up-list (&optional arg) -- cgit v1.2.3 From 3bfddaec3ac6e545350d30a6db80188537b845ad Mon Sep 17 00:00:00 2001 From: Mattias Engdegård Date: Wed, 23 Sep 2020 18:08:32 +0200 Subject: ; * lisp/emacs-lisp/lisp.el: rename parameter in last change --- lisp/emacs-lisp/lisp.el | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index ba78d7f9b39..35590123ee6 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -55,7 +55,7 @@ This affects `insert-parentheses' and `insert-pair'." "If non-nil, `forward-sexp' delegates to this function. Should take the same arguments and behave similarly to `forward-sexp'.") -(defun forward-sexp (&optional arg user-error) +(defun forward-sexp (&optional arg interactive) "Move forward across one balanced expression (sexp). With ARG, do it that many times. Negative arg -N means move backward across N balanced expressions. This command assumes @@ -64,10 +64,10 @@ point is not in a string or comment. Calls If unable to move over a sexp, signal `scan-error' with three arguments: a message, the start of the obstacle (usually a parenthesis or list marker of some kind), and end of the -obstacle. If USER-ERROR is non-nil, as it is interactively, -report errors as appropriate for an interactive command." +obstacle. If INTERACTIVE is non-nil, as it is interactively, +report errors as appropriate for this kind of usage." (interactive "^p\nd") - (if user-error + (if interactive (condition-case _ (forward-sexp arg nil) (scan-error (user-error (if (> arg 0) @@ -79,17 +79,17 @@ report errors as appropriate for an interactive command." (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) (if (< arg 0) (backward-prefix-chars))))) -(defun backward-sexp (&optional arg user-error) +(defun backward-sexp (&optional arg interactive) "Move backward across one balanced expression (sexp). With ARG, do it that many times. Negative arg -N means move forward across N balanced expressions. This command assumes point is not in a string or comment. Uses `forward-sexp' to do the work. -If USER-ERROR is non-nil, as it is interactively, -report errors as appropriate for an interactive command." +If INTERACTIVE is non-nil, as it is interactively, +report errors as appropriate for this kind of usage." (interactive "^p\nd") (or arg (setq arg 1)) - (forward-sexp (- arg) user-error)) + (forward-sexp (- arg) interactive)) (defun mark-sexp (&optional arg allow-extend) "Set mark ARG sexps from point. @@ -129,17 +129,17 @@ This command assumes point is not in a string or comment." (point)) nil t)))) -(defun forward-list (&optional arg user-error) +(defun forward-list (&optional arg interactive) "Move forward across one balanced group of parentheses. This command will also work on other parentheses-like expressions defined by the current language mode. With ARG, do it that many times. Negative arg -N means move backward across N groups of parentheses. This command assumes point is not in a string or comment. -If USER-ERROR is non-nil, as it is interactively, -report errors as appropriate for an interactive command." +If INTERACTIVE is non-nil, as it is interactively, +report errors as appropriate for this kind of usage." (interactive "^p\nd") - (if user-error + (if interactive (condition-case _ (forward-list arg nil) (scan-error (user-error (if (> arg 0) @@ -148,30 +148,30 @@ report errors as appropriate for an interactive command." (or arg (setq arg 1)) (goto-char (or (scan-lists (point) arg 0) (buffer-end arg))))) -(defun backward-list (&optional arg user-error) +(defun backward-list (&optional arg interactive) "Move backward across one balanced group of parentheses. This command will also work on other parentheses-like expressions defined by the current language mode. With ARG, do it that many times. Negative arg -N means move forward across N groups of parentheses. This command assumes point is not in a string or comment. -If USER-ERROR is non-nil, as it is interactively, -report errors as appropriate for an interactive command." +If INTERACTIVE is non-nil, as it is interactively, +report errors as appropriate for this kind of usage." (interactive "^p\nd") (or arg (setq arg 1)) - (forward-list (- arg) user-error)) + (forward-list (- arg) interactive)) -(defun down-list (&optional arg user-error) +(defun down-list (&optional arg interactive) "Move forward down one level of parentheses. This command will also work on other parentheses-like expressions defined by the current language mode. With ARG, do this that many times. A negative argument means move backward but still go down a level. This command assumes point is not in a string or comment. -If USER-ERROR is non-nil, as it is interactively, -report errors as appropriate for an interactive command." +If INTERACTIVE is non-nil, as it is interactively, +report errors as appropriate for this kind of usage." (interactive "^p\nd") - (if user-error + (if interactive (condition-case _ (down-list arg nil) (scan-error (user-error "At bottom level"))) @@ -272,15 +272,15 @@ point is unspecified." (signal (car err) (cdr err))))))) (setq arg (- arg inc))))) -(defun kill-sexp (&optional arg user-error) +(defun kill-sexp (&optional arg interactive) "Kill the sexp (balanced expression) following point. With ARG, kill that many sexps after point. Negative arg -N means kill N sexps before point. This command assumes point is not in a string or comment. -If USER-ERROR is non-nil, as it is interactively, -report errors as appropriate for an interactive command." +If INTERACTIVE is non-nil, as it is interactively, +report errors as appropriate for this kind of usage." (interactive "p\nd") - (if user-error + (if interactive (condition-case _ (kill-sexp arg nil) (scan-error (user-error (if (> arg 0) @@ -290,15 +290,15 @@ report errors as appropriate for an interactive command." (forward-sexp (or arg 1)) (kill-region opoint (point))))) -(defun backward-kill-sexp (&optional arg user-error) +(defun backward-kill-sexp (&optional arg interactive) "Kill the sexp (balanced expression) preceding point. With ARG, kill that many sexps before point. Negative arg -N means kill N sexps after point. This command assumes point is not in a string or comment. -If USER-ERROR is non-nil, as it is interactively, -report errors as appropriate for an interactive command." +If INTERACTIVE is non-nil, as it is interactively, +report errors as appropriate for this kind of usage." (interactive "p\nd") - (kill-sexp (- (or arg 1)) user-error)) + (kill-sexp (- (or arg 1)) interactive)) ;; After Zmacs: (defun kill-backward-up-list (&optional arg) -- cgit v1.2.3 From 79762ffa618ba0f0b8b4483c1cca8ccb1aab2606 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 25 Sep 2020 14:30:13 +0200 Subject: Mark string-search as being side effect free * lisp/emacs-lisp/byte-opt.el (side-effect-free-fns): Add string-search. --- lisp/emacs-lisp/byte-opt.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 4987596bf95..2c95c870606 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -1173,7 +1173,8 @@ degrees-to-radians radians-to-degrees rassq rassoc read-from-string regexp-quote region-beginning region-end reverse round - sin sqrt string string< string= string-equal string-lessp string-to-char + sin sqrt string string< string= string-equal string-lessp + string-search string-to-char string-to-number substring sxhash sxhash-equal sxhash-eq sxhash-eql symbol-function symbol-name symbol-plist symbol-value string-make-unibyte -- cgit v1.2.3 From 497a1ed8bba528bf4078c80bb00b29870eb01e6f Mon Sep 17 00:00:00 2001 From: Mattias Engdegård Date: Fri, 25 Sep 2020 17:00:17 +0200 Subject: string-search robustness and documentation improvement (bug#43598) * src/fns.c (Fstring_search): Check START-POS argument range. Simplify logic. Improve doc string. * test/src/fns-tests.el (string-search): Add test cases. * doc/lispref/strings.texi (Text Comparison): Elaborate. * lisp/emacs-lisp/byte-opt.el (pure-fns): Mark string-search as pure. --- doc/lispref/strings.texi | 4 +++- lisp/emacs-lisp/byte-opt.el | 1 + src/fns.c | 20 +++++++++++++------- test/src/fns-tests.el | 30 +++++++++++++++++++++++++++++- 4 files changed, 46 insertions(+), 9 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index 6eb3d6f3100..0f157c39d63 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi @@ -660,8 +660,10 @@ ignores case differences. Return the position of the first instance of @var{needle} in @var{haystack}, both of which are strings. If @var{start-pos} is non-@code{nil}, start searching from that position in @var{needle}. +Return @code{nil} if no match was found. This function only considers the characters in the strings when doing -the comparison; text properties are ignored. +the comparison; text properties are ignored. Matching is always +case-sensitive. @end defun @defun compare-strings string1 start1 end1 string2 start2 end2 &optional ignore-case diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 2c95c870606..8a6c0b9a7fa 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -1264,6 +1264,7 @@ floor ceiling round truncate ffloor fceiling fround ftruncate string= string-equal string< string-lessp + string-search consp atom listp nlistp propert-list-p sequencep arrayp vectorp stringp bool-vector-p hash-table-p null not diff --git a/src/fns.c b/src/fns.c index 3927e4306e6..2f64d955760 100644 --- a/src/fns.c +++ b/src/fns.c @@ -5456,15 +5456,18 @@ It should not be used for anything security-related. See DEFUN ("string-search", Fstring_search, Sstring_search, 2, 3, 0, doc: /* Search for the string NEEDLE in the string HAYSTACK. -The return value is the position of the first instance of NEEDLE in -HAYSTACK. +The return value is the position of the first occurrence of NEEDLE in +HAYSTACK, or nil if no match was found. The optional START-POS argument says where to start searching in -HAYSTACK. If not given, start at the beginning. */) +HAYSTACK and defaults to zero (start at the beginning). +It must be between zero and the length of HAYSTACK, inclusive. + +Case is always significant and text properties are ignored. */) (register Lisp_Object needle, Lisp_Object haystack, Lisp_Object start_pos) { ptrdiff_t start_byte = 0, haybytes; - char *res = NULL, *haystart; + char *res, *haystart; CHECK_STRING (needle); CHECK_STRING (haystack); @@ -5472,7 +5475,10 @@ HAYSTACK. If not given, start at the beginning. */) if (!NILP (start_pos)) { CHECK_FIXNUM (start_pos); - start_byte = string_char_to_byte (haystack, XFIXNUM (start_pos)); + EMACS_INT start = XFIXNUM (start_pos); + if (start < 0 || start > SCHARS (haystack)) + xsignal1 (Qargs_out_of_range, start_pos); + start_byte = string_char_to_byte (haystack, start); } haystart = SSDATA (haystack) + start_byte; @@ -5481,13 +5487,13 @@ HAYSTACK. If not given, start at the beginning. */) if (STRING_MULTIBYTE (haystack) == STRING_MULTIBYTE (needle)) res = memmem (haystart, haybytes, SSDATA (needle), SBYTES (needle)); - else if (STRING_MULTIBYTE (haystack) && !STRING_MULTIBYTE (needle)) + else if (STRING_MULTIBYTE (haystack)) /* unibyte needle */ { Lisp_Object multi_needle = string_to_multibyte (needle); res = memmem (haystart, haybytes, SSDATA (multi_needle), SBYTES (multi_needle)); } - else if (!STRING_MULTIBYTE (haystack) && STRING_MULTIBYTE (needle)) + else /* unibyte haystack, multibyte needle */ { Lisp_Object uni_needle = Fstring_as_unibyte (needle); res = memmem (haystart, haybytes, diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 8c2b1300dce..323743d8420 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -907,6 +907,12 @@ (should (equal (string-search "foo" "foobarzot") 0)) (should (not (string-search "fooz" "foobarzot"))) (should (not (string-search "zot" "foobarzo"))) + (should (equal (string-search "ab" "ab") 0)) + (should (equal (string-search "ab\0" "ab") nil)) + (should (equal (string-search "ab" "abababab" 3) 4)) + (should (equal (string-search "ab" "ababac" 3) nil)) + (let ((case-fold-search t)) + (should (equal (string-search "ab" "AB") nil))) (should (equal (string-search (make-string 2 130) @@ -923,4 +929,26 @@ (should (not (string-search (make-string 1 255) "a\377ø"))) (should (not (string-search (make-string 1 255) "a\377a"))) - (should (equal (string-search "fóo" "zotfóo") 3))) + (should (equal (string-search "fóo" "zotfóo") 3)) + + (should (equal (string-search (string-to-multibyte "\377") "ab\377c") 2)) + (should (equal (string-search "\303" "aøb") nil)) + (should (equal (string-search "\270" "aøb") nil)) + ;; This test currently fails, but it shouldn't! + ;;(should (equal (string-search "ø" "\303\270") nil)) + + (should-error (string-search "a" "abc" -1)) + (should-error (string-search "a" "abc" 4)) + (should-error (string-search "a" "abc" 100000000000)) + + (should (equal (string-search "a" "aaa" 3) nil)) + (should (equal (string-search "\0" "") nil)) + + (should (equal (string-search "" "") 0)) + (should-error (string-search "" "" 1)) + (should (equal (string-search "" "abc") 0)) + (should (equal (string-search "" "abc" 2) 2)) + (should (equal (string-search "" "abc" 3) 3)) + (should-error (string-search "" "abc" 4)) + (should-error (string-search "" "abc" -1)) + ) -- cgit v1.2.3