1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
;;; cconv-tests.el --- Tests for cconv.el -*- lexical-binding: t -*-
;; Copyright (C) 2018-2022 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'ert)
(require 'cl-lib)
(ert-deftest cconv-tests-lambda-:documentation ()
"Docstring for lambda can be specified with :documentation."
(let ((fun (lambda ()
(:documentation (concat "lambda" " documentation"))
'lambda-result)))
(should (string= (documentation fun) "lambda documentation"))
(should (eq (funcall fun) 'lambda-result))))
(ert-deftest cconv-tests-pcase-lambda-:documentation ()
"Docstring for pcase-lambda can be specified with :documentation."
(let ((fun (pcase-lambda (`(,a ,b))
(:documentation (concat "pcase-lambda" " documentation"))
(list b a))))
(should (string= (documentation fun) "pcase-lambda documentation"))
(should (equal '(2 1) (funcall fun '(1 2))))))
(defun cconv-tests-defun ()
(:documentation (concat "defun" " documentation"))
'defun-result)
(ert-deftest cconv-tests-defun-:documentation ()
"Docstring for defun can be specified with :documentation."
(should (string= (documentation 'cconv-tests-defun)
"defun documentation"))
(should (eq (cconv-tests-defun) 'defun-result)))
(cl-defun cconv-tests-cl-defun ()
(:documentation (concat "cl-defun" " documentation"))
'cl-defun-result)
(ert-deftest cconv-tests-cl-defun-:documentation ()
"Docstring for cl-defun can be specified with :documentation."
(should (string= (documentation 'cconv-tests-cl-defun)
"cl-defun documentation"))
(should (eq (cconv-tests-cl-defun) 'cl-defun-result)))
;; FIXME: The byte-complier croaks on this. See Bug#28557.
;; (defmacro cconv-tests-defmacro ()
;; (:documentation (concat "defmacro" " documentation"))
;; '(quote defmacro-result))
;; (ert-deftest cconv-tests-defmacro-:documentation ()
;; "Docstring for defmacro can be specified with :documentation."
;; (should (string= (documentation 'cconv-tests-defmacro)
;; "defmacro documentation"))
;; (should (eq (cconv-tests-defmacro) 'defmacro-result)))
;; FIXME: The byte-complier croaks on this. See Bug#28557.
;; (cl-defmacro cconv-tests-cl-defmacro ()
;; (:documentation (concat "cl-defmacro" " documentation"))
;; '(quote cl-defmacro-result))
;; (ert-deftest cconv-tests-cl-defmacro-:documentation ()
;; "Docstring for cl-defmacro can be specified with :documentation."
;; (should (string= (documentation 'cconv-tests-cl-defmacro)
;; "cl-defmacro documentation"))
;; (should (eq (cconv-tests-cl-defmacro) 'cl-defmacro-result)))
(cl-iter-defun cconv-tests-cl-iter-defun ()
(:documentation (concat "cl-iter-defun" " documentation"))
(iter-yield 'cl-iter-defun-result))
(ert-deftest cconv-tests-cl-iter-defun-:documentation ()
"Docstring for cl-iter-defun can be specified with :documentation."
;; FIXME: See Bug#28557.
:tags '(:unstable)
:expected-result :failed
(should (string= (documentation 'cconv-tests-cl-iter-defun)
"cl-iter-defun documentation"))
(should (eq (iter-next (cconv-tests-cl-iter-defun))
'cl-iter-defun-result)))
(iter-defun cconv-tests-iter-defun ()
(:documentation (concat "iter-defun" " documentation"))
(iter-yield 'iter-defun-result))
(ert-deftest cconv-tests-iter-defun-:documentation ()
"Docstring for iter-defun can be specified with :documentation."
;; FIXME: See Bug#28557.
:tags '(:unstable)
:expected-result :failed
(should (string= (documentation 'cconv-tests-iter-defun)
"iter-defun documentation"))
(should (eq (iter-next (cconv-tests-iter-defun)) 'iter-defun-result)))
(ert-deftest cconv-tests-iter-lambda-:documentation ()
"Docstring for iter-lambda can be specified with :documentation."
;; FIXME: See Bug#28557.
:expected-result :failed
(let ((iter-fun
(iter-lambda ()
(:documentation (concat "iter-lambda" " documentation"))
(iter-yield 'iter-lambda-result))))
(should (string= (documentation iter-fun) "iter-lambda documentation"))
(should (eq (iter-next (funcall iter-fun)) 'iter-lambda-result))))
(ert-deftest cconv-tests-cl-function-:documentation ()
"Docstring for cl-function can be specified with :documentation."
;; FIXME: See Bug#28557.
:expected-result :failed
(let ((fun (cl-function (lambda (&key arg)
(:documentation (concat "cl-function"
" documentation"))
(list arg 'cl-function-result)))))
(should (string= (documentation fun) "cl-function documentation"))
(should (equal (funcall fun :arg t) '(t cl-function-result)))))
(ert-deftest cconv-tests-function-:documentation ()
"Docstring for lambda inside function can be specified with :documentation."
(let ((fun #'(lambda (arg)
(:documentation (concat "function" " documentation"))
(list arg 'function-result))))
(should (string= (documentation fun) "function documentation"))
(should (equal (funcall fun t) '(t function-result)))))
(fmakunbound 'cconv-tests-cl-defgeneric)
(setplist 'cconv-tests-cl-defgeneric nil)
(cl-defgeneric cconv-tests-cl-defgeneric (n)
(:documentation (concat "cl-defgeneric" " documentation")))
(cl-defmethod cconv-tests-cl-defgeneric ((n integer))
(:documentation (concat "cl-defmethod" " documentation"))
(+ 1 n))
(ert-deftest cconv-tests-cl-defgeneric-:documentation ()
"Docstring for cl-defgeneric can be specified with :documentation."
;; FIXME: See Bug#28557.
:expected-result :failed
(let ((descr (describe-function 'cconv-tests-cl-defgeneric)))
(set-text-properties 0 (length descr) nil descr)
(should (string-match-p "cl-defgeneric documentation" descr))
(should (string-match-p "cl-defmethod documentation" descr)))
(should (= 11 (cconv-tests-cl-defgeneric 10))))
(fmakunbound 'cconv-tests-cl-defgeneric-literal)
(setplist 'cconv-tests-cl-defgeneric-literal nil)
(cl-defgeneric cconv-tests-cl-defgeneric-literal (n)
(:documentation "cl-defgeneric-literal documentation"))
(cl-defmethod cconv-tests-cl-defgeneric-literal ((n integer))
(:documentation "cl-defmethod-literal documentation")
(+ 1 n))
(ert-deftest cconv-tests-cl-defgeneric-literal-:documentation ()
"Docstring for cl-defgeneric can be specified with :documentation."
(let ((descr (describe-function 'cconv-tests-cl-defgeneric-literal)))
(set-text-properties 0 (length descr) nil descr)
(should (string-match-p "cl-defgeneric-literal documentation" descr))
(should (string-match-p "cl-defmethod-literal documentation" descr)))
(should (= 11 (cconv-tests-cl-defgeneric-literal 10))))
(defsubst cconv-tests-defsubst ()
(:documentation (concat "defsubst" " documentation"))
'defsubst-result)
(ert-deftest cconv-tests-defsubst-:documentation ()
"Docstring for defsubst can be specified with :documentation."
(should (string= (documentation 'cconv-tests-defsubst)
"defsubst documentation"))
(should (eq (cconv-tests-defsubst) 'defsubst-result)))
(cl-defsubst cconv-tests-cl-defsubst ()
(:documentation (concat "cl-defsubst" " documentation"))
'cl-defsubst-result)
(ert-deftest cconv-tests-cl-defsubst-:documentation ()
"Docstring for cl-defsubst can be specified with :documentation."
(should (string= (documentation 'cconv-tests-cl-defsubst)
"cl-defsubst documentation"))
(should (eq (cconv-tests-cl-defsubst) 'cl-defsubst-result)))
(ert-deftest cconv-convert-lambda-lifted ()
;; Verify that lambda-lifting is actually performed at all.
(should (equal (cconv-closure-convert
'#'(lambda (x) (let ((f #'(lambda () (+ x 1))))
(funcall f))))
'#'(lambda (x) (let ((f #'(lambda (x) (+ x 1))))
(funcall f x)))))
;; Bug#30872.
(should
(equal (funcall
(byte-compile
'#'(lambda (handle-fun arg)
(let* ((subfun
#'(lambda (params)
(ignore handle-fun)
(funcall #'(lambda () (setq params 42)))
params)))
(funcall subfun arg))))
nil 99)
42)))
(provide 'cconv-tests)
;;; cconv-tests.el ends here
|