Skip to content

Commit 15bc1af

Browse files
committedFeb 27, 2024
* correct doc string
* support vars * add test case
1 parent fdff564 commit 15bc1af

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed
 

‎src/main/cljs/cljs/core.cljs

+10-3
Original file line numberDiff line numberDiff line change
@@ -11886,10 +11886,17 @@ reduces them without incurring seq initialization"
1188611886
x))
1188711887

1188811888
(defn test
11889-
"test [v] finds fn at key :test in var metadata and calls it,
11890-
presuming failure will throw exception"
11889+
"test [v] - if var, finds fn at key :test in var metadata, if function, finds
11890+
special test property. Calls it, presuming failure will throw exception.
11891+
11892+
Examples:
11893+
11894+
(test my-fn) ;; :ok
11895+
(test #'my-fn) ;; :ok"
1189111896
[v]
11892-
(let [f (.-cljs$lang$test v)]
11897+
(let [f (if (instance? Var v)
11898+
(-> v meta :test)
11899+
(some-> v .-cljs$lang$test))]
1189311900
(if f
1189411901
(do (f) :ok)
1189511902
:no-test)))

‎src/test/cljs/cljs/core_test.cljs

+15-3
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@
20062006
IDeref
20072007
(-deref [_]
20082008
(:x @a))
2009-
2009+
20102010
ISwap
20112011
(-swap! [o f]
20122012
(:x (swap! a update :x f)))
@@ -2016,7 +2016,7 @@
20162016
(:x (swap! a update :x f x y)))
20172017
(-swap! [o f x y zs]
20182018
(:x (swap! a #(apply update % :x f x y zs))))
2019-
2019+
20202020
IReset
20212021
(-reset! [o new-value]
20222022
(:x (swap! a assoc :x new-value))))]
@@ -2031,7 +2031,7 @@
20312031
(is (= 11 @c))
20322032
(is (= 0 (reset! c 0)))
20332033
(is (= 0 @c))
2034-
2034+
20352035
(is (= [0 1] (swap-vals! c inc)))
20362036
(is (= 1 @c))
20372037
(is (= [1 2] (swap-vals! c + 1)))
@@ -2042,3 +2042,15 @@
20422042
(is (= 11 @c))
20432043
(is (= [11 0] (reset-vals! c 0)))
20442044
(is (= 0 @c)))))
2045+
2046+
(defn cljs-3411-function
2047+
"this function adds two numbers"
2048+
{:test #(do
2049+
(assert (= (cljs-3411-function 2 3) 5))
2050+
(assert (= (cljs-3411-function 4 4) 8)))}
2051+
([x y] (+ x y)))
2052+
2053+
(deftest cljs-3411
2054+
(testing "cljs.core/test respects docstring"
2055+
(is (= :ok (test cljs-3411)))
2056+
(is (= :ok (test #'cljs-3411)))))

0 commit comments

Comments
 (0)