summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp/pcase-tests.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2021-03-01 23:57:34 -0500
committerStefan Monnier <monnier@iro.umontreal.ca>2021-03-01 23:57:56 -0500
commit165353674e5fe7109ba9cbf526de0333902b7851 (patch)
tree8a119ab22fb363ef06f37fd13ab85d29a7399929 /test/lisp/emacs-lisp/pcase-tests.el
parentbac0089fb8b15b71bd4bde00f6fd8e1c4b9fbd1d (diff)
downloademacs-165353674e5fe7109ba9cbf526de0333902b7851.tar.gz
* lisp/emacs-lisp/pcase.el: Bind all the vars in `or` patterns
Improve the handling of `or` patterns where not all sub-patterns bind the same set of variables. This used to be "unsupported" and behaved in somewhat unpredictable ways. (pcase--expand): Rewrite. (pcase-codegen): Delete. * doc/lispref/control.texi (pcase Macro): Adjust accordingly. Also remove the warning about "at least two" sub patterns. These work fine, AFAICT, and if not we should fix it. * test/lisp/emacs-lisp/pcase-tests.el (pcase-tests-or-vars): New test.
Diffstat (limited to 'test/lisp/emacs-lisp/pcase-tests.el')
-rw-r--r--test/lisp/emacs-lisp/pcase-tests.el14
1 files changed, 10 insertions, 4 deletions
diff --git a/test/lisp/emacs-lisp/pcase-tests.el b/test/lisp/emacs-lisp/pcase-tests.el
index 6ddeb7b622b..2120139ec18 100644
--- a/test/lisp/emacs-lisp/pcase-tests.el
+++ b/test/lisp/emacs-lisp/pcase-tests.el
@@ -85,13 +85,19 @@
(ert-deftest pcase-tests-bug46786 ()
(let ((self 'outer))
+ (ignore self)
(should (equal (cl-macrolet ((show-self () `(list 'self self)))
- (pcase-let ((`(,self ,self2) '(inner "2")))
+ (pcase-let ((`(,self ,_self2) '(inner "2")))
(show-self)))
'(self inner)))))
-;; Local Variables:
-;; no-byte-compile: t
-;; End:
+(ert-deftest pcase-tests-or-vars ()
+ (let ((f (lambda (v)
+ (pcase v
+ ((or (and 'b1 (let x1 4) (let x2 5))
+ (and 'b2 (let y1 8) (let y2 9)))
+ (list x1 x2 y1 y2))))))
+ (should (equal (funcall f 'b1) '(4 5 nil nil)))
+ (should (equal (funcall f 'b2) '(nil nil 8 9)))))
;;; pcase-tests.el ends here.