Skip to content

Commit

Permalink
[#406] Tests for multi-arity protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Sep 16, 2020
1 parent 00331ca commit af176c0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test/sci/protocols_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@
(let [prog "
(defprotocol IFruit (subtotal [item] [item subtotal]))
(defrecord Apple [price] IFruit (subtotal [_] price) (subtotal [_ discount] (- price discount)))
[(subtotal (->Apple 100)) (subtotal (->Apple 100) 5)]
"]
(is (= [100 95] (tu/eval* prog {})))))
(extend-type String IFruit (subtotal ([s] (count s)) ([s discount] (- (count s) discount))))
[(subtotal (->Apple 100)) (subtotal (->Apple 100) 5) (subtotal \"foo\") (subtotal \"foo\" 2)]
"
prog #?(:clj prog
:cljs (-> prog
(str/replace "String" "js/String")))]
(is (= [100 95 3 1] (tu/eval* prog #?(:clj {}
:cljs {:classes {:allow :all
'js #js {:String js/String}}}))))))

#?(:clj
(deftest import-test
Expand Down

0 comments on commit af176c0

Please sign in to comment.