diff options
| author | Mattias Engdegård | 2020-09-25 17:00:17 +0200 |
|---|---|---|
| committer | Mattias Engdegård | 2020-09-25 17:08:00 +0200 |
| commit | 497a1ed8bba528bf4078c80bb00b29870eb01e6f (patch) | |
| tree | 55aec2280ff0b5cf281838ba3260cd2df41d955d /test/src | |
| parent | 499848d8407855d8ca24f0c175c602a0f24da074 (diff) | |
| download | emacs-497a1ed8bba528bf4078c80bb00b29870eb01e6f.tar.gz emacs-497a1ed8bba528bf4078c80bb00b29870eb01e6f.zip | |
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')
| -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 @@ | |||
| 907 | (should (equal (string-search "foo" "foobarzot") 0)) | 907 | (should (equal (string-search "foo" "foobarzot") 0)) |
| 908 | (should (not (string-search "fooz" "foobarzot"))) | 908 | (should (not (string-search "fooz" "foobarzot"))) |
| 909 | (should (not (string-search "zot" "foobarzo"))) | 909 | (should (not (string-search "zot" "foobarzo"))) |
| 910 | (should (equal (string-search "ab" "ab") 0)) | ||
| 911 | (should (equal (string-search "ab\0" "ab") nil)) | ||
| 912 | (should (equal (string-search "ab" "abababab" 3) 4)) | ||
| 913 | (should (equal (string-search "ab" "ababac" 3) nil)) | ||
| 914 | (let ((case-fold-search t)) | ||
| 915 | (should (equal (string-search "ab" "AB") nil))) | ||
| 910 | 916 | ||
| 911 | (should (equal | 917 | (should (equal |
| 912 | (string-search (make-string 2 130) | 918 | (string-search (make-string 2 130) |
| @@ -923,4 +929,26 @@ | |||
| 923 | (should (not (string-search (make-string 1 255) "a\377ø"))) | 929 | (should (not (string-search (make-string 1 255) "a\377ø"))) |
| 924 | (should (not (string-search (make-string 1 255) "a\377a"))) | 930 | (should (not (string-search (make-string 1 255) "a\377a"))) |
| 925 | 931 | ||
| 926 | (should (equal (string-search "fóo" "zotfóo") 3))) | 932 | (should (equal (string-search "fóo" "zotfóo") 3)) |
| 933 | |||
| 934 | (should (equal (string-search (string-to-multibyte "\377") "ab\377c") 2)) | ||
| 935 | (should (equal (string-search "\303" "aøb") nil)) | ||
| 936 | (should (equal (string-search "\270" "aøb") nil)) | ||
| 937 | ;; This test currently fails, but it shouldn't! | ||
| 938 | ;;(should (equal (string-search "ø" "\303\270") nil)) | ||
| 939 | |||
| 940 | (should-error (string-search "a" "abc" -1)) | ||
| 941 | (should-error (string-search "a" "abc" 4)) | ||
| 942 | (should-error (string-search "a" "abc" 100000000000)) | ||
| 943 | |||
| 944 | (should (equal (string-search "a" "aaa" 3) nil)) | ||
| 945 | (should (equal (string-search "\0" "") nil)) | ||
| 946 | |||
| 947 | (should (equal (string-search "" "") 0)) | ||
| 948 | (should-error (string-search "" "" 1)) | ||
| 949 | (should (equal (string-search "" "abc") 0)) | ||
| 950 | (should (equal (string-search "" "abc" 2) 2)) | ||
| 951 | (should (equal (string-search "" "abc" 3) 3)) | ||
| 952 | (should-error (string-search "" "abc" 4)) | ||
| 953 | (should-error (string-search "" "abc" -1)) | ||
| 954 | ) | ||