comparison tests/automated/search-tests.el @ 4897:91a023144e72

fix longstanding search bug involving searching for Control-1 chars -------------------- ChangeLog entries follow: -------------------- src/ChangeLog addition: 2010-01-29 Ben Wing <ben@xemacs.org> * search.c (boyer_moore): Fix longstanding bug involving searching for Control-1 chars; code was trying to directly extract the last byte in the textual representation of a char from an Ichar (and doing it in a buggy fashion) rather than just converting the Ichar to text and looking at the last byte. tests/ChangeLog addition: 2010-01-29 Ben Wing <ben@xemacs.org> * automated/search-tests.el: New file. * automated/search-tests.el: * automated/case-tests.el: * automated/case-tests.el (pristine-case-table): Removed. * automated/case-tests.el (uni-mappings): * automated/lisp-tests.el: * automated/regexp-tests.el: Extract some search-related code from case-tests and regexp-tests and move to search-tests. Move some regexp-related code from lisp-tests to regexp-tests. Write a comment trying to express the proper division of labor between case-tests, search-tests and regexp-tests. Add a new test for the Control-1 search bug. Fix a buggy test in the Unicode torture-test section of case-tests.el.
author Ben Wing <ben@xemacs.org>
date Fri, 29 Jan 2010 20:57:42 -0600
parents
children c902301f8b7d
comparison
equal deleted inserted replaced
4896:a7ab1d6ff301 4897:91a023144e72
1 ;;; -*- coding: iso-8859-1 -*-
2
3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
4 ;; Copyright (C) 2010 Ben Wing.
5
6 ;; Author: Yoshiki Hayashi <yoshiki@xemacs.org>
7 ;; Maintainer: Yoshiki Hayashi <yoshiki@xemacs.org>
8 ;; Created: 2000
9 ;; Keywords: tests
10
11 ;; This file is part of XEmacs.
12
13 ;; XEmacs is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; XEmacs is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 ;; 02111-1307, USA.
27
28 ;;; Synched up with: Not in FSF.
29
30 ;;; Commentary:
31
32 ;; Test of non-regexp searching.
33
34 ;; Split out of case-tests.el.
35
36 ;; NOTE NOTE NOTE: See also:
37 ;;
38 ;; (1) regexp-tests.el, for regexp searching.
39 ;; (2) case-tests.el, for some case-related searches.
40
41 ;; NOTE NOTE NOTE: There is some domain overlap among regexp-tests.el,
42 ;; search-tests.el and case-tests.el. The current rule for what goes where
43 ;; is:
44 ;;
45 ;; (1) Anything regexp-related goes in regexp-tests.el, including searches.
46 ;; (2) Non-regexp searches go in search-tests.el. This includes case-folding
47 ;; searches in the situation where the test tests both folding and
48 ;; non-folding behavior.
49 ;; (3) If it tests specifically case-folding search behavior, it may go in
50 ;; case-tets.el, especially if it is testing something non-search-related
51 ;; at the same time (e.g. the Unicode case map torture tests).
52
53 (with-temp-buffer
54 (insert "Test Buffer")
55 (let ((case-fold-search t))
56 (goto-char (point-min))
57 (Assert-eq (search-forward "test buffer" nil t) 12)
58 (goto-char (point-min))
59 (Assert-eq (search-forward "Test buffer" nil t) 12)
60 (goto-char (point-min))
61 (Assert-eq (search-forward "Test Buffer" nil t) 12)
62
63 (setq case-fold-search nil)
64 (goto-char (point-min))
65 (Assert (not (search-forward "test buffer" nil t)))
66 (goto-char (point-min))
67 (Assert (not (search-forward "Test buffer" nil t)))
68 (goto-char (point-min))
69 (Assert-eq (search-forward "Test Buffer" nil t) 12)))
70
71 (with-temp-buffer
72 (insert "abcdefghijklmnäopqrstuÄvwxyz")
73 ;; case insensitive
74 (Assert (not (search-forward "ö" nil t)))
75 (goto-char (point-min))
76 (Assert-eq 16 (search-forward "ä" nil t))
77 (Assert-eq 24 (search-forward "ä" nil t))
78 (goto-char (point-min))
79 (Assert-eq 16 (search-forward "Ä" nil t))
80 (Assert-eq 24 (search-forward "Ä" nil t))
81 (goto-char (point-max))
82 (Assert-eq 23 (search-backward "ä" nil t))
83 (Assert-eq 15 (search-backward "ä" nil t))
84 (goto-char (point-max))
85 (Assert-eq 23 (search-backward "Ä" nil t))
86 (Assert-eq 15 (search-backward "Ä" nil t))
87 ;; case sensitive
88 (setq case-fold-search nil)
89 (goto-char (point-min))
90 (Assert (not (search-forward "ö" nil t)))
91 (goto-char (point-min))
92 (Assert-eq 16 (search-forward "ä" nil t))
93 (Assert (not (search-forward "ä" nil t)))
94 (goto-char (point-min))
95 (Assert-eq 24 (search-forward "Ä" nil t))
96 (goto-char 16)
97 (Assert-eq 24 (search-forward "Ä" nil t))
98 (goto-char (point-max))
99 (Assert-eq 15 (search-backward "ä" nil t))
100 (goto-char 15)
101 (Assert (not (search-backward "ä" nil t)))
102 (goto-char (point-max))
103 (Assert-eq 23 (search-backward "Ä" nil t))
104 (Assert (not (search-backward "Ä" nil t))))
105
106 (with-temp-buffer
107 (insert "aaaaäÄäÄäÄäÄäÄbbbb")
108 (goto-char (point-min))
109 (Assert-eq 15 (search-forward "ää" nil t 5))
110 (goto-char (point-min))
111 (Assert (not (search-forward "ää" nil t 6)))
112 (goto-char (point-max))
113 (Assert-eq 5 (search-backward "ää" nil t 5))
114 (goto-char (point-max))
115 (Assert (not (search-backward "ää" nil t 6))))
116
117 (when (featurep 'mule)
118 (let* ((hiragana-a (make-char 'japanese-jisx0208 36 34))
119 (a-diaeresis ?ä)
120 (case-table (copy-case-table (standard-case-table)))
121 (str-hiragana-a (char-to-string hiragana-a))
122 (str-a-diaeresis (char-to-string a-diaeresis))
123 (string (concat str-hiragana-a str-a-diaeresis)))
124 (put-case-table-pair hiragana-a a-diaeresis case-table)
125 (with-temp-buffer
126 (set-case-table case-table)
127 (insert hiragana-a "abcdefg" a-diaeresis)
128 ;; forward
129 (goto-char (point-min))
130 (Assert (not (search-forward "ö" nil t)))
131 (goto-char (point-min))
132 (Assert-eq 2 (search-forward str-hiragana-a nil t))
133 (goto-char (point-min))
134 (Assert-eq 2 (search-forward str-a-diaeresis nil t))
135 (goto-char (1+ (point-min)))
136 (Assert-eq (point-max)
137 (search-forward str-hiragana-a nil t))
138 (goto-char (1+ (point-min)))
139 (Assert-eq (point-max)
140 (search-forward str-a-diaeresis nil t))
141 ;; backward
142 (goto-char (point-max))
143 (Assert (not (search-backward "ö" nil t)))
144 (goto-char (point-max))
145 (Assert-eq (1- (point-max)) (search-backward str-hiragana-a nil t))
146 (goto-char (point-max))
147 (Assert-eq (1- (point-max)) (search-backward str-a-diaeresis nil t))
148 (goto-char (1- (point-max)))
149 (Assert-eq 1 (search-backward str-hiragana-a nil t))
150 (goto-char (1- (point-max)))
151 (Assert-eq 1 (search-backward str-a-diaeresis nil t))
152 (replace-match "a")
153 (Assert (looking-at (format "abcdefg%c" a-diaeresis))))
154 (with-temp-buffer
155 (set-case-table case-table)
156 (insert string)
157 (insert string)
158 (insert string)
159 (insert string)
160 (insert string)
161 (goto-char (point-min))
162 (Assert-eq 11 (search-forward string nil t 5))
163 (goto-char (point-min))
164 (Assert (not (search-forward string nil t 6)))
165 (goto-char (point-max))
166 (Assert-eq 1 (search-backward string nil t 5))
167 (goto-char (point-max))
168 (Assert (not (search-backward string nil t 6))))))
169
170 ;; Bug reported in http://mid.gmane.org/y9lk5lu5orq.fsf@deinprogramm.de from
171 ;; Michael Sperber. Fixed 2008-01-29.
172 (with-string-as-buffer-contents "\n\nDer beruhmte deutsche Flei\xdf\n\n"
173 (goto-char (point-min))
174 (Assert (search-forward "Flei\xdf")))
175
176 (with-temp-buffer
177 (let ((target "M\xe9zard")
178 (debug-xemacs-searches 1))
179 (Assert (not (search-forward target nil t)))
180 (insert target)
181 (goto-char (point-min))
182 ;; #### search-algorithm-used is simple-search after the following,
183 ;; which shouldn't be necessary; it should be possible to use
184 ;; Boyer-Moore.
185 ;;
186 ;; But searches for ASCII strings in buffers with nothing above ?\xFF
187 ;; use Boyer Moore with the current implementation, which is the
188 ;; important thing for the Gnus use case.
189 (Assert= (1+ (length target)) (search-forward target nil t))))
190
191 (Skip-Test-Unless
192 (boundp 'debug-xemacs-searches) ; normal when we have DEBUG_XEMACS
193 "not a DEBUG_XEMACS build"
194 "checks that the algorithm chosen by #'search-forward is relatively sane"
195 (let ((debug-xemacs-searches 1))
196 (with-temp-buffer
197 ;;#### Ben thinks this is unnecessary. with-temp-buffer creates
198 ;;a new buffer, which automatically inherits the standard case table.
199 ;;(set-case-table pristine-case-table)
200 (insert "\n\nDer beruhmte deutsche Fleiss\n\n")
201 (goto-char (point-min))
202 (Assert (search-forward "Fleiss"))
203 (delete-region (point-min) (point-max))
204 (insert "\n\nDer beruhmte deutsche Flei\xdf\n\n")
205 (goto-char (point-min))
206 (Assert (search-forward "Flei\xdf"))
207 (Assert-eq 'boyer-moore search-algorithm-used)
208 (delete-region (point-min) (point-max))
209 (when (featurep 'mule)
210 (insert "\n\nDer beruhmte deutsche Flei\xdf\n\n")
211 (goto-char (point-min))
212 (Assert
213 (search-forward (format "Fle%c\xdf"
214 (make-char 'latin-iso8859-9 #xfd))))
215 (Assert-eq 'boyer-moore search-algorithm-used)
216 (insert (make-char 'latin-iso8859-9 #xfd))
217 (goto-char (point-min))
218 (Assert (search-forward "Flei\xdf"))
219 (Assert-eq 'simple-search search-algorithm-used)
220 (goto-char (point-min))
221 (Assert (search-forward (format "Fle%c\xdf"
222 (make-char 'latin-iso8859-9 #xfd))))
223 (Assert-eq 'simple-search search-algorithm-used)))))
224
225
226 ;; XEmacs bug of long standing.
227
228 (with-temp-buffer
229 (insert "foo\201bar")
230 (goto-char (point-min))
231 (Assert-eq (search-forward "\201" nil t) 5))