Mercurial > hg > xemacs-beta
annotate tests/automated/regexp-tests.el @ 4504:b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
tests/ChangeLog addition:
2008-08-27 Aidan Kehoe <kehoea@parhasard.net>
* automated/regexp-tests.el:
Add a few basic #'skip-chars-forward, #'skip-chars-backward
tests.
lisp/ChangeLog addition:
2008-08-27 Aidan Kehoe <kehoea@parhasard.net>
* subr.el (skip-chars-quote):
Correct the implementation, following the docstring of
#'skip-char-forward more closely rather than the documentation of
character classes in the Lispref.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 27 Aug 2008 21:47:21 +0200 |
parents | 3660d327399f |
children | 5e8f6469169f |
rev | line source |
---|---|
446 | 1 ;;; -*- coding: iso-8859-1 -*- |
2 | |
1612 | 3 ;; Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc. |
446 | 4 |
5 ;; Author: Yoshiki Hayashi <yoshiki@xemacs.org> | |
1612 | 6 ;; Maintainer: Stephen J. Turnbull <stephen@xemacs.org> |
446 | 7 ;; Created: 2000 |
8 ;; Keywords: tests | |
9 | |
10 ;; This file is part of XEmacs. | |
11 | |
12 ;; XEmacs is free software; you can redistribute it and/or modify it | |
13 ;; under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; XEmacs is distributed in the hope that it will be useful, but | |
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 ;; General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
25 ;; 02111-1307, USA. | |
26 | |
27 ;;; Synched up with: Not in FSF. | |
28 | |
29 ;;; Commentary: | |
30 | |
31 ;; Test regular expression. | |
32 | |
33 (Check-Error-Message error "Trailing backslash" | |
34 (string-match "\\" "a")) | |
35 (Check-Error-Message error "Invalid preceding regular expression" | |
36 (string-match "a++" "a")) | |
37 (Check-Error-Message error "Invalid preceding regular expression" | |
38 (string-match "a**" "a")) | |
39 (Check-Error-Message error "Invalid preceding regular expression" | |
40 (string-match "a???" "a")) | |
41 (Check-Error-Message error "Unmatched \\[ or \\[^" | |
42 (string-match "[" "a")) | |
43 (Check-Error-Message error "Unmatched \\[ or \\[^" | |
44 (string-match "[abc" "a")) | |
45 (Check-Error-Message error "Unmatched ) or \\\\)" | |
46 (string-match "\\)" "a")) | |
47 (Check-Error-Message error "Invalid regular expression" | |
48 (string-match "\\(?.\\)" "a")) | |
49 (Check-Error-Message error "Unmatched \\\\{" | |
50 (string-match "a\\{" "a")) | |
51 (Check-Error-Message error "Invalid content of \\\\{\\\\}" | |
52 (string-match "a\\{a\\}" "a")) | |
53 | |
54 ;; exactn | |
55 | |
56 ;; string-match | |
57 (with-temp-buffer | |
58 ;; case-insensitive | |
59 (Assert (string-match "ä" "ä")) | |
60 (Assert (string-match "ä" "Ä")) | |
61 (Assert (string-match "Ä" "Ä")) | |
62 (Assert (string-match "Ä" "ä")) | |
63 ;; case-sensitive | |
64 (setq case-fold-search nil) | |
65 (Assert (string-match "ä" "ä")) | |
66 (Assert (not (string-match "ä" "Ä"))) | |
67 (Assert (string-match "Ä" "Ä")) | |
68 (Assert (not (string-match "Ä" "ä")))) | |
69 | |
70 ;; looking-at | |
71 (with-temp-buffer | |
72 (insert "äÄ") | |
73 ;; case-insensitive | |
74 (goto-char (point-min)) | |
75 (Assert (looking-at "ä")) | |
76 (Assert (looking-at "Ä")) | |
77 (forward-char) | |
78 (Assert (looking-at "ä")) | |
79 (Assert (looking-at "Ä")) | |
80 ;; case-sensitive | |
81 (setq case-fold-search nil) | |
82 (goto-char (point-min)) | |
83 (Assert (looking-at "ä")) | |
84 (Assert (not (looking-at "Ä"))) | |
85 (forward-char) | |
86 (Assert (not (looking-at "ä"))) | |
87 (Assert (looking-at "Ä"))) | |
88 | |
89 ;; re-search-forward and re-search-backward | |
90 (with-temp-buffer | |
91 (insert "äÄ") | |
92 ;; case insensitive | |
93 ;; forward | |
94 (goto-char (point-min)) | |
95 ;; Avoid trivial regexp. | |
96 (Assert (eq 2 (re-search-forward "ä\\|a" nil t))) | |
97 (goto-char (point-min)) | |
98 (Assert (eq 2 (re-search-forward "Ä\\|a" nil t))) | |
99 (goto-char (1+ (point-min))) | |
100 (Assert (eq 3 (re-search-forward "ä\\|a" nil t))) | |
101 (goto-char (1+ (point-min))) | |
102 (Assert (eq 3 (re-search-forward "Ä\\|a" nil t))) | |
103 ;; backward | |
104 (goto-char (point-max)) | |
105 (Assert (eq 2 (re-search-backward "ä\\|a" nil t))) | |
106 (goto-char (point-max)) | |
107 (Assert (eq 2 (re-search-backward "Ä\\|a" nil t))) | |
108 (goto-char (1- (point-max))) | |
109 (Assert (eq 1 (re-search-backward "ä\\|a" nil t))) | |
110 (goto-char (1- (point-max))) | |
111 (Assert (eq 1 (re-search-backward "Ä\\|a" nil t))) | |
112 ;; case sensitive | |
113 (setq case-fold-search nil) | |
114 ;; forward | |
115 (goto-char (point-min)) | |
116 (Assert (eq 2 (re-search-forward "ä\\|a" nil t))) | |
117 (goto-char (point-min)) | |
118 (Assert (eq 3 (re-search-forward "Ä\\|a" nil t))) | |
119 (goto-char (1+ (point-min))) | |
120 (Assert (not (re-search-forward "ä\\|a" nil t))) | |
121 (goto-char (1+ (point-min))) | |
122 (Assert (eq 3 (re-search-forward "Ä\\|a" nil t))) | |
123 ;; backward | |
124 (goto-char (point-max)) | |
125 (Assert (eq 1 (re-search-backward "ä\\|a" nil t))) | |
126 (goto-char (point-max)) | |
127 (Assert (eq 2 (re-search-backward "Ä\\|a" nil t))) | |
128 (goto-char (1- (point-max))) | |
129 (Assert (eq 1 (re-search-backward "ä\\|a" nil t))) | |
130 (goto-char (1- (point-max))) | |
131 (Assert (not (re-search-backward "Ä\\|a" nil t)))) | |
132 | |
133 ;; duplicate | |
134 (with-temp-buffer | |
135 ;; case insensitive | |
136 (Assert (string-match "^\\(ä\\)\\1$" "ää")) | |
137 (Assert (string-match "^\\(ä\\)\\1$" "äÄ")) | |
138 (Assert (string-match "^\\(ä\\)\\1$" "ÄÄ")) | |
139 (Assert (string-match "^\\(ä\\)\\1$" "Ää")) | |
140 (Assert (string-match "^\\(Ä\\)\\1$" "ää")) | |
141 (Assert (string-match "^\\(Ä\\)\\1$" "äÄ")) | |
142 (Assert (string-match "^\\(Ä\\)\\1$" "ÄÄ")) | |
143 (Assert (string-match "^\\(Ä\\)\\1$" "Ää")) | |
144 ;; case sensitive | |
145 (setq case-fold-search nil) | |
146 (Assert (string-match "^\\(ä\\)\\1$" "ää")) | |
147 (Assert (not (string-match "^\\(ä\\)\\1$" "äÄ"))) | |
148 (Assert (not (string-match "^\\(ä\\)\\1$" "ÄÄ"))) | |
149 (Assert (not (string-match "^\\(ä\\)\\1$" "Ää"))) | |
150 (Assert (not (string-match "^\\(Ä\\)\\1$" "ää"))) | |
151 (Assert (not (string-match "^\\(Ä\\)\\1$" "äÄ"))) | |
152 (Assert (string-match "^\\(Ä\\)\\1$" "ÄÄ")) | |
153 (Assert (not (string-match "^\\(Ä\\)\\1$" "Ää")))) | |
154 | |
1714 | 155 ;; multiple-match |
156 ;; Thanks to Manfred Bartz <MBartz@xix.com> | |
157 ;; c.e.x <vn4rkkm7ouf3b5@corp.supernews.com> | |
158 ;; #### Need to do repetitions of more complex regexps | |
159 ;; #### WASH ME! | |
160 (with-temp-buffer | |
161 (Assert (not (string-match "^a\\{4,4\\}$" "aaa"))) | |
162 (Assert (string-match "^a\\{4,4\\}$" "aaaa")) | |
163 (Assert (not (string-match "^a\\{4,4\\}$" "aaaaa"))) | |
164 (Assert (not (string-match "^[a]\\{4,4\\}$" "aaa"))) | |
165 (Assert (string-match "^[a]\\{4,4\\}$" "aaaa")) | |
166 (Assert (not (string-match "^[a]\\{4,4\\}$" "aaaaa"))) | |
167 (Assert (not (string-match "^\\(a\\)\\{4,4\\}$" "aaa"))) | |
168 (Assert (string-match "^\\(a\\)\\{4,4\\}$" "aaaa")) | |
169 (Assert (not (string-match "^\\(a\\)\\{4,4\\}$" "aaaaa"))) | |
170 ;; Use class because repetition of single char broken in 21.5.15 | |
171 (Assert (not (string-match "^[a]\\{3,5\\}$" "aa"))) | |
172 (Assert (string-match "^[a]\\{3,5\\}$" "aaa")) | |
173 (Assert (string-match "^[a]\\{3,5\\}$" "aaaa")) | |
174 (Assert (string-match "^[a]\\{3,5\\}$" "aaaaa")) | |
175 (Assert (not (string-match "^[a]\\{3,5\\}$" "aaaaaa"))) | |
176 (insert "\ | |
177 aa | |
178 aaa | |
179 aaaa | |
180 aaaaa | |
181 aaaaaa | |
182 baaaa | |
183 ") | |
184 (goto-char (point-min)) | |
185 (forward-line 1) | |
186 (Assert (not (looking-at "^a\\{4,4\\}$"))) | |
187 (forward-line 1) | |
188 (Assert (looking-at "^a\\{4,4\\}$")) | |
189 (forward-line 1) | |
190 (Assert (not (looking-at "^a\\{4,4\\}$"))) | |
191 (goto-char (point-min)) | |
192 (forward-line 1) | |
193 (Assert (not (looking-at "^[a]\\{4,4\\}$"))) | |
194 (forward-line 1) | |
195 (Assert (looking-at "^[a]\\{4,4\\}$")) | |
196 (forward-line 1) | |
197 (Assert (not (looking-at "^[a]\\{4,4\\}$"))) | |
198 (goto-char (point-min)) | |
199 (forward-line 1) | |
200 (Assert (not (looking-at "^\\(a\\)\\{4,4\\}$"))) | |
201 (forward-line 1) | |
202 (Assert (looking-at "^\\(a\\)\\{4,4\\}$")) | |
203 (forward-line 1) | |
204 (Assert (not (looking-at "^\\(a\\)\\{4,4\\}$"))) | |
205 ;; Use class because repetition of single char broken in 21.5.15 | |
206 (goto-char (point-min)) | |
207 (Assert (not (looking-at "^[a]\\{3,5\\}$"))) | |
208 (forward-line 1) | |
209 (Assert (looking-at "^[a]\\{3,5\\}$")) | |
210 (forward-line 1) | |
211 (Assert (looking-at "^[a]\\{3,5\\}$")) | |
212 (forward-line 1) | |
213 (Assert (looking-at "^[a]\\{3,5\\}$")) | |
214 (forward-line 1) | |
215 (Assert (not (looking-at "^[a]\\{3,5\\}$"))) | |
216 (goto-char (point-min)) | |
217 (Assert (= 12 (re-search-forward "a\\{4,4\\}"))) | |
218 (goto-char (point-min)) | |
219 (Assert (= 12 (re-search-forward "b?a\\{4,4\\}"))) | |
220 (goto-char (point-min)) | |
221 (Assert (= 31 (re-search-forward "ba\\{4,4\\}"))) | |
222 (goto-char (point-min)) | |
223 (Assert (= 31 (re-search-forward "[b]a\\{4,4\\}"))) | |
224 (goto-char (point-min)) | |
225 (Assert (= 31 (re-search-forward "\\(b\\)a\\{4,4\\}"))) | |
226 (goto-char (point-min)) | |
227 (Assert (= 12 (re-search-forward "^a\\{4,4\\}"))) | |
228 (goto-char (point-min)) | |
229 (Assert (= 12 (re-search-forward "^a\\{4,4\\}$"))) | |
230 (goto-char (point-min)) | |
231 (Assert (= 12 (re-search-forward "[a]\\{4,4\\}"))) | |
232 (goto-char (point-min)) | |
233 (Assert (= 12 (re-search-forward "^[a]\\{4,4\\}"))) | |
234 (goto-char (point-min)) | |
235 (Assert (= 12 (re-search-forward "^[a]\\{4,4\\}$"))) | |
236 ) | |
237 | |
446 | 238 ;; charset, charset_not |
239 ;; Not called because it takes too much time. | |
240 (defun test-regexp-charset-paranoid () | |
241 (let ((i 0) | |
242 (max (expt 2 (if (featurep 'mule) 19 8))) | |
243 (range "[a-z]") | |
244 (range-not "[^a-z]") | |
245 char string) | |
246 (while (< i max) | |
247 (when (setq char (int-to-char i)) | |
248 (setq string (char-to-string char)) | |
249 (if (or (and (<= 65 i) | |
250 (<= i 90)) | |
251 (and (<= 97 i) | |
252 (<= i 122))) | |
253 (progn | |
254 (Assert (string-match range string)) | |
255 (Assert (not (string-match range-not string)))) | |
256 (Assert (not (string-match range string))) | |
257 (Assert (string-match range-not string)))) | |
258 (setq i (1+ i))))) | |
259 | |
260 ;; (test-regexp-charset-paranoid) | |
261 | |
262 ;; charset_mule, charset_mule_not | |
263 ;; Not called because it takes too much time. | |
264 (defun test-regex-charset-mule-paranoid () | |
265 (if (featurep 'mule) | |
266 (let ((i 0) | |
267 (max (expt 2 19)) | |
268 (range (format "[%c-%c]" | |
269 (make-char 'japanese-jisx0208 36 34) | |
270 (make-char 'japanese-jisx0208 36 42))) | |
271 (range-not (format "[^%c-%c]" | |
272 (make-char 'japanese-jisx0208 36 34) | |
273 (make-char 'japanese-jisx0208 36 42))) | |
274 (min-int (char-to-int (make-char 'japanese-jisx0208 36 34))) | |
275 (max-int (char-to-int (make-char 'japanese-jisx0208 36 42))) | |
276 char string) | |
277 (while (< i max) | |
278 (when (setq char (int-to-char i)) | |
279 (setq string (char-to-string char)) | |
280 (if (and (<= min-int i) | |
281 (<= i max-int)) | |
282 (progn | |
283 (Assert (string-match range string)) | |
284 (Assert (not (string-match range-not string)))) | |
285 (Assert (not (string-match range string))) | |
286 (Assert (string-match range-not string)))) | |
287 (setq i (1+ i)))))) | |
288 | |
289 ;; (test-regex-charset-mule-paranoid) | |
448 | 290 |
1472 | 291 ;; Test that replace-match does not clobber registers after a failed match |
448 | 292 (with-temp-buffer |
293 (insert "This is a test buffer.") | |
294 (goto-char (point-min)) | |
295 (search-forward "this is a test ") | |
296 (looking-at "Unmatchable text") | |
1472 | 297 (replace-match "") |
298 (Assert (looking-at "^buffer.$"))) | |
1024 | 299 |
300 ;; Test that trivial regexps reset unused registers | |
301 ;; Thanks to Martin Sternholm for the report. | |
302 ;; xemacs-beta <5blm6h2ki5.fsf@lister.roxen.com> | |
303 (with-temp-buffer | |
304 (insert "ab") | |
305 (goto-char (point-min)) | |
306 (re-search-forward "\\(a\\)") | |
1175 | 307 ;; test the whole-match data, too -- one attempted fix scotched that, too! |
1024 | 308 (Assert (string= (match-string 0) "a")) |
309 (Assert (string= (match-string 1) "a")) | |
310 (re-search-forward "b") | |
311 (Assert (string= (match-string 0) "b")) | |
312 (Assert (string= (match-string 1) nil))) | |
313 | |
314 ;; Test word boundaries | |
1095 | 315 (Assert (= (string-match "\\<a" " a") 1)) |
316 (Assert (= (string-match "a\\>" "a ") 0)) | |
1024 | 317 (Assert (= (string-match "\\ba" " a") 1)) |
318 (Assert (= (string-match "a\\b" "a ") 0)) | |
319 ;; should work at target boundaries | |
320 (Assert (= (string-match "\\<a" "a") 0)) | |
321 (Assert (= (string-match "a\\>" "a") 0)) | |
322 (Assert (= (string-match "\\ba" "a") 0)) | |
323 (Assert (= (string-match "a\\b" "a") 0)) | |
1095 | 324 ;; Check for weirdness |
325 (Assert (not (string-match " \\> " " "))) | |
326 (Assert (not (string-match " \\< " " "))) | |
327 (Assert (not (string-match " \\b " " "))) | |
1024 | 328 ;; but not if the "word" would be on the null side of the boundary! |
329 (Assert (not (string-match "\\<" ""))) | |
330 (Assert (not (string-match "\\>" ""))) | |
331 (Assert (not (string-match " \\<" " "))) | |
332 (Assert (not (string-match "\\> " " "))) | |
333 (Assert (not (string-match "a\\<" "a"))) | |
334 (Assert (not (string-match "\\>a" "a"))) | |
1389 | 335 ;; Added Known-Bug 2002-09-09 sjt |
336 ;; Fixed bug 2003-03-21 sjt | |
337 (Assert (not (string-match "\\b" ""))) | |
338 (Assert (not (string-match "\\b" " "))) | |
339 (Assert (not (string-match " \\b" " "))) | |
340 (Assert (not (string-match "\\b " " "))) | |
1175 | 341 |
342 ;; Character classes are broken in Mule as of 21.5.9 | |
343 ;; Added Known-Bug 2002-12-27 | |
1413 | 344 ;; Fixed by Daiki Ueno 2003-03-24 |
1175 | 345 (if (featurep 'mule) |
346 ;; note: (int-to-char 65) => ?A | |
347 (let ((ch0 (make-char 'japanese-jisx0208 52 65)) | |
348 (ch1 (make-char 'japanese-jisx0208 51 65))) | |
349 (Assert (not (string-match "A" (string ch0)))) | |
350 (Assert (not (string-match "[A]" (string ch0)))) | |
1413 | 351 (Assert (eq (string-match "[^A]" (string ch0)) 0)) |
1175 | 352 (Assert (not (string-match "@A" (string ?@ ch0)))) |
1413 | 353 (Assert (not (string-match "@[A]" (string ?@ ch0)))) |
354 (Assert (eq (string-match "@[^A]" (string ?@ ch0)) 0)) | |
1175 | 355 (Assert (not (string-match "@?A" (string ?@ ch0)))) |
356 (Assert (not (string-match "A" (string ch1)))) | |
357 (Assert (not (string-match "[A]" (string ch1)))) | |
358 (Assert (eq (string-match "[^A]" (string ch1)) 0)) | |
359 (Assert (not (string-match "@A" (string ?@ ch1)))) | |
360 (Assert (not (string-match "@[A]" (string ?@ ch1)))) | |
361 (Assert (eq (string-match "@[^A]" (string ?@ ch1)) 0)) | |
1413 | 362 (Assert (not (string-match "@?A" (string ?@ ch1)))) |
363 ) | |
364 ) | |
1195 | 365 |
366 ;; More stale match data tests. | |
367 ;; Thanks to <bjacob@ca.metsci.com>. | |
1425 | 368 ;; These tests used to fail because we cleared match data only on success. |
369 ;; Fixed 2003-04-17. | |
1612 | 370 ;; Must change sense of failing tests 2003-05-09. Too much code depends on |
371 ;; failed matches preserving match-data. | |
1472 | 372 (let ((a "a")) |
373 (Assert (string= (progn (string-match "a" a) | |
374 (string-match "b" a) | |
375 (match-string 0 a)) | |
376 a)) | |
377 (Assert (not (progn (string-match "a" a) | |
378 (string-match "b" a) | |
379 (match-string 1 a)))) | |
380 ;; test both for the second match is a plain string match and a regexp match | |
381 (Assert (string= (progn (string-match "\\(a\\)" a) | |
382 (string-match "\\(b\\)" a) | |
383 (match-string 0 a)) | |
384 a)) | |
385 (Assert (string= (progn (string-match "\\(a\\)" a) | |
386 (string-match "b" a) | |
387 (match-string 0 a)) | |
388 a)) | |
389 (Assert (string= (progn (string-match "\\(a\\)" a) | |
390 (string-match "\\(b\\)" a) | |
391 (match-string 1 a)) | |
392 a)) | |
393 (Assert (string= (progn (string-match "\\(a\\)" a) | |
394 (string-match "b" a) | |
395 (match-string 1 a)) | |
2542 | 396 a)) |
397 ;; in 21.4.16, registers from num_shy_groups to num_groups were not cleared, | |
398 ;; resulting in stale match data | |
399 (Assert (progn (string-match "\\(a\\)" a) | |
400 (string-match "\\(?:a\\)" a) | |
401 (not (match-beginning 1)))) | |
402 ) | |
2254 | 403 |
404 ;; bug identified by Katsumi Yamaoka 2004-09-03 <b9ywtzbbpue.fsf_-_@jpl.org> | |
405 ;; fix submitted by sjt 2004-09-08 | |
406 ;; trailing comments are values from buggy 21.4.15 | |
407 (let ((text "abc")) | |
408 (Assert (eq 0 (string-match "\\(?:ab+\\)*c" text))) ; 2 | |
409 (Assert (eq 0 (string-match "^\\(?:ab+\\)*c" text))) ; nil | |
410 (Assert (eq 0 (string-match "^\\(?:ab+\\)*" text))) ; 0 | |
411 (Assert (eq 0 (string-match "^\\(?:ab+\\)c" text))) ; 0 | |
412 (Assert (eq 0 (string-match "^\\(?:ab\\)*c" text))) ; 0 | |
413 (Assert (eq 0 (string-match "^\\(?:a+\\)*b" text))) ; nil | |
414 (Assert (eq 0 (string-match "^\\(?:a\\)*b" text))) ; 0 | |
415 ) | |
416 | |
2324 | 417 ;; per Steve Youngs 2004-09-30 <microsoft-free.87ekkjhj7t.fsf@youngs.au.com> |
418 ;; fix submitted by sjt 2004-10-07 | |
419 ;; trailing comments are values from buggy 21.4.pre16 | |
420 (let ((text "abc")) | |
421 (Assert (eq 0 (string-match "\\(?:a\\(b\\)\\)" text))) ; 0 | |
422 (Assert (string= (match-string 1 text) "b")) ; ab | |
423 (Assert (null (match-string 2 text))) ; b | |
424 (Assert (null (match-string 3 text))) ; nil | |
425 (Assert (eq 0 (string-match "\\(?:a\\(?:b\\(c\\)\\)\\)" text))) ; 0 | |
426 (Assert (string= (match-string 1 text) "c")) ; abc | |
427 (Assert (null (match-string 2 text))) ; ab | |
428 (Assert (null (match-string 3 text))) ; c | |
429 (Assert (null (match-string 4 text))) ; nil | |
430 ) | |
431 | |
2542 | 432 ;; trivial subpatterns and backreferences with shy groups |
433 (let ((text1 "abb") | |
434 (text2 "aba") | |
435 (re0 "\\(a\\)\\(b\\)\\2") | |
436 (re1 "\\(?:a\\)\\(b\\)\\2") | |
437 (re2 "\\(?:a\\)\\(b\\)\\1") | |
438 (re3 "\\(a\\)\\(?:b\\)\\1")) | |
439 | |
440 (Assert (eq 0 (string-match re0 text1))) | |
441 (Assert (string= text1 (match-string 0 text1))) | |
442 (Assert (string= "a" (match-string 1 text1))) | |
443 (Assert (string= "b" (match-string 2 text1))) | |
444 (Assert (null (string-match re0 text2))) | |
445 | |
446 (Check-Error-Message 'invalid-regexp "Invalid back reference" | |
447 (string-match re1 text1)) | |
448 | |
449 (Assert (eq 0 (string-match re2 text1))) | |
450 (Assert (string= text1 (match-string 0 text1))) | |
451 (Assert (string= "b" (match-string 1 text1))) | |
452 (Assert (null (match-string 2 text1))) | |
453 (Assert (null (string-match re2 text2))) | |
454 | |
455 (Assert (null (string-match re3 text1))) | |
456 (Assert (eq 0 (string-match re3 text2))) | |
457 (Assert (string= text2 (match-string 0 text2))) | |
458 (Assert (string= "a" (match-string 1 text2))) | |
459 (Assert (null (match-string 2 text2))) | |
460 ) | |
461 | |
4199 | 462 ;; replace-regexp-in-string (regexp rep source |
463 ;; fixedcase literal buf-or-subexp start) | |
464 | |
465 ;; Currently we test the following cases: | |
466 ;; where `cbuf' and `bar-or-empty' are bound below. | |
467 | |
468 ;; #### Tests for the various functional features (fixedcase, literal, start) | |
469 ;; should be added. | |
470 | |
471 (with-temp-buffer | |
472 (flet ((bar-or-empty (subexp) (if (string= subexp "foo") "bar" ""))) | |
473 (let ((cbuf (current-buffer))) | |
474 (dolist (test-case | |
475 ;; REP BUF-OR-SUBEXP EXPECTED RESULT | |
476 `(("bar" nil " bar") | |
477 ("bar" ,cbuf " bar") | |
478 ("bar" 0 " bar") | |
479 ("bar" 1 " bar foo") | |
480 (bar-or-empty nil " ") | |
481 (bar-or-empty ,cbuf " ") | |
482 (bar-or-empty 0 " ") | |
483 (bar-or-empty 1 " bar foo"))) | |
484 (Assert | |
485 (string= | |
486 (nth 2 test-case) | |
487 (replace-regexp-in-string "\\(foo\\).*\\'" (nth 0 test-case) | |
488 " foo foo" nil nil (nth 1 test-case))))) | |
489 ;; #### Why doesn't this loop work right? | |
490 ; (dolist (test-case | |
491 ; ;; REP BUF-OR-SUBEXP EXPECTED ERROR EXPECTED MESSAGE | |
492 ; `(;; expected message was "bufferp, symbol" up to 21.5.28 | |
493 ; ("bar" 'symbol wrong-type-argument "integerp, symbol") | |
494 ; ("bar" -1 invalid-argument | |
495 ; "match data register invalid, -1") | |
496 ; ("bar" 2 invalid-argument | |
497 ; "match data register not set, 2") | |
498 ; )) | |
499 ; (eval | |
500 ; `(Check-Error-Message ,(nth 2 test-case) ,(nth 3 test-case) | |
501 ; (replace-regexp-in-string "\\(foo\\).*\\'" ,(nth 0 test-case) | |
502 ; " foo foo" nil nil ,(nth 1 test-case))))) | |
503 ;; #### Can't test the message with w-t-a, see test-harness.el. | |
504 (Check-Error wrong-type-argument | |
505 (replace-regexp-in-string "\\(foo\\).*\\'" | |
506 "bar" | |
507 " foo foo" nil nil | |
508 'symbol)) | |
509 ;; #### Can't test the FROB (-1), see test-harness.el. | |
510 (Check-Error-Message invalid-argument | |
511 "match data register invalid" | |
512 (replace-regexp-in-string "\\(foo\\).*\\'" | |
513 "bar" | |
514 " foo foo" nil nil | |
515 -1)) | |
516 ;; #### Can't test the FROB (-1), see test-harness.el. | |
517 (Check-Error-Message invalid-argument | |
518 "match data register not set" | |
519 (replace-regexp-in-string "\\(foo\\).*\\'" | |
520 "bar" | |
521 " foo foo" nil nil | |
522 2)) | |
523 ))) | |
524 | |
4504
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
525 ;; Not very comprehensive tests of skip-chars-forward, skip-chars-background: |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
526 |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
527 (with-string-as-buffer-contents |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
528 "-]-----------------------------][]]------------------------" |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
529 (skip-chars-forward (skip-chars-quote "-[]")) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
530 (Assert (= (point) (point-max))) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
531 (skip-chars-backward (skip-chars-quote "-[]")) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
532 (Assert (= (point) (point-min))) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
533 ;; Testing in passing for an old bug in #'skip-chars-forward where I |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
534 ;; thought it was impossible to call it with a string containing only ?- |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
535 ;; and ?]: |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
536 (Assert (= (skip-chars-forward (skip-chars-quote "-]")) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
537 (position ?[ (buffer-string) :test #'=))) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
538 ;; This used to error, incorrectly: |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
539 (Assert (skip-chars-quote "[-"))) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
540 |
4199 | 541 ;; replace-match (REPLACEMENT &optional FIXEDCASE LITERAL STRING STRBUFFER) |
542 | |
543 ;; #### Write some tests! Much functionality is implicitly tested above | |
544 ;; via `replace-regexp-in-string', but we should specifically test bogus | |
545 ;; combinations of STRING and STRBUFFER. | |
546 |