Skip to content

Commit af176c0

Browse files
committed
[#406] Tests for multi-arity protocols
1 parent 00331ca commit af176c0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

test/sci/protocols_test.cljc

+9-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,15 @@
117117
(let [prog "
118118
(defprotocol IFruit (subtotal [item] [item subtotal]))
119119
(defrecord Apple [price] IFruit (subtotal [_] price) (subtotal [_ discount] (- price discount)))
120-
[(subtotal (->Apple 100)) (subtotal (->Apple 100) 5)]
121-
"]
122-
(is (= [100 95] (tu/eval* prog {})))))
120+
(extend-type String IFruit (subtotal ([s] (count s)) ([s discount] (- (count s) discount))))
121+
[(subtotal (->Apple 100)) (subtotal (->Apple 100) 5) (subtotal \"foo\") (subtotal \"foo\" 2)]
122+
"
123+
prog #?(:clj prog
124+
:cljs (-> prog
125+
(str/replace "String" "js/String")))]
126+
(is (= [100 95 3 1] (tu/eval* prog #?(:clj {}
127+
:cljs {:classes {:allow :all
128+
'js #js {:String js/String}}}))))))
123129

124130
#?(:clj
125131
(deftest import-test

0 commit comments

Comments
 (0)