about summary refs log tree commit diff
path: root/users/wpcarro/emacs/pkgs/struct/tests.el
blob: a7ddb52c46d682dd84af84302981d1fee9acd4fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Dependencies
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(require 'ert)
(require 'struct)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Tests
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(cl-defstruct dummy name age)

(ert-deftest struct-update ()
  (let* ((test (make-dummy :name "Roofus" :age 19))
         (result (struct-update dummy name #'upcase test)))
    ;; test
    (should (string= "Roofus" (dummy-name test)))
    (should (= 19 (dummy-age test)))
    ;; result
    (should (string= "ROOFUS" (dummy-name result)))
    (should (= 19 (dummy-age result)))))

(ert-deftest struct-update! ()
  (let ((test (make-dummy :name "Roofus" :age 19)))
    (struct-update! dummy name #'upcase test)
    (should (string= "ROOFUS" (dummy-name test)))
    (should (= 19 (dummy-age test)))))

(ert-deftest struct-set ()
  (let* ((test (make-dummy :name "Roofus" :age 19))
         (result (struct-set dummy name "Shoofus" test)))
    ;; test
    (should (string= "Roofus" (dummy-name test)))
    (should (= 19 (dummy-age test)))
    ;; result
    (should (string= "Shoofus" (dummy-name result)))
    (should (= 19 (dummy-age result)))))

(ert-deftest struct-set! ()
  (let ((test (make-dummy :name "Roofus" :age 19)))
    (struct-set! dummy name "Doofus" test)
    (should (string= "Doofus" (dummy-name test)))
    (should (= 19 (dummy-age test)))))