about summary refs log tree commit diff
path: root/users/wpcarro/emacs/pkgs/al/tests.el
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-07-30T01·12-0700
committerclbot <clbot@tvl.fyi>2022-07-30T01·29+0000
commit6b3f4113cc6ffe79eff0fa0008a1d8d95f5a6bac (patch)
tree8a0b9d9948989fee65f839fdfaddd34368fb584f /users/wpcarro/emacs/pkgs/al/tests.el
parent230c4bbb3e9f44875d6593a7c6cb0ca33bb63805 (diff)
feat(wpcarro/emacs): Support default value for al-get r/4345
Similar to Elixir's `Map.get/3`.

Change-Id: I736f7e618aafc786a32eeba46ca635cb27db18b6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6000
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/emacs/pkgs/al/tests.el')
-rw-r--r--users/wpcarro/emacs/pkgs/al/tests.el13
1 files changed, 13 insertions, 0 deletions
diff --git a/users/wpcarro/emacs/pkgs/al/tests.el b/users/wpcarro/emacs/pkgs/al/tests.el
index 5146ee6b21a4..6556ddabc359 100644
--- a/users/wpcarro/emacs/pkgs/al/tests.el
+++ b/users/wpcarro/emacs/pkgs/al/tests.el
@@ -14,6 +14,19 @@
    (al-has-key? 'fname '((fname . "William")))
    (not (al-has-key? 'lname '((fname . "William"))))))
 
+(ert-deftest al-get ()
+  (let ((xs (->> (al-new)
+                 (al-set 'fname "John")
+                 (al-set 'employed? nil))))
+    (and
+     (string= "John" (al-get 'fname xs))
+     (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).
+     (eq nil (al-get 'employed? xs))
+     (eq nil (al-get 'employed? xs "default")))))
+
 (ert-deftest al-has-value? ()
   (and
    (al-has-value? "William" '((fname . "William")))