diff options
author | Andrea Corallo <akrl@sdf.org> | 2021-01-16 13:26:10 +0100 |
---|---|---|
committer | Andrea Corallo <akrl@sdf.org> | 2021-01-16 13:26:10 +0100 |
commit | 0a7ac0b5504e75275699a3d8d2d5d94bcfda8708 (patch) | |
tree | bb6158c8a9edeb1e716718abfc98dca16aef9e9e /test/lisp/emacs-lisp/cl-macs-tests.el | |
parent | f1efac1f9efbfa15b6434ebef507c00c1277633f (diff) | |
parent | 0732fc31932c75c682c8b65b4dcb4376ca63e8fd (diff) | |
download | emacs-0a7ac0b5504e75275699a3d8d2d5d94bcfda8708.tar.gz emacs-0a7ac0b5504e75275699a3d8d2d5d94bcfda8708.tar.bz2 emacs-0a7ac0b5504e75275699a3d8d2d5d94bcfda8708.zip |
Merge remote-tracking branch 'savannah/master' into native-comp
Diffstat (limited to 'test/lisp/emacs-lisp/cl-macs-tests.el')
-rw-r--r-- | test/lisp/emacs-lisp/cl-macs-tests.el | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el index 446983c2e3e..bcd63f73a3c 100644 --- a/test/lisp/emacs-lisp/cl-macs-tests.el +++ b/test/lisp/emacs-lisp/cl-macs-tests.el @@ -610,4 +610,27 @@ collection clause." ;; Just make sure the function can be instrumented. (edebug-defun))) +;;; cl-labels + +(ert-deftest cl-macs--labels () + ;; Simple recursive function. + (cl-labels ((len (xs) (if xs (1+ (len (cdr xs))) 0))) + (should (equal (len (make-list 42 t)) 42))) + + ;; Simple tail-recursive function. + (cl-labels ((len (xs n) (if xs (len (cdr xs) (1+ n)) n))) + (should (equal (len (make-list 42 t) 0) 42)) + ;; Should not bump into stack depth limits. + (should (equal (len (make-list 42000 t) 0) 42000))) + + ;; Check that non-recursive functions are handled more efficiently. + (should (pcase (macroexpand '(cl-labels ((f (x) (+ x 1))) (f 5))) + (`(let* ,_ (funcall ,_ 5)) t))) + + ;; Case of "tail-recursive lambdas". + (should (pcase (macroexpand + '(cl-labels ((len (xs n) (if xs (len (cdr xs) (1+ n)) n))) + #'len)) + (`(function (lambda (,_ ,_) . ,_)) t)))) + ;;; cl-macs-tests.el ends here |