1 ;;; let-alist.el --- tests for file handling. -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2015 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/>.
26 (ert-deftest let-alist-surface-test ()
27 "Tests basic macro expansion for `let-alist'."
29 (equal '(let ((symbol data))
30 (let ((.test-one (cdr (assq 'test-one symbol)))
31 (.test-two (cdr (assq 'test-two symbol))))
32 (list .test-one .test-two
33 .test-two .test-two)))
34 (cl-letf (((symbol-function #'make-symbol) (lambda (x) 'symbol)))
36 '(let-alist data (list .test-one .test-two
37 .test-two .test-two))))))
40 (let ((.external "ext")
42 (let-alist '((test-two . 0)
46 (list .test-one .test-two .test-three
47 .sublist.foo .sublist.bar
48 ..external ..external.too)))
49 (list nil 0 1 2 3 "ext" "et"))))
51 (defvar let-alist--test-counter 0
52 "Used to count number of times a function is called.")
54 (ert-deftest let-alist-evaluate-once ()
55 "Check that the alist argument is only evaluated once."
56 (let ((let-alist--test-counter 0))
60 (cons 'test-two (cl-incf let-alist--test-counter))
61 (cons 'test-three (cl-incf let-alist--test-counter)))
62 (list .test-one .test-two .test-two .test-three .cl-incf))
65 (ert-deftest let-alist-remove-dot ()
66 "Remove first dot from symbol."
67 (should (equal (let-alist--remove-dot 'hi) 'hi))
68 (should (equal (let-alist--remove-dot '.hi) 'hi))
69 (should (equal (let-alist--remove-dot '..hi) '.hi)))
71 (ert-deftest let-alist-list-to-sexp ()
72 "Check that multiple dots are handled correctly."
73 (should (= 1 (eval (let-alist--list-to-sexp '(a b c d) ''((d (c (b (a . 1)))))))))
74 (should (equal (let-alist--access-sexp '.foo.bar.baz 'var)
75 '(cdr (assq 'baz (cdr (assq 'bar (cdr (assq 'foo var))))))))
76 (should (equal (let-alist--access-sexp '..foo.bar.baz 'var) '.foo.bar.baz)))
78 ;;; let-alist.el ends here