comparison tests/automated/regexp-tests.el @ 2542:60989130c706

[xemacs-hg @ 2005-02-02 11:37:18 by stephent] Shy groups tests <87fz0f6vog.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Wed, 02 Feb 2005 11:37:21 +0000
parents df2fafa399a1
children 3660d327399f
comparison
equal deleted inserted replaced
2541:d5df0f14fac0 2542:60989130c706
391 (match-string 1 a)) 391 (match-string 1 a))
392 a)) 392 a))
393 (Assert (string= (progn (string-match "\\(a\\)" a) 393 (Assert (string= (progn (string-match "\\(a\\)" a)
394 (string-match "b" a) 394 (string-match "b" a)
395 (match-string 1 a)) 395 (match-string 1 a))
396 a))) 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 )
397 403
398 ;; bug identified by Katsumi Yamaoka 2004-09-03 <b9ywtzbbpue.fsf_-_@jpl.org> 404 ;; bug identified by Katsumi Yamaoka 2004-09-03 <b9ywtzbbpue.fsf_-_@jpl.org>
399 ;; fix submitted by sjt 2004-09-08 405 ;; fix submitted by sjt 2004-09-08
400 ;; trailing comments are values from buggy 21.4.15 406 ;; trailing comments are values from buggy 21.4.15
401 (let ((text "abc")) 407 (let ((text "abc"))
421 (Assert (null (match-string 2 text))) ; ab 427 (Assert (null (match-string 2 text))) ; ab
422 (Assert (null (match-string 3 text))) ; c 428 (Assert (null (match-string 3 text))) ; c
423 (Assert (null (match-string 4 text))) ; nil 429 (Assert (null (match-string 4 text))) ; nil
424 ) 430 )
425 431
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