summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-11-09 21:30:17 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-11-09 21:30:17 +0300
commit40eeb480099fe238ae03566ae7167003789ea4c7 (patch)
treed97a73b7565358622b4b7905201c4ae310d0d80d /test
parent695dc4050697afdd4d7b106cbba8a43afc256a13 (diff)
fix(macros): fix multimethods which use tables as the dispatch value
Diffstat (limited to 'test')
-rw-r--r--test/macros.fnl16
1 files changed, 15 insertions, 1 deletions
diff --git a/test/macros.fnl b/test/macros.fnl
index ae7ab40..4d4ac57 100644
--- a/test/macros.fnl
+++ b/test/macros.fnl
@@ -92,7 +92,21 @@
(assert-eq (send-message {:protocol :http :message "ваыв"})
"sending ваыв over HTTP")
(assert-eq (send-message {:protocol :icap :message 42})
- "sending 42 over ICAP")))
+ "sending 42 over ICAP"))
+
+ (testing "defmulti with dispatch on tables"
+ (defmulti encounter (fn [x y] [(. x :species) (. y :species)]))
+ (defmethod encounter [:bunny :lion] [_ _] :run)
+ (defmethod encounter [:lion :bunny] [_ _] :eat)
+ (defmethod encounter [:lion :lion] [_ _] :fight)
+ (defmethod encounter [:bunny :bunny] [_ _] :mate)
+
+ (let [l {:species :lion}
+ b {:species :bunny}]
+ (assert-eq (encounter b b) :mate)
+ (assert-eq (encounter l l) :fight)
+ (assert-eq (encounter b l) :run)
+ (assert-eq (encounter l b) :eat))))
(deftest def-macros
(testing "def"