From 40eeb480099fe238ae03566ae7167003789ea4c7 Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Mon, 9 Nov 2020 21:30:17 +0300 Subject: fix(macros): fix multimethods which use tables as the dispatch value --- test/macros.fnl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'test/macros.fnl') 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" -- cgit v1.2.3