about summary refs log tree commit diff
path: root/configs/shared/.emacs.d/wpc
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-01-09T13·43+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-17T10·56+0000
commit1399eae319a56c3867110118252f1253ad8fd50c (patch)
treeaddefd35c68845462685e379d3f1ec89647e6233 /configs/shared/.emacs.d/wpc
parentb52d210b9bc70e1f5e4a7bc8077db50e8bea4cd5 (diff)
Cover struct.el
Add some basic test coverage to struct.el.
Diffstat (limited to 'configs/shared/.emacs.d/wpc')
-rw-r--r--configs/shared/.emacs.d/wpc/struct.el23
1 files changed, 20 insertions, 3 deletions
diff --git a/configs/shared/.emacs.d/wpc/struct.el b/configs/shared/.emacs.d/wpc/struct.el
index 248d08e97c42..7d237d3259ff 100644
--- a/configs/shared/.emacs.d/wpc/struct.el
+++ b/configs/shared/.emacs.d/wpc/struct.el
@@ -24,9 +24,12 @@
 (require 'dash)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Functions
+;; Library
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(defvar struct/enable-tests? t
+  "When t, run the test suite defined herein.")
+
 (defmacro struct/update (type field f xs)
   "Apply F to FIELD in XS, which is a struct of TYPE.
 This is immutable."
@@ -64,8 +67,22 @@ This is an adapter interface to `setf'."
                        (string/prepend (string/concat (symbol-name type) "-"))
                        intern)))
     `(progn
-       (setf (,accessor xs) ,x)
-       xs)))
+       (setf (,accessor ,xs) ,x)
+       ,xs)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Tests
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(when struct/enable-tests?
+  (cl-defstruct dummy name age)
+  (defvar test-dummy (make-dummy :name "Roofus" :age 19))
+  (struct/set! dummy name "Doofus" test-dummy)
+  (prelude/assert (string= "Doofus" (dummy-name test-dummy)))
+  (let ((result (struct/set dummy name "Shoofus" test-dummy)))
+    ;; Test the immutability of `struct/set'
+    (prelude/assert (string= "Doofus" (dummy-name test-dummy)))
+    (prelude/assert (string= "Shoofus" (dummy-name result)))))
 
 (provide 'struct)
 ;;; struct.el ends here