diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-12-08 16:58:24 -0500 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-12-08 16:58:24 -0500 |
commit | c6bf11c281553121aaf0fc8686c75bd15dcb3a92 (patch) | |
tree | 98a3937227c48dca104d909571aee73ab75aa329 /test/lisp/emacs-lisp/subr-x-tests.el | |
parent | 3a0e0187b711db69df48e16b35a577f046cf38b1 (diff) | |
download | emacs-c6bf11c281553121aaf0fc8686c75bd15dcb3a92.tar.gz emacs-c6bf11c281553121aaf0fc8686c75bd15dcb3a92.tar.bz2 emacs-c6bf11c281553121aaf0fc8686c75bd15dcb3a92.zip |
* test/lisp/emacs-lisp/subr-x-tests.el (subr-x-named-let): New test
Diffstat (limited to 'test/lisp/emacs-lisp/subr-x-tests.el')
-rw-r--r-- | test/lisp/emacs-lisp/subr-x-tests.el | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/test/lisp/emacs-lisp/subr-x-tests.el b/test/lisp/emacs-lisp/subr-x-tests.el index d8369506000..821b6770ba0 100644 --- a/test/lisp/emacs-lisp/subr-x-tests.el +++ b/test/lisp/emacs-lisp/subr-x-tests.el @@ -676,7 +676,7 @@ (buffer-string)) "foo\n"))) -(ert-deftest test-add-display-text-property () +(ert-deftest subr-x-test-add-display-text-property () (with-temp-buffer (insert "Foo bar zot gazonk") (add-display-text-property 4 8 'height 2.0) @@ -694,5 +694,23 @@ [(raise 0.5) (height 2.0)])) (should (equal (get-text-property 9 'display) '(raise 0.5))))) +(ert-deftest subr-x-named-let () + (let ((funs ())) + (named-let loop + ((rest '(1 42 3)) + (sum 0)) + (when rest + ;; Here, we make sure that the variables are distinct in every + ;; iteration, since a naive tail-call optimization would tend to end up + ;; with a single `sum' variable being shared by all the closures. + (push (lambda () sum) funs) + ;; Here we add a dummy `sum' variable which shadows the `sum' iteration + ;; variable since a naive tail-call optimization could also trip here + ;; thinking it can `(setq sum ...)' to set the iteration + ;; variable's value. + (let ((sum sum)) + (loop (cdr rest) (+ sum (car rest)))))) + (should (equal (mapcar #'funcall funs) '(43 1 0))))) + (provide 'subr-x-tests) ;;; subr-x-tests.el ends here |