]> code.delx.au - gnu-emacs/blob - test/automated/subr-tests.el
Merge from origin/emacs-24
[gnu-emacs] / test / automated / subr-tests.el
1 ;;; subr-tests.el --- Tests for subr.el
2
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5 ;; Author: Oleh Krehel <ohwoeowho@gmail.com>
6 ;; Keywords:
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;
26
27 ;;; Code:
28
29 (require 'ert)
30
31 (ert-deftest let-when-compile ()
32 ;; good case
33 (should (equal (macroexpand '(let-when-compile ((foo (+ 2 3)))
34 (setq bar (eval-when-compile (+ foo foo)))
35 (setq boo (eval-when-compile (* foo foo)))))
36 '(progn
37 (setq bar (quote 10))
38 (setq boo (quote 25)))))
39 ;; bad case: `eval-when-compile' omitted, byte compiler should catch this
40 (should (equal (macroexpand
41 '(let-when-compile ((foo (+ 2 3)))
42 (setq bar (+ foo foo))
43 (setq boo (eval-when-compile (* foo foo)))))
44 '(progn
45 (setq bar (+ foo foo))
46 (setq boo (quote 25)))))
47 ;; something practical
48 (should (equal (macroexpand
49 '(let-when-compile ((keywords '("true" "false")))
50 (font-lock-add-keywords
51 'c++-mode
52 `((,(eval-when-compile
53 (format "\\<%s\\>" (regexp-opt keywords)))
54 0 font-lock-keyword-face)))))
55 '(font-lock-add-keywords
56 (quote c++-mode)
57 (list
58 (cons (quote
59 "\\<\\(?:\\(?:fals\\|tru\\)e\\)\\>")
60 (quote
61 (0 font-lock-keyword-face))))))))
62
63 (provide 'subr-tests)
64 ;;; subr-tests.el ends here