[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/object-type 3b0e0e6dad3: test/src/data-tests.el (data-tests--cl-
From: |
Stefan Monnier |
Subject: |
scratch/object-type 3b0e0e6dad3: test/src/data-tests.el (data-tests--cl-type-of): New test. |
Date: |
Fri, 15 Mar 2024 18:22:28 -0400 (EDT) |
branch: scratch/object-type
commit 3b0e0e6dad366ca3f1f01374cfa83f997791407c
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
test/src/data-tests.el (data-tests--cl-type-of): New test.
---
test/src/data-tests.el | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index ad3b2071254..ef58c57057d 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -838,4 +838,27 @@ comparing the subr with a much slower Lisp implementation."
(dolist (sym (list nil t 'xyzzy (make-symbol "")))
(should (eq sym (bare-symbol (position-symbol sym 0)))))))
+(require 'cl-extra) ;For `cl--class-children'.
+
+(ert-deftest data-tests--cl-type-of ()
+ ;; Make sure that `cl-type-of' returns the most precise type.
+ ;; Note: This doesn't work for list/vector structs since those types
+ ;; are too difficult/unreliable to detect (so `cl-type-of' only says
+ ;; it's a `cons' or a `vector').
+ (dolist (val (list -2 10 (expt 2 128) nil t 'car
+ (symbol-function 'car)
+ (symbol-function 'progn)
+ (position-symbol 'car 7)))
+ (let* ((type (cl-type-of val)))
+ (dolist (subtype (cl--class-children (cl-find-class type)))
+ ;; FIXME: Some types don't have any associated predicate, and
+ ;; some predicate don't quite correspond to the type
+ ;; (e.g. `functionp' will return non-nil for some symbols and
+ ;; some lists whereas `cl-type-of' will never consider those as
+ ;; being `function's).
+ (let ((predicate (get subtype 'cl-deftype-satisfies)))
+ (should predicate)
+ (should-not (funcall predicate val)))))))
+
+
;;; data-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- scratch/object-type 3b0e0e6dad3: test/src/data-tests.el (data-tests--cl-type-of): New test.,
Stefan Monnier <=