+
+;; More stale match data tests.
+;; Thanks to <bjacob@ca.metsci.com> for drawing attention to this issue.
+;; Flying in the face of sanity, the Asserts with positive results below are
+;; correct. Too much code depends on failed matches preserving match-data.
+(let ((a "a"))
+ (Assert (string= (progn (string-match "a" a)
+ (string-match "b" a)
+ (match-string 0 a))
+ a))
+ (Assert (not (progn (string-match "a" a)
+ (string-match "b" a)
+ (match-string 1 a))))
+ ;; test both for the second match is a plain string match and a regexp match
+ (Assert (string= (progn (string-match "\\(a\\)" a)
+ (string-match "\\(b\\)" a)
+ (match-string 0 a))
+ a))
+ (Assert (string= (progn (string-match "\\(a\\)" a)
+ (string-match "b" a)
+ (match-string 0 a))
+ a))
+ (Assert (string= (progn (string-match "\\(a\\)" a)
+ (string-match "\\(b\\)" a)
+ (match-string 1 a))
+ a))
+ (Assert (string= (progn (string-match "\\(a\\)" a)
+ (string-match "b" a)
+ (match-string 1 a))
+ a)))