* automated/let-alist.el: require `cl-lib'
[emacs.git] / test / automated / let-alist.el
bloba700a4773ff7cd0c259e9d39a9e91025acc5a06d
1 ;;; let-alist.el --- tests for file handling. -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
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.
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.
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/>.
20 ;;; Code:
22 (require 'ert)
23 (require 'cl-lib)
25 (ert-deftest let-alist-surface-test ()
26 "Tests basic macro expansion for `let-alist'."
27 (should
28 (equal '(let ((symbol data))
29 (let ((.test-one (cdr (assq 'test-one symbol)))
30 (.test-two (cdr (assq 'test-two symbol))))
31 (list .test-one .test-two
32 .test-two .test-two)))
33 (cl-letf (((symbol-function #'gensym) (lambda (x) 'symbol)))
34 (macroexpand
35 '(let-alist data (list .test-one .test-two
36 .test-two .test-two)))))))
38 (defvar let-alist--test-counter 0
39 "Used to count number of times a function is called.")
41 (ert-deftest let-alist-evaluate-once ()
42 "Check that the alist argument is only evaluated once."
43 (let ((let-alist--test-counter 0))
44 (should
45 (equal
46 (let-alist (list
47 (cons 'test-two (cl-incf let-alist--test-counter))
48 (cons 'test-three (cl-incf let-alist--test-counter)))
49 (list .test-one .test-two .test-two .test-three .cl-incf))
50 '(nil 1 1 2 nil)))))
53 ;;; let-alist.el ends here