aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/automated/pcase-tests.el68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/automated/pcase-tests.el b/test/automated/pcase-tests.el
new file mode 100644
index 00000000000..ec0c3bc7fd5
--- /dev/null
+++ b/test/automated/pcase-tests.el
@@ -0,0 +1,68 @@
1;;; pcase-tests.el --- Test suite for pcase macro.
2
3;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Commentary:
21
22;;; Code:
23
24(require 'ert)
25(require 'cl-lib)
26
27(ert-deftest pcase-tests-base ()
28 "Test pcase code."
29 (should (equal (pcase '(1 . 2) ((app car '2) 6) ((app car '1) 5)) 5)))
30
31(pcase-defmacro pcase-tests-plus (pat n)
32 `(app (lambda (v) (- v ,n)) ,pat))
33
34(ert-deftest pcase-tests-macro ()
35 (should (equal (pcase 5 ((pcase-tests-plus x 3) x)) 2)))
36
37(defun pcase-tests-grep (fname exp)
38 (when (consp exp)
39 (or (eq fname (car exp))
40 (cl-some (lambda (exp) (pcase-tests-grep fname exp)) (cdr exp)))))
41
42(ert-deftest pcase-tests-tests ()
43 (should (pcase-tests-grep 'memq '(or (+ 2 3) (memq x y))))
44 (should-not (pcase-tests-grep 'memq '(or (+ 2 3) (- x y)))))
45
46(ert-deftest pcase-tests-member ()
47 (should (pcase-tests-grep
48 'memq (macroexpand-all '(pcase x ((or 1 2 3) body)))))
49 (should (pcase-tests-grep
50 'member (macroexpand-all '(pcase x ((or '"a" '2 '3) body)))))
51 (should-not (pcase-tests-grep
52 'memq (macroexpand-all '(pcase x ((or "a" 2 3) body)))))
53 (let ((exp (macroexpand-all
54 '(pcase x
55 ("a" body1)
56 (2 body2)
57 ((or "a" 2 3) body)))))
58 (should-not (pcase-tests-grep 'memq exp))
59 (should-not (pcase-tests-grep 'member exp))))
60
61(ert-deftest pcase-tests-vectors ()
62 (should (equal (pcase [1 2] (`[,x] 1) (`[,x ,y] (+ x y))) 3)))
63
64;; Local Variables:
65;; no-byte-compile: t
66;; End:
67
68;;; pcase-tests.el ends here.