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)
 | 
			
		||||
 | 
			
		||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 | 
			
		||||
;; 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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue