Mercurial > hg > xemacs-beta
comparison tests/automated/regexp-tests.el @ 4199:3660d327399f
[xemacs-hg @ 2007-10-01 08:07:39 by stephent]
Implement subexpression replacement in replace-match. <87ejgf6yy9.fsf@uwakimon.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Mon, 01 Oct 2007 08:07:57 +0000 |
parents | 60989130c706 |
children | b82fdf7305ee |
comparison
equal
deleted
inserted
replaced
4198:fb83e69ce80a | 4199:3660d327399f |
---|---|
457 (Assert (string= text2 (match-string 0 text2))) | 457 (Assert (string= text2 (match-string 0 text2))) |
458 (Assert (string= "a" (match-string 1 text2))) | 458 (Assert (string= "a" (match-string 1 text2))) |
459 (Assert (null (match-string 2 text2))) | 459 (Assert (null (match-string 2 text2))) |
460 ) | 460 ) |
461 | 461 |
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 | |
525 ;; replace-match (REPLACEMENT &optional FIXEDCASE LITERAL STRING STRBUFFER) | |
526 | |
527 ;; #### Write some tests! Much functionality is implicitly tested above | |
528 ;; via `replace-regexp-in-string', but we should specifically test bogus | |
529 ;; combinations of STRING and STRBUFFER. | |
530 |