Cover struct.el
Add some basic test coverage to struct.el.
This commit is contained in:
parent
b52d210b9b
commit
1399eae319
1 changed files with 20 additions and 3 deletions
|
@ -24,9 +24,12 @@
|
||||||
(require 'dash)
|
(require 'dash)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Functions
|
;; Library
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defvar struct/enable-tests? t
|
||||||
|
"When t, run the test suite defined herein.")
|
||||||
|
|
||||||
(defmacro struct/update (type field f xs)
|
(defmacro struct/update (type field f xs)
|
||||||
"Apply F to FIELD in XS, which is a struct of TYPE.
|
"Apply F to FIELD in XS, which is a struct of TYPE.
|
||||||
This is immutable."
|
This is immutable."
|
||||||
|
@ -64,8 +67,22 @@ This is an adapter interface to `setf'."
|
||||||
(string/prepend (string/concat (symbol-name type) "-"))
|
(string/prepend (string/concat (symbol-name type) "-"))
|
||||||
intern)))
|
intern)))
|
||||||
`(progn
|
`(progn
|
||||||
(setf (,accessor xs) ,x)
|
(setf (,accessor ,xs) ,x)
|
||||||
xs)))
|
,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)
|
(provide 'struct)
|
||||||
;;; struct.el ends here
|
;;; struct.el ends here
|
||||||
|
|
Loading…
Reference in a new issue