aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJuri Linkov2022-07-08 20:58:33 +0300
committerJuri Linkov2022-07-08 20:58:33 +0300
commitdf157953612910e26cab7d1aa31b7ac5cd58d945 (patch)
tree8f64756254abf183e584a9e84e5591980769994b /test
parent3cfac1fe073815bdbba96e3a35a1c15626022c07 (diff)
downloademacs-df157953612910e26cab7d1aa31b7ac5cd58d945.tar.gz
emacs-df157953612910e26cab7d1aa31b7ac5cd58d945.zip
* lisp/isearch.el (isearch-search-fun-in-noncontiguous-region): New function.
(isearch-search-fun-in-text-property): Refactor body to 'search-within-boundaries', then call it (bug#14013). (search-within-boundaries): New function refactored from isearch-search-fun-in-text-property. * test/lisp/isearch-tests.el: Add tests for new search functions. (isearch--test-search-within-boundaries): New function. (isearch--test-search-fun-in-text-property) (isearch--test-search-fun-in-noncontiguous-region): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/isearch-tests.el80
1 files changed, 80 insertions, 0 deletions
diff --git a/test/lisp/isearch-tests.el b/test/lisp/isearch-tests.el
index 4600757d940..8cb5e5e4542 100644
--- a/test/lisp/isearch-tests.el
+++ b/test/lisp/isearch-tests.el
@@ -38,5 +38,85 @@
38 ;; Bug #21091: let `isearch-done' work without `isearch-update'. 38 ;; Bug #21091: let `isearch-done' work without `isearch-update'.
39 (isearch-done)) 39 (isearch-done))
40 40
41
42;; Search functions.
43
44(defun isearch--test-search-within-boundaries (pairs)
45 (goto-char (point-min))
46 (let ((isearch-forward t)
47 (isearch-regexp nil))
48 (dolist (pos (append pairs nil))
49 (should (eq (cdr pos) (isearch-search-string "foo" nil t)))
50 (should (equal (match-string 0) "foo"))
51 (when (car pos) (should (eq (car pos) (match-beginning 0))))))
52
53 (goto-char (point-max))
54 (let ((isearch-forward nil)
55 (isearch-regexp nil))
56 (dolist (pos (append (reverse pairs) nil))
57 (should (eq (car pos) (isearch-search-string "foo" nil t)))
58 (should (equal (match-string 0) "foo"))
59 (when (cdr pos) (should (eq (cdr pos) (match-end 0))))))
60
61 (goto-char (point-min))
62 (let ((isearch-forward t)
63 (isearch-regexp t))
64 (dolist (pos (append pairs nil))
65 (should (eq (cdr pos) (isearch-search-string ".*" nil t)))
66 (should (equal (match-string 0) "foo"))
67 (when (car pos) (should (eq (car pos) (match-beginning 0))))))
68
69 (goto-char (point-min))
70 (let ((isearch-forward t)
71 (isearch-regexp t))
72 (dolist (pos (append pairs nil))
73 (should (eq (cdr pos) (isearch-search-string "^.*" nil t)))
74 (should (equal (match-string 0) "foo"))
75 (when (car pos) (should (eq (car pos) (match-beginning 0))))))
76
77 (goto-char (point-min))
78 (let ((isearch-forward t)
79 (isearch-regexp t))
80 (dolist (pos (append pairs nil))
81 (should (eq (cdr pos) (isearch-search-string ".*$" nil t)))
82 (should (equal (match-string 0) "foo"))
83 (when (car pos) (should (eq (car pos) (match-beginning 0))))))
84
85 (goto-char (point-max))
86 (let ((isearch-forward nil)
87 (isearch-regexp t))
88 (dolist (pos (append (reverse pairs) nil))
89 (should (eq (car pos) (isearch-search-string "^.*" nil t)))
90 (should (equal (match-string 0) "foo"))
91 (when (cdr pos) (should (eq (cdr pos) (match-end 0))))))
92
93 (goto-char (point-max))
94 (let ((isearch-forward nil)
95 (isearch-regexp t))
96 (dolist (pos (append (reverse pairs) nil))
97 (should (eq (car pos) (isearch-search-string "foo$" nil t)))
98 (should (equal (match-string 0) "foo"))
99 (when (cdr pos) (should (eq (cdr pos) (match-end 0)))))))
100
101(ert-deftest isearch--test-search-fun-in-text-property ()
102 (let* ((pairs '((4 . 7) (11 . 14) (21 . 24)))
103 (isearch-search-fun-function
104 (lambda () (isearch-search-fun-in-text-property nil 'dired-filename))))
105 (with-temp-buffer
106 (insert "foo" (propertize "foo" 'dired-filename t) "foo\n")
107 (insert (propertize "foo" 'dired-filename t) "foo\n")
108 (insert "foo" (propertize "foo" 'dired-filename t) "\n")
109 (isearch--test-search-within-boundaries pairs))))
110
111(ert-deftest isearch--test-search-fun-in-noncontiguous-region ()
112 (let* ((pairs '((4 . 7) (11 . 14) (21 . 24)))
113 (isearch-search-fun-function
114 (lambda () (isearch-search-fun-in-noncontiguous-region nil pairs))))
115 (with-temp-buffer
116 (insert "foofoofoo\n")
117 (insert "foofoo\n")
118 (insert "foofoo\n")
119 (isearch--test-search-within-boundaries pairs))))
120
41(provide 'isearch-tests) 121(provide 'isearch-tests)
42;;; isearch-tests.el ends here 122;;; isearch-tests.el ends here