emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/record 2c86c45 6/6: Add tests.


From: Lars Brinkhoff
Subject: [Emacs-diffs] scratch/record 2c86c45 6/6: Add tests.
Date: Tue, 21 Mar 2017 16:21:03 -0400 (EDT)

branch: scratch/record
commit 2c86c450f642ff2d8f9fa77c7eb575816782474a
Author: Lars Brinkhoff <address@hidden>
Commit: Lars Brinkhoff <address@hidden>

    Add tests.
---
 test/lisp/emacs-lisp/cl-lib-tests.el   | 13 +++++++++++++
 test/lisp/emacs-lisp/cl-print-tests.el | 10 ++++++++++
 test/src/alloc-tests.el                | 20 ++++++++++++++++++++
 test/src/data-tests.el                 |  8 ++++++++
 4 files changed, 51 insertions(+)

diff --git a/test/lisp/emacs-lisp/cl-lib-tests.el 
b/test/lisp/emacs-lisp/cl-lib-tests.el
index 5edc3e7..b66e7ac 100644
--- a/test/lisp/emacs-lisp/cl-lib-tests.el
+++ b/test/lisp/emacs-lisp/cl-lib-tests.el
@@ -493,4 +493,17 @@
   (should (cl-typep '* 'cl-lib-test-type))
   (should-not (cl-typep 1 'cl-lib-test-type)))
 
+(ert-deftest cl-lib-defstruct-record ()
+  (cl-defstruct foo x)
+  (let ((x (make-foo :x 42)))
+    (should (recordp x))
+    (should (eq (type-of x) 'foo))
+    (should (eql (foo-x x) 42))))
+
+(ert-deftest cl-lib-old-struct ()
+  (let ((old-struct-compat nil))
+    (cl-struct-define 'foo "" 'cl-structure-object nil nil nil
+                      'cl-struct-foo-tags 'cl-struct-foo t)
+    (should old-struct-compat)))
+
 ;;; cl-lib.el ends here
diff --git a/test/lisp/emacs-lisp/cl-print-tests.el 
b/test/lisp/emacs-lisp/cl-print-tests.el
index 04ddfee..547dbe7 100644
--- a/test/lisp/emacs-lisp/cl-print-tests.el
+++ b/test/lisp/emacs-lisp/cl-print-tests.el
@@ -37,4 +37,14 @@
     (should (string-match "\\`#f(compiled-function (x) .*\n\n.*)\\'"
                           (cl-prin1-to-string (symbol-function #'caar))))))
 
+(ert-deftest cl-print-tests-2 ()
+  (let ((x (record 'foo 1 2 3)))
+    (should (equal
+             x
+             (car (read-from-string (with-output-to-string (prin1 x))))))
+    (let ((print-circle t))
+      (should (string-match
+               "\\`(#1=.* #1#)\\'"
+               (cl-prin1-to-string (list x x)))))))
+
 ;;; cl-print-tests.el ends here.
diff --git a/test/src/alloc-tests.el b/test/src/alloc-tests.el
index af4ad6c..8b4ef8c 100644
--- a/test/src/alloc-tests.el
+++ b/test/src/alloc-tests.el
@@ -31,3 +31,23 @@
 
 (ert-deftest finalizer-object-type ()
   (should (equal (type-of (make-finalizer nil)) 'finalizer)))
+
+(ert-deftest record-1 ()
+  (let ((x (record 'foo 1 2 3)))
+    (should (recordp x))
+    (should (eq (type-of x) 'foo))
+    (should (eq (aref x 0) 'foo))
+    (should (eql (aref x 3) 3))
+    (should (eql (length x) 4))))
+
+(ert-deftest record-2 ()
+  (let ((x (make-record 'bar 1 0)))
+    (should (eql (length x) 2))
+    (should (eql (aref x 1) 0))))
+
+(ert-deftest record-3 ()
+  (let* ((x (record 'foo 1 2 3))
+         (y (copy-record x)))
+    (should-not (eq x y))
+    (dotimes (i 4)
+      (should (eql (aref x i) (aref y i))))))
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index 67d00a7..f4729dd 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -480,3 +480,11 @@ comparing the subr with a much slower lisp implementation."
       (remove-variable-watcher 'data-tests-lvar collect-watch-data)
       (setq data-tests-lvar 6)
       (should (null watch-data)))))
+
+(ert-deftest old-struct ()
+  (let ((x [cl-struct-foo]))
+    (let ((old-struct-compat nil))
+      (should (eq (type-of x) 'vector)))
+    (let ((old-struct-compat t))
+      (should (eq (type-of x) 'cl-struct-foo))
+      (should (eq (type-of [foo]) 'vector)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]