changeset 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 d5df0f14fac0
children 5e6de1feeafc
files tests/ChangeLog tests/automated/regexp-tests.el
diffstat 2 files changed, 47 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/ChangeLog	Tue Feb 01 22:51:18 2005 +0000
+++ b/tests/ChangeLog	Wed Feb 02 11:37:21 2005 +0000
@@ -1,3 +1,13 @@
+2005-02-01  Vin Shelton  <acs@xemacs.org>
+
+	* automated/regexp-tests.el: Added test for stale match data with
+	shy groups authored by Arnaud Giersch <arnaud.giersch@free.fr>
+
+2005-01-13  Stephen J. Turnbull  <stephen@xemacs.org>
+
+	* automated/regexp-tests.el:
+	Test trivial subpatterns and backreferences with shy groups.
+
 2004-10-28  Stephen J. Turnbull  <stephen@xemacs.org>
 
 	* automated/os-tests.el: New file.  Add tests for bug reported by
--- a/tests/automated/regexp-tests.el	Tue Feb 01 22:51:18 2005 +0000
+++ b/tests/automated/regexp-tests.el	Wed Feb 02 11:37:21 2005 +0000
@@ -393,7 +393,13 @@
   (Assert (string= (progn (string-match "\\(a\\)" a)
 			  (string-match "b" a)
 			  (match-string 1 a))
-		   a)))
+		   a))
+  ;; in 21.4.16, registers from num_shy_groups to num_groups were not cleared,
+  ;; resulting in stale match data
+  (Assert (progn (string-match "\\(a\\)" a)  
+		 (string-match "\\(?:a\\)" a)  
+		 (not (match-beginning 1))))
+  )
 
 ;; bug identified by Katsumi Yamaoka 2004-09-03 <b9ywtzbbpue.fsf_-_@jpl.org>
 ;; fix submitted by sjt 2004-09-08
@@ -423,3 +429,33 @@
   (Assert (null (match-string 4 text)))				; nil
 )
 
+;; trivial subpatterns and backreferences with shy groups
+(let ((text1 "abb")
+      (text2 "aba")
+      (re0 "\\(a\\)\\(b\\)\\2")
+      (re1 "\\(?:a\\)\\(b\\)\\2")
+      (re2 "\\(?:a\\)\\(b\\)\\1")
+      (re3 "\\(a\\)\\(?:b\\)\\1"))
+
+  (Assert (eq 0 (string-match re0 text1)))
+  (Assert (string= text1 (match-string 0 text1)))
+  (Assert (string= "a" (match-string 1 text1)))
+  (Assert (string= "b" (match-string 2 text1)))
+  (Assert (null (string-match re0 text2)))
+
+  (Check-Error-Message 'invalid-regexp "Invalid back reference"
+		       (string-match re1 text1))
+
+  (Assert (eq 0 (string-match re2 text1)))
+  (Assert (string= text1 (match-string 0 text1)))
+  (Assert (string= "b" (match-string 1 text1)))
+  (Assert (null (match-string 2 text1)))
+  (Assert (null (string-match re2 text2)))
+
+  (Assert (null (string-match re3 text1)))
+  (Assert (eq 0 (string-match re3 text2)))
+  (Assert (string= text2 (match-string 0 text2)))
+  (Assert (string= "a" (match-string 1 text2)))
+  (Assert (null (match-string 2 text2)))
+)
+