aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Heerdegen2017-11-02 18:45:34 +0100
committerMichael Heerdegen2017-12-01 08:54:05 +0100
commitcc58d4de56e362f5e017d0607986b2962ee47fc1 (patch)
tree3b2427fc07973dd598424ed185b5a36bc0d69be9 /test
parentef183144add2b92359a9ade2ec0b28681b26956b (diff)
downloademacs-cc58d4de56e362f5e017d0607986b2962ee47fc1.tar.gz
emacs-cc58d4de56e362f5e017d0607986b2962ee47fc1.zip
Add macros `thunk-let' and `thunk-let*'
* lisp/emacs-lisp/thunk.el (thunk-let, thunk-let*): New macros. * test/lisp/emacs-lisp/thunk-tests.el: (thunk-let-basic-test, thunk-let*-basic-test) (thunk-let-bound-vars-cant-be-set-test) (thunk-let-laziness-test, thunk-let*-laziness-test) (thunk-let-bad-binding-test): New tests for `thunk-let' and `thunk-let*. * doc/lispref/eval.texi (Deferred Eval): New section. * doc/lispref/elisp.texi: Update menu.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/thunk-tests.el50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/thunk-tests.el b/test/lisp/emacs-lisp/thunk-tests.el
index 973a14b8180..a63ce289e8a 100644
--- a/test/lisp/emacs-lisp/thunk-tests.el
+++ b/test/lisp/emacs-lisp/thunk-tests.el
@@ -51,5 +51,55 @@
51 (thunk-force thunk) 51 (thunk-force thunk)
52 (should (= x 1)))) 52 (should (= x 1))))
53 53
54
55
56;; thunk-let tests
57
58(ert-deftest thunk-let-basic-test ()
59 "Test whether bindings are established."
60 (should (equal (thunk-let ((x 1) (y 2)) (+ x y)) 3)))
61
62(ert-deftest thunk-let*-basic-test ()
63 "Test whether bindings are established."
64 (should (equal (thunk-let* ((x 1) (y (+ 1 x))) (+ x y)) 3)))
65
66(ert-deftest thunk-let-bound-vars-cant-be-set-test ()
67 "Test whether setting a `thunk-let' bound variable fails."
68 (should-error
69 (eval '(thunk-let ((x 1)) (let ((y 7)) (setq x (+ x y)) (* 10 x))) t)))
70
71(ert-deftest thunk-let-laziness-test ()
72 "Test laziness of `thunk-let'."
73 (should
74 (equal (let ((x-evalled nil)
75 (y-evalled nil))
76 (thunk-let ((x (progn (setq x-evalled t) (+ 1 2)))
77 (y (progn (setq y-evalled t) (+ 3 4))))
78 (let ((evalled-y y))
79 (list x-evalled y-evalled evalled-y))))
80 (list nil t 7))))
81
82(ert-deftest thunk-let*-laziness-test ()
83 "Test laziness of `thunk-let*'."
84 (should
85 (equal (let ((x-evalled nil)
86 (y-evalled nil)
87 (z-evalled nil)
88 (a-evalled nil))
89 (thunk-let* ((x (progn (setq x-evalled t) (+ 1 1)))
90 (y (progn (setq y-evalled t) (+ x 1)))
91 (z (progn (setq z-evalled t) (+ y 1)))
92 (a (progn (setq a-evalled t) (+ z 1))))
93 (let ((evalled-z z))
94 (list x-evalled y-evalled z-evalled a-evalled evalled-z))))
95 (list t t t nil 4))))
96
97(ert-deftest thunk-let-bad-binding-test ()
98 "Test whether a bad binding causes an error when expanding."
99 (should-error (macroexpand '(thunk-let ((x 1 1)) x)))
100 (should-error (macroexpand '(thunk-let (27) x)))
101 (should-error (macroexpand '(thunk-let x x))))
102
103
54(provide 'thunk-tests) 104(provide 'thunk-tests)
55;;; thunk-tests.el ends here 105;;; thunk-tests.el ends here