diff options
author | Mattias Engdegård <mattiase@acm.org> | 2020-09-25 17:00:17 +0200 |
---|---|---|
committer | Mattias Engdegård <mattiase@acm.org> | 2020-09-25 17:08:00 +0200 |
commit | 497a1ed8bba528bf4078c80bb00b29870eb01e6f (patch) | |
tree | 55aec2280ff0b5cf281838ba3260cd2df41d955d /test/src/fns-tests.el | |
parent | 499848d8407855d8ca24f0c175c602a0f24da074 (diff) | |
download | emacs-497a1ed8bba528bf4078c80bb00b29870eb01e6f.tar.gz |
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.
Diffstat (limited to 'test/src/fns-tests.el')
-rw-r--r-- | test/src/fns-tests.el | 30 |
1 files changed, 29 insertions, 1 deletions
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)) + ) |