2022-07-29 05:29:07 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(require 'ert)
|
|
|
|
(require 'al)
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Tests
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(ert-deftest al-has-key? ()
|
2022-07-30 16:13:38 +02:00
|
|
|
(should (al-has-key? 'fname '((fname . "William"))))
|
|
|
|
(should (not (al-has-key? 'lname '((fname . "William"))))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
2022-07-30 03:12:16 +02:00
|
|
|
(ert-deftest al-get ()
|
|
|
|
(let ((xs (->> (al-new)
|
|
|
|
(al-set 'fname "John")
|
|
|
|
(al-set 'employed? nil))))
|
2022-07-30 16:13:38 +02:00
|
|
|
(should (string= "John" (al-get 'fname xs)))
|
|
|
|
(should (string= "Cleese" (al-get 'lname xs "Cleese")))
|
|
|
|
;; Test that the value of nil is returned even when a default is defined,
|
|
|
|
;; which could be a subtle bug in the typical Elisp pattern of supporting
|
|
|
|
;; defaults with: (or foo default).
|
|
|
|
(should (eq nil (al-get 'employed? xs)))
|
|
|
|
(should (eq nil (al-get 'employed? xs "default")))))
|
2022-07-30 03:12:16 +02:00
|
|
|
|
2022-07-29 05:29:07 +02:00
|
|
|
(ert-deftest al-has-value? ()
|
2022-07-30 16:13:38 +02:00
|
|
|
(should (al-has-value? "William" '((fname . "William"))))
|
|
|
|
(should (not (al-has-key? "John" '((fname . "William"))))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
|
|
|
(ert-deftest al-map-keys ()
|
2022-07-30 16:13:38 +02:00
|
|
|
(should
|
|
|
|
(equal '((2 . one)
|
|
|
|
(3 . two))
|
|
|
|
(al-map-keys #'1+
|
|
|
|
'((1 . one)
|
|
|
|
(2 . two))))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
|
|
|
(ert-deftest al-map-values ()
|
2022-07-30 16:13:38 +02:00
|
|
|
(should (equal '((one . 2)
|
|
|
|
(two . 3))
|
|
|
|
(al-map-values #'1+
|
|
|
|
'((one . 1)
|
|
|
|
(two . 2))))))
|
|
|
|
|
|
|
|
(ert-deftest al-delete ()
|
|
|
|
(let ((person (->> (al-new)
|
|
|
|
(al-set "fname" "John")
|
|
|
|
(al-set "lname" "Cleese")
|
|
|
|
(al-set "age" 82))))
|
|
|
|
(should (al-has-key? "age" person))
|
|
|
|
(should (not (al-has-key? "age" (al-delete "age" person))))))
|