diff --git a/test/clojure/core_test/abs.cljc b/test/clojure/core_test/abs.cljc index 675e9a7b..8a84cebf 100644 --- a/test/clojure/core_test/abs.cljc +++ b/test/clojure/core_test/abs.cljc @@ -1,25 +1,28 @@ (ns clojure.core-test.abs - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - (t/is (thrown? NullPointerException (abs nil))) - (t/are [in ex] (= ex (abs in)) - -1 1 - 1 1 - Long/MIN_VALUE Long/MIN_VALUE ; Special case! - -1.0 1.0 - -0.0 0.0 - ##-Inf ##Inf - ##Inf ##Inf - -123.456M 123.456M - -123N 123N - -1/5 1/5) - (t/is (NaN? (abs ##NaN)))) +(p/when-var-exists clojure.core/abs + (deftest test-abs + (testing "common" + (are [in ex] (= ex (abs in)) + -1 1 + 1 1 + Long/MIN_VALUE Long/MIN_VALUE ; Special case! + -1.0 1.0 + -0.0 0.0 + ##-Inf ##Inf + ##Inf ##Inf + -123.456M 123.456M + -123N 123N + -1/5 1/5) + (is (NaN? (abs ##NaN))) + (is (thrown? NullPointerException (abs nil)))) -(t/deftest unboxed - (let [a 42 - b -42 - a' (abs a) - b' (abs b)] - (t/is (= 42 a')) - (t/is (= 42 b')))) + (testing "unboxed" + (let [a 42 + b -42 + a' (abs a) + b' (abs b)] + (is (= 42 a')) + (is (= 42 b')))))) diff --git a/test/clojure/core_test/aclone.cljc b/test/clojure/core_test/aclone.cljc index c9cb250f..d2b988f3 100644 --- a/test/clojure/core_test/aclone.cljc +++ b/test/clojure/core_test/aclone.cljc @@ -1,27 +1,30 @@ (ns clojure.core-test.aclone - (:require [clojure.test :as t :refer [deftest is]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(defn clone-test - [a b] - (aset a 0 1) - (aset a 1 2) - (aset a 2 3) - (let [a' (aclone a) - b' (aclone b)] - (is (= 3 (alength a'))) - (is (every? identity (map #(= (aget a %) (aget a' %)) (range 3)))) - (is (zero? (alength b'))) - (is (not (identical? a a'))) - (is (not (identical? b b'))) - (aset a 1 11) - (is (= 11 (aget a 1))) - (is (= 2 (aget a' 1))) - (aset a' 2 12) - (is (= 3 (aget a 2))) - (is (= 12 (aget a' 2))))) +(p/when-var-exists clojure.core/aclone + (defn clone-test + [a b] + (aset a 0 1) + (aset a 1 2) + (aset a 2 3) + (let [a' (aclone a) + b' (aclone b)] + (is (= 3 (alength a'))) + (is (every? identity (map #(= (aget a %) (aget a' %)) (range 3)))) + (is (zero? (alength b'))) + (is (not (identical? a a'))) + (is (not (identical? b b'))) + (aset a 1 11) + (is (= 11 (aget a 1))) + (is (= 2 (aget a' 1))) + (aset a' 2 12) + (is (= 3 (aget a 2))) + (is (= 12 (aget a' 2))))) -(deftest integer-arrays - (clone-test (int-array 3) (int-array 0))) + (deftest test-aclone + (testing "integer-arrays" + (clone-test (int-array 3) (int-array 0))) -(deftest object-arrays - (clone-test (object-array 3) (object-array 0))) + (testing "object-arrays" + (clone-test (object-array 3) (object-array 0))))) diff --git a/test/clojure/core_test/add_watch.cljc b/test/clojure/core_test/add_watch.cljc index 9d013f69..32a39a32 100644 --- a/test/clojure/core_test/add_watch.cljc +++ b/test/clojure/core_test/add_watch.cljc @@ -1,299 +1,302 @@ (ns clojure.core-test.add-watch - (:require [clojure.test :as t :refer [is]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) (def testvar 40) -(t/deftest watch-atom - ;; checks atoms and interspersed multiple watches - (let [state (volatile! []) - tester1 (fn [key ref old new] (vswap! state conj {:key key :ref ref :old old :new new :tester 1})) - tester2 (fn [key ref old new] (vswap! state conj {:key key :ref ref :old old :new new :tester 2})) - err (fn [key ref old new] - (throw (ex-info "test" {:key key :ref ref :old old :new new :tester :err}))) - a (atom 0) - r (atom 10) - update! (fn [] - (let [do-update (fn [x op] - (try - (op x inc) - (catch clojure.lang.ExceptionInfo e - (let [{:keys [old] :as data} (ex-data e)] - (vswap! state conj data)))))] - (do-update a swap!) - (do-update r swap!) - (do-update #'testvar alter-var-root))) - keyed (fn [k s] (filter #(= k (:key %)) s))] - - ;; check removing something that isn't there - (is (= a (remove-watch a :one))) - ;; check removing nil - (is (= a (remove-watch a nil))) - - ;; add a watch to the atom - (is (= a (add-watch a :a tester1))) - (is (= r (add-watch r :r tester1))) - (is (= #'testvar (add-watch #'testvar :v tester1))) - (update!) +(p/when-var-exists clojure.core/add-watch + (deftest watch-atom + ;; checks atoms and interspersed multiple watches + (let [state (volatile! []) + tester1 (fn [key ref old new] (vswap! state conj {:key key :ref ref :old old :new new :tester 1})) + tester2 (fn [key ref old new] (vswap! state conj {:key key :ref ref :old old :new new :tester 2})) + err (fn [key ref old new] + (throw (ex-info "test" {:key key :ref ref :old old :new new :tester :err}))) + a (atom 0) + r (atom 10) + update! (fn [] + (let [do-update (fn [x op] + (try + (op x inc) + (catch clojure.lang.ExceptionInfo e + (let [{:keys [old] :as data} (ex-data e)] + (vswap! state conj data)))))] + (do-update a swap!) + (do-update r swap!) + (do-update #'testvar alter-var-root))) + keyed (fn [k s] (filter #(= k (:key %)) s))] + + ;; check removing something that isn't there + (is (= a (remove-watch a :one))) + ;; check removing nil + (is (= a (remove-watch a nil))) + + ;; add a watch to the atom + (is (= a (add-watch a :a tester1))) + (is (= r (add-watch r :r tester1))) + (is (= #'testvar (add-watch #'testvar :v tester1))) + (update!) - ;; add a second watch to the atom - new key - (add-watch a :s tester2) - (add-watch r :s tester2) - (add-watch #'testvar :s tester2) - (update!) - - ;; replace the first watch by reusing the keys - (add-watch a :a tester2) - (add-watch r :r tester2) - (add-watch #'testvar :v tester2) - (update!) - - ;; remove the first watche - (is (= a (remove-watch a :a))) - (is (= r (remove-watch r :r))) - (is (= #'testvar (remove-watch #'testvar :v))) - (update!) - - ;; check progress - (let [checkdata [{:key :a :ref a :old 0 :new 1 :tester 1} - {:key :r :ref r :old 10 :new 11 :tester 1} - {:key :v :ref #'testvar :old 40 :new 41 :tester 1} - - {:key :a :ref a :old 1 :new 2 :tester 1} - {:key :r :ref r :old 11 :new 12 :tester 1} - {:key :v :ref #'testvar :old 41 :new 42 :tester 1} - {:key :s :ref a :old 1 :new 2 :tester 2} - {:key :s :ref r :old 11 :new 12 :tester 2} - {:key :s :ref #'testvar :old 41 :new 42 :tester 2} - - {:key :a :ref a :old 2 :new 3 :tester 2} - {:key :r :ref r :old 12 :new 13 :tester 2} - {:key :v :ref #'testvar :old 42 :new 43 :tester 2} - {:key :s :ref a :old 2 :new 3 :tester 2} - {:key :s :ref r :old 12 :new 13 :tester 2} - {:key :s :ref #'testvar :old 42 :new 43 :tester 2} - - {:key :s :ref a :old 3 :new 4 :tester 2} - {:key :s :ref r :old 13 :new 14 :tester 2} - {:key :s :ref #'testvar :old 43 :new 44 :tester 2}]] - (is (= (keyed :a checkdata) (keyed :a @state))) - (is (= (keyed :r checkdata) (keyed :r @state))) - (is (= (keyed :v checkdata) (keyed :v @state))) - (vreset! state []) - - ;; remove the second watche - should be no updates - (remove-watch a :s) - (remove-watch r :s) - (remove-watch #'testvar :s) - (update!) - (is (empty? @state)) - - ;; add the first again, and check if it still works - (add-watch a :a tester1) - (add-watch r :r tester1) - (add-watch #'testvar :v tester1) - (update!) - - (is (= [{:key :a :ref a :old 5 :new 6 :tester 1}] (keyed :a @state))) - (is (= [{:key :r :ref r :old 15 :new 16 :tester 1}] (keyed :r @state))) - (is (= [{:key :v :ref #'testvar :old 45 :new 46 :tester 1}] (keyed :v @state))) - - ;; add error watch - (add-watch a :e err) - (add-watch r :e err) - (add-watch #'testvar :e err) - (update!) - - ;; The final watch may or may not have gone to :a before the error - ;; so remove this if it is there - (is (= #{{:key :a :ref a :old 5 :new 6 :tester 1}} - (disj (set (keyed :a @state)) - {:key :a :ref a :old 6 :new 7 :tester 1}))) - (is (= #{{:key :r :ref r :old 15 :new 16 :tester 1}} - (disj (set (keyed :r @state)) - {:key :r :ref r :old 16 :new 17 :tester 1}))) - (is (= #{{:key :v :ref #'testvar :old 45 :new 46 :tester 1}} - (disj (set (keyed :v @state)) - {:key :v :ref #'testvar :old 46 :new 47 :tester 1}))) - - (is (= #{{:key :e :ref a :old 6 :new 7 :tester :err} - {:key :e :ref r :old 16 :new 17 :tester :err} - {:key :e :ref #'testvar :old 46 :new 47 :tester :err}} - (set (keyed :e @state))))))) - -#?(:cljs nil - :default - (t/deftest watch-ref - (let [state (volatile! []) - tester1 (fn [key ref old new] (vswap! state conj {:key key :ref ref :old old :new new :tester 1})) - tester2 (fn [key ref old new] (vswap! state conj {:key key :ref ref :old old :new new :tester 2})) - err (fn [key ref old new] - (throw (ex-info "test" {:key key :ref ref :old old :new new :tester :err}))) - r (ref 10) - update! (fn [] - (try - (dosync (ref-set r (inc @r))) - (catch clojure.lang.ExceptionInfo e - (let [{:keys [old] :as data} (ex-data e)] - (vswap! state conj data))))) - keyed (fn [k s] (filter #(= k (:key %)) s))] - - ;; add a watch to the ref - (is (= r (add-watch r :r tester1))) - (update!) - - ;; add a second watch to the ref - (add-watch r :s tester2) + ;; add a second watch to the atom - new key + (add-watch a :s tester2) + (add-watch r :s tester2) + (add-watch #'testvar :s tester2) + (update!) + + ;; replace the first watch by reusing the keys + (add-watch a :a tester2) + (add-watch r :r tester2) + (add-watch #'testvar :v tester2) + (update!) + + ;; remove the first watche + (is (= a (remove-watch a :a))) + (is (= r (remove-watch r :r))) + (is (= #'testvar (remove-watch #'testvar :v))) + (update!) + + ;; check progress + (let [checkdata [{:key :a :ref a :old 0 :new 1 :tester 1} + {:key :r :ref r :old 10 :new 11 :tester 1} + {:key :v :ref #'testvar :old 40 :new 41 :tester 1} + + {:key :a :ref a :old 1 :new 2 :tester 1} + {:key :r :ref r :old 11 :new 12 :tester 1} + {:key :v :ref #'testvar :old 41 :new 42 :tester 1} + {:key :s :ref a :old 1 :new 2 :tester 2} + {:key :s :ref r :old 11 :new 12 :tester 2} + {:key :s :ref #'testvar :old 41 :new 42 :tester 2} + + {:key :a :ref a :old 2 :new 3 :tester 2} + {:key :r :ref r :old 12 :new 13 :tester 2} + {:key :v :ref #'testvar :old 42 :new 43 :tester 2} + {:key :s :ref a :old 2 :new 3 :tester 2} + {:key :s :ref r :old 12 :new 13 :tester 2} + {:key :s :ref #'testvar :old 42 :new 43 :tester 2} + + {:key :s :ref a :old 3 :new 4 :tester 2} + {:key :s :ref r :old 13 :new 14 :tester 2} + {:key :s :ref #'testvar :old 43 :new 44 :tester 2}]] + (is (= (keyed :a checkdata) (keyed :a @state))) + (is (= (keyed :r checkdata) (keyed :r @state))) + (is (= (keyed :v checkdata) (keyed :v @state))) + (vreset! state []) + + ;; remove the second watche - should be no updates + (remove-watch a :s) + (remove-watch r :s) + (remove-watch #'testvar :s) (update!) + (is (empty? @state)) - ;; replace the first watch by reusing the key - (add-watch r :r tester2) + ;; add the first again, and check if it still works + (add-watch a :a tester1) + (add-watch r :r tester1) + (add-watch #'testvar :v tester1) (update!) - ;; remove the first watch - (is (= r (remove-watch r :r))) - (update!) + (is (= [{:key :a :ref a :old 5 :new 6 :tester 1}] (keyed :a @state))) + (is (= [{:key :r :ref r :old 15 :new 16 :tester 1}] (keyed :r @state))) + (is (= [{:key :v :ref #'testvar :old 45 :new 46 :tester 1}] (keyed :v @state))) - ;; check progress - (let [checkdata [{:key :r :ref r :old 10 :new 11 :tester 1} - - {:key :r :ref r :old 11 :new 12 :tester 1} - {:key :s :ref r :old 11 :new 12 :tester 2} - - {:key :r :ref r :old 12 :new 13 :tester 2} - {:key :s :ref r :old 12 :new 13 :tester 2} - - {:key :s :ref r :old 13 :new 14 :tester 2}]] - (is (= (keyed :r checkdata) (keyed :r @state))) - (vreset! state []) - - ;; remove the second watch - should be no updates - (remove-watch r :s) - (update!) - (is (empty? @state)) - - ;; add the first again, and check if is still works - (add-watch r :r tester1) - (update!) - - (is (= [{:key :r :ref r :old 15 :new 16 :tester 1}] (keyed :r @state))) - - ;; add error watch - (add-watch r :e err) - (update!) - - ;; The final watch may or may not have gone to :r before the error - ;; so remove this if it is there - (is (= #{{:key :r :ref r :old 15 :new 16 :tester 1}} - (disj (set (keyed :r @state)) - {:key :r :ref r :old 16 :new 17 :tester 1}))) - (is (= [{:key :e :ref r :old 16 :new 17 :tester :err}] - (keyed :e @state))))))) - -#?(:clj (defn sleep [n] (Thread/sleep n))) - -#?(:cljs nil - :default - (t/deftest watch-agents - (let [state (volatile! []) - tester1 (fn [key ref old new] - (when (not= old new) - (vswap! state conj {:key key :old old :new new :tester 1}))) - tester2 (fn [key ref old new] - (when (not= old new) - (vswap! state conj {:key key :old old :new new :tester 2}))) - agent-end (promise) - err (fn [key ref old new] - (deliver agent-end :done) - (throw (ex-info "test" {:key key :old old :new new :tester :err}))) - g (agent 20) - update! (fn [] - (when-let [e (agent-error g)] - (vswap! state conj (ex-data e)) - (restart-agent g :ready)) - (send g inc)) - keyed (fn [k s] (set (filter #(= k (:key %)) s)))] - - ;; add a watch to the agent - (is (= g (add-watch g :g tester1))) - (update!) - (await g) - (is (= [{:key :g :old 20 :new 21 :tester 1}] - @state)) - - ;; add a second watch - new key - (add-watch g :s tester2) - (update!) - (await g) - (is (= #{{:key :g :old 20 :new 21 :tester 1} - {:key :g :old 21 :new 22 :tester 1} - {:key :s :old 21 :new 22 :tester 2}} - (set @state))) - - ;; replace the first watch by reusing the key - (add-watch g :g tester2) + ;; add error watch + (add-watch a :e err) + (add-watch r :e err) + (add-watch #'testvar :e err) (update!) - (await g) - (is (= #{{:key :g :old 20 :new 21 :tester 1} - {:key :g :old 21 :new 22 :tester 1} - {:key :s :old 21 :new 22 :tester 2} - {:key :g :old 22 :new 23 :tester 2} - {:key :s :old 22 :new 23 :tester 2}} - (set @state))) - - ;; remove the first watch - (is (= g (remove-watch g :g))) - (update!) - (await g) - (is (= #{{:key :g :old 20 :new 21 :tester 1} - {:key :g :old 21 :new 22 :tester 1} - {:key :s :old 21 :new 22 :tester 2} - {:key :g :old 22 :new 23 :tester 2} - {:key :s :old 22 :new 23 :tester 2} - {:key :s :old 23 :new 24 :tester 2}} - (set @state))) - - ;; remove the second watches - should be no updates - (remove-watch g :s) - (update!) - (await g) - (is (= #{{:key :g :old 20 :new 21 :tester 1} - {:key :g :old 21 :new 22 :tester 1} - {:key :s :old 21 :new 22 :tester 2} - {:key :g :old 22 :new 23 :tester 2} - {:key :s :old 22 :new 23 :tester 2} - {:key :s :old 23 :new 24 :tester 2}} - (set @state))) - ;; add the first again, and check if it still works - (add-watch g :g tester1) - (update!) - (await g) - (is (= #{{:key :g :old 20 :new 21 :tester 1} - {:key :g :old 21 :new 22 :tester 1} - {:key :s :old 21 :new 22 :tester 2} - {:key :g :old 22 :new 23 :tester 2} - {:key :s :old 22 :new 23 :tester 2} - {:key :s :old 23 :new 24 :tester 2} - {:key :g :old 25 :new 26 :tester 1}} - (set @state))) - - ;; add error watches - (add-watch g :e err) - (update!) - (deref agent-end) - (sleep 1) - (if-let [e (agent-error g)] - (do - (is (= {:key :e :old 26 :new 27 :tester :err} (ex-data e))) - ;; The final call may not have gone to tester 1 - (is (= #{{:key :g :old 20 :new 21 :tester 1} - {:key :g :old 21 :new 22 :tester 1} - {:key :s :old 21 :new 22 :tester 2} - {:key :g :old 22 :new 23 :tester 2} - {:key :s :old 22 :new 23 :tester 2} - {:key :s :old 23 :new 24 :tester 2} - {:key :g :old 25 :new 26 :tester 1}} - (disj (set @state) {:key :g :old 26 :new 27 :tester 1})))) - (println "Unexpected lack of error")) - - (shutdown-agents)))) + ;; The final watch may or may not have gone to :a before the error + ;; so remove this if it is there + (is (= #{{:key :a :ref a :old 5 :new 6 :tester 1}} + (disj (set (keyed :a @state)) + {:key :a :ref a :old 6 :new 7 :tester 1}))) + (is (= #{{:key :r :ref r :old 15 :new 16 :tester 1}} + (disj (set (keyed :r @state)) + {:key :r :ref r :old 16 :new 17 :tester 1}))) + (is (= #{{:key :v :ref #'testvar :old 45 :new 46 :tester 1}} + (disj (set (keyed :v @state)) + {:key :v :ref #'testvar :old 46 :new 47 :tester 1}))) + + (is (= #{{:key :e :ref a :old 6 :new 7 :tester :err} + {:key :e :ref r :old 16 :new 17 :tester :err} + {:key :e :ref #'testvar :old 46 :new 47 :tester :err}} + (set (keyed :e @state))))))) + + #?(:cljs nil + :default + (deftest watch-ref + (let [state (volatile! []) + tester1 (fn [key ref old new] (vswap! state conj {:key key :ref ref :old old :new new :tester 1})) + tester2 (fn [key ref old new] (vswap! state conj {:key key :ref ref :old old :new new :tester 2})) + err (fn [key ref old new] + (throw (ex-info "test" {:key key :ref ref :old old :new new :tester :err}))) + r (ref 10) + update! (fn [] + (try + (dosync (ref-set r (inc @r))) + (catch clojure.lang.ExceptionInfo e + (let [{:keys [old] :as data} (ex-data e)] + (vswap! state conj data))))) + keyed (fn [k s] (filter #(= k (:key %)) s))] + + ;; add a watch to the ref + (is (= r (add-watch r :r tester1))) + (update!) + + ;; add a second watch to the ref + (add-watch r :s tester2) + (update!) + + ;; replace the first watch by reusing the key + (add-watch r :r tester2) + (update!) + + ;; remove the first watch + (is (= r (remove-watch r :r))) + (update!) + + ;; check progress + (let [checkdata [{:key :r :ref r :old 10 :new 11 :tester 1} + + {:key :r :ref r :old 11 :new 12 :tester 1} + {:key :s :ref r :old 11 :new 12 :tester 2} + + {:key :r :ref r :old 12 :new 13 :tester 2} + {:key :s :ref r :old 12 :new 13 :tester 2} + + {:key :s :ref r :old 13 :new 14 :tester 2}]] + (is (= (keyed :r checkdata) (keyed :r @state))) + (vreset! state []) + + ;; remove the second watch - should be no updates + (remove-watch r :s) + (update!) + (is (empty? @state)) + + ;; add the first again, and check if is still works + (add-watch r :r tester1) + (update!) + + (is (= [{:key :r :ref r :old 15 :new 16 :tester 1}] (keyed :r @state))) + + ;; add error watch + (add-watch r :e err) + (update!) + + ;; The final watch may or may not have gone to :r before the error + ;; so remove this if it is there + (is (= #{{:key :r :ref r :old 15 :new 16 :tester 1}} + (disj (set (keyed :r @state)) + {:key :r :ref r :old 16 :new 17 :tester 1}))) + (is (= [{:key :e :ref r :old 16 :new 17 :tester :err}] + (keyed :e @state))))))) + + #?(:clj (defn sleep [n] (Thread/sleep n))) + + #?(:cljs nil + :default + (deftest watch-agents + (let [state (volatile! []) + tester1 (fn [key ref old new] + (when (not= old new) + (vswap! state conj {:key key :old old :new new :tester 1}))) + tester2 (fn [key ref old new] + (when (not= old new) + (vswap! state conj {:key key :old old :new new :tester 2}))) + agent-end (promise) + err (fn [key ref old new] + (deliver agent-end :done) + (throw (ex-info "test" {:key key :old old :new new :tester :err}))) + g (agent 20) + update! (fn [] + (when-let [e (agent-error g)] + (vswap! state conj (ex-data e)) + (restart-agent g :ready)) + (send g inc)) + keyed (fn [k s] (set (filter #(= k (:key %)) s)))] + + ;; add a watch to the agent + (is (= g (add-watch g :g tester1))) + (update!) + (await g) + (is (= [{:key :g :old 20 :new 21 :tester 1}] + @state)) + + ;; add a second watch - new key + (add-watch g :s tester2) + (update!) + (await g) + (is (= #{{:key :g :old 20 :new 21 :tester 1} + {:key :g :old 21 :new 22 :tester 1} + {:key :s :old 21 :new 22 :tester 2}} + (set @state))) + + ;; replace the first watch by reusing the key + (add-watch g :g tester2) + (update!) + (await g) + (is (= #{{:key :g :old 20 :new 21 :tester 1} + {:key :g :old 21 :new 22 :tester 1} + {:key :s :old 21 :new 22 :tester 2} + {:key :g :old 22 :new 23 :tester 2} + {:key :s :old 22 :new 23 :tester 2}} + (set @state))) + + ;; remove the first watch + (is (= g (remove-watch g :g))) + (update!) + (await g) + (is (= #{{:key :g :old 20 :new 21 :tester 1} + {:key :g :old 21 :new 22 :tester 1} + {:key :s :old 21 :new 22 :tester 2} + {:key :g :old 22 :new 23 :tester 2} + {:key :s :old 22 :new 23 :tester 2} + {:key :s :old 23 :new 24 :tester 2}} + (set @state))) + + ;; remove the second watches - should be no updates + (remove-watch g :s) + (update!) + (await g) + (is (= #{{:key :g :old 20 :new 21 :tester 1} + {:key :g :old 21 :new 22 :tester 1} + {:key :s :old 21 :new 22 :tester 2} + {:key :g :old 22 :new 23 :tester 2} + {:key :s :old 22 :new 23 :tester 2} + {:key :s :old 23 :new 24 :tester 2}} + (set @state))) + + ;; add the first again, and check if it still works + (add-watch g :g tester1) + (update!) + (await g) + (is (= #{{:key :g :old 20 :new 21 :tester 1} + {:key :g :old 21 :new 22 :tester 1} + {:key :s :old 21 :new 22 :tester 2} + {:key :g :old 22 :new 23 :tester 2} + {:key :s :old 22 :new 23 :tester 2} + {:key :s :old 23 :new 24 :tester 2} + {:key :g :old 25 :new 26 :tester 1}} + (set @state))) + + ;; add error watches + (add-watch g :e err) + (update!) + (deref agent-end) + (sleep 1) + (if-let [e (agent-error g)] + (do + (is (= {:key :e :old 26 :new 27 :tester :err} (ex-data e))) + ;; The final call may not have gone to tester 1 + (is (= #{{:key :g :old 20 :new 21 :tester 1} + {:key :g :old 21 :new 22 :tester 1} + {:key :s :old 21 :new 22 :tester 2} + {:key :g :old 22 :new 23 :tester 2} + {:key :s :old 22 :new 23 :tester 2} + {:key :s :old 23 :new 24 :tester 2} + {:key :g :old 25 :new 26 :tester 1}} + (disj (set @state) {:key :g :old 26 :new 27 :tester 1})))) + (println "Unexpected lack of error")) + + (shutdown-agents)))) + ) diff --git a/test/clojure/core_test/and.cljc b/test/clojure/core_test/and.cljc index 76f10568..bd1de8ec 100644 --- a/test/clojure/core_test/and.cljc +++ b/test/clojure/core_test/and.cljc @@ -1,33 +1,36 @@ (ns clojure.core-test.and - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - (t/is (= true (and))) - (t/are [x] (= x (and x)) - true - false - nil - :example) - (t/are [ex a b] (= ex (and a b)) - true true true - false true false - false false true - false false false - true true true - nil true nil - nil nil true - nil nil nil) - (t/testing "binds values before comparing" - (let [counter (volatile! 0)] - (t/is (= nil (and (vswap! counter inc) nil))) - (t/is (= 1 @counter)))) - (t/testing "early exits" - (let [counter (volatile! 0)] - (t/is (= nil (and nil (vswap! counter inc)))) - (t/is (= 0 @counter)))) - (t/testing "handles varargs" - (t/is (= nil (and nil nil 3))) - (t/is (= nil (and nil nil nil nil nil nil nil nil nil nil nil nil true))))) +(p/when-var-exists clojure.core/and + (deftest test-and + (testing "common" + (is (= true (and))) + (are [x] (= x (and x)) + true + false + nil + :example) + (are [ex a b] (= ex (and a b)) + true true true + false true false + false false true + false false false + true true true + nil true nil + nil nil true + nil nil nil) + (testing "binds values before comparing" + (let [counter (volatile! 0)] + (is (= nil (and (vswap! counter inc) nil))) + (is (= 1 @counter)))) + (testing "early exits" + (let [counter (volatile! 0)] + (is (= nil (and nil (vswap! counter inc)))) + (is (= 0 @counter)))) + (testing "handles varargs" + (is (= nil (and nil nil 3))) + (is (= nil (and nil nil nil nil nil nil nil nil nil nil nil nil true))))) -(t/deftest infinite-sequence - (t/is (some? (and (range))))) + (testing "infinite-sequence" + (is (some? (and (range))))))) diff --git a/test/clojure/core_test/any.cljc b/test/clojure/core_test/any.cljc deleted file mode 100644 index 7f7326a4..00000000 --- a/test/clojure/core_test/any.cljc +++ /dev/null @@ -1,14 +0,0 @@ -(ns clojure.core-test.any - (:require [clojure.test :as t])) - -(t/deftest common - (t/are [x] (= true (any? x)) - nil - true - false - "" - 0 - 1)) - -(t/deftest infinite-sequence - (t/is (= true (any? (range))))) diff --git a/test/clojure/core_test/any_questionmark.cljc b/test/clojure/core_test/any_questionmark.cljc new file mode 100644 index 00000000..06e98784 --- /dev/null +++ b/test/clojure/core_test/any_questionmark.cljc @@ -0,0 +1,17 @@ +(ns clojure.core-test.any-questionmark + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) + +(p/when-var-exists clojure.core/any? + (deftest test-any? + (testing "common" + (are [x] (= true (any? x)) + nil + true + false + "" + 0 + 1)) + + (testing "infinite-sequence" + (is (= true (any? (range))))))) diff --git a/test/clojure/core_test/bigdec.cljc b/test/clojure/core_test/bigdec.cljc index b15b657d..8d3020d2 100644 --- a/test/clojure/core_test/bigdec.cljc +++ b/test/clojure/core_test/bigdec.cljc @@ -1,24 +1,26 @@ (ns clojure.core-test.bigdec - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-bigdec - (are [expected x] (= expected (bigdec x)) - 1M 1 - 0M 0 - -1M -1 - 1M 1N - 0M 0N - -1M -1N - 1M 1.0 - 0M 0.0 - -1M -1.0 - 0.5M 1/2 - 0M 0/2 - -0.5M -1/2) +(p/when-var-exists clojure.core/bigdec + (deftest test-bigdec + (are [expected x] (= expected (bigdec x)) + 1M 1 + 0M 0 + -1M -1 + 1M 1N + 0M 0N + -1M -1N + 1M 1.0 + 0M 0.0 + -1M -1.0 + 0.5M 1/2 + 0M 0/2 + -0.5M -1/2) - ;; `bigdec` must produce objects that satisfy `decimal?` - (is (decimal? (bigdec 1))) + ;; `bigdec` must produce objects that satisfy `decimal?` + (is (decimal? (bigdec 1))) - #?@(:cljs nil - :default - [(is (instance? java.math.BigDecimal (bigdec 1)))])) + #?@(:cljs nil + :default + [(is (instance? java.math.BigDecimal (bigdec 1)))]))) diff --git a/test/clojure/core_test/bigint.cljc b/test/clojure/core_test/bigint.cljc index abaef7c3..6aad0553 100644 --- a/test/clojure/core_test/bigint.cljc +++ b/test/clojure/core_test/bigint.cljc @@ -1,28 +1,30 @@ (ns clojure.core-test.bigint (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-bigint - (are [expected x] (= expected (bigint x)) - 1N 1 - 0N 0 - -1N -1 - #?@(:cljs nil - :clj [179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000N r/max-double]) - 1N 1.0 - 0N 0.0 - -1N -1.0 - 1N 12/12 - 0N 0/12 - -1N -12/12) +(p/when-var-exists clojure.core/bigint + (deftest test-bigint + (are [expected x] (= expected (bigint x)) + 1N 1 + 0N 0 + -1N -1 + #?@(:cljs nil + :clj [179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000N r/max-double]) + 1N 1.0 + 0N 0.0 + -1N -1.0 + 1N 12/12 + 0N 0/12 + -1N -12/12) - ;; Validate that we correctly promote from int to bigint with `inc'` and `dec'`. - (is (= 9223372036854775808N (inc (bigint r/max-int)) (inc' r/max-int))) - (is (= -9223372036854775809N (dec (bigint r/min-int)) (dec' r/min-int))) + ;; Validate that we correctly promote from int to bigint with `inc'` and `dec'`. + (is (= 9223372036854775808N (inc (bigint r/max-int)) (inc' r/max-int))) + (is (= -9223372036854775809N (dec (bigint r/min-int)) (dec' r/min-int))) - #?@(:cljs nil - :default - [(is (instance? clojure.lang.BigInt (bigint 0))) - (is (instance? clojure.lang.BigInt (bigint 0.0))) - (is (instance? clojure.lang.BigInt (inc' r/max-int))) - (is (instance? clojure.lang.BigInt (dec' r/min-int)))])) + #?@(:cljs nil + :default + [(is (instance? clojure.lang.BigInt (bigint 0))) + (is (instance? clojure.lang.BigInt (bigint 0.0))) + (is (instance? clojure.lang.BigInt (inc' r/max-int))) + (is (instance? clojure.lang.BigInt (dec' r/min-int)))]))) diff --git a/test/clojure/core_test/bit_and.cljc b/test/clojure/core_test/bit_and.cljc index 1b9f4f02..0b5a5897 100644 --- a/test/clojure/core_test/bit_and.cljc +++ b/test/clojure/core_test/bit_and.cljc @@ -1,20 +1,22 @@ (ns clojure.core-test.bit-and - (:require [clojure.test :as t] - [clojure.core-test.number-range :as r])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-and nil 1))) - :cljs (t/is (bit-and nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-and 1 nil))) - :cljs (t/is (bit-and 1 nil))) +(p/when-var-exists clojure.core/bit-and + (deftest test-bit-and + #?(:clj (is (thrown? NullPointerException (bit-and nil 1))) + :cljs (is (bit-and nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-and 1 nil))) + :cljs (is (bit-and 1 nil))) - (t/are [ex a b] (= ex (bit-and a b)) - 8 12 9 - 8 8 0xff - 0 r/all-ones-int 0 - 0 0 r/all-ones-int - r/all-ones-int r/all-ones-int r/all-ones-int - 0 r/full-width-checker-pos 0 - r/full-width-checker-pos r/full-width-checker-pos r/full-width-checker-pos - r/full-width-checker-pos r/full-width-checker-pos r/all-ones-int - 0 r/full-width-checker-pos r/full-width-checker-neg)) + (are [ex a b] (= ex (bit-and a b)) + 8 12 9 + 8 8 0xff + 0 r/all-ones-int 0 + 0 0 r/all-ones-int + r/all-ones-int r/all-ones-int r/all-ones-int + 0 r/full-width-checker-pos 0 + r/full-width-checker-pos r/full-width-checker-pos r/full-width-checker-pos + r/full-width-checker-pos r/full-width-checker-pos r/all-ones-int + 0 r/full-width-checker-pos r/full-width-checker-neg))) diff --git a/test/clojure/core_test/bit_and_not.cljc b/test/clojure/core_test/bit_and_not.cljc index fa57c997..d1cbcb84 100644 --- a/test/clojure/core_test/bit_and_not.cljc +++ b/test/clojure/core_test/bit_and_not.cljc @@ -1,22 +1,24 @@ (ns clojure.core-test.bit-and-not - (:require [clojure.test :as t] - [clojure.core-test.number-range :as r])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-and-not nil 1))) - :cljs (t/is (bit-and-not nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-and-not 1 nil))) - :cljs (t/is (bit-and-not 1 nil))) +(p/when-var-exists clojure.core/bit-and-not + (deftest test-bit-and-not + #?(:clj (is (thrown? NullPointerException (bit-and-not nil 1))) + :cljs (is (bit-and-not nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-and-not 1 nil))) + :cljs (is (bit-and-not 1 nil))) - (t/are [ex a b] (= ex (bit-and-not a b)) - 0 0 0 - 8 12 4 - 0xff 0xff 0 - 0x80 0xff 0x7f - r/all-ones-int r/all-ones-int 0 - 0 0 r/all-ones-int - 0 r/all-ones-int r/all-ones-int - r/full-width-checker-pos r/full-width-checker-pos 0 - 0 r/full-width-checker-pos r/full-width-checker-pos - 0 r/full-width-checker-pos r/all-ones-int - r/full-width-checker-pos r/full-width-checker-pos r/full-width-checker-neg)) + (are [ex a b] (= ex (bit-and-not a b)) + 0 0 0 + 8 12 4 + 0xff 0xff 0 + 0x80 0xff 0x7f + r/all-ones-int r/all-ones-int 0 + 0 0 r/all-ones-int + 0 r/all-ones-int r/all-ones-int + r/full-width-checker-pos r/full-width-checker-pos 0 + 0 r/full-width-checker-pos r/full-width-checker-pos + 0 r/full-width-checker-pos r/all-ones-int + r/full-width-checker-pos r/full-width-checker-pos r/full-width-checker-neg))) diff --git a/test/clojure/core_test/bit_clear.cljc b/test/clojure/core_test/bit_clear.cljc index 397d6d71..0cf3f4ad 100644 --- a/test/clojure/core_test/bit_clear.cljc +++ b/test/clojure/core_test/bit_clear.cljc @@ -1,11 +1,13 @@ (ns clojure.core-test.bit-clear - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-clear nil 1))) - :cljs (t/is (bit-clear nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-clear 1 nil))) - :cljs (t/is (bit-clear 1 nil))) +(p/when-var-exists clojure.core/bit-clear + (deftest test-bit-clear + #?(:clj (is (thrown? NullPointerException (bit-clear nil 1))) + :cljs (is (bit-clear nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-clear 1 nil))) + :cljs (is (bit-clear 1 nil))) - (t/are [ex a b] (= ex (bit-clear a b)) - 3 11 3)) + (are [ex a b] (= ex (bit-clear a b)) + 3 11 3))) diff --git a/test/clojure/core_test/bit_flip.cljc b/test/clojure/core_test/bit_flip.cljc index d49bdaf5..962c505e 100644 --- a/test/clojure/core_test/bit_flip.cljc +++ b/test/clojure/core_test/bit_flip.cljc @@ -1,12 +1,14 @@ (ns clojure.core-test.bit-flip - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-flip nil 1))) - :cljs (t/is (bit-flip nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-flip 1 nil))) - :cljs (t/is (bit-flip 1 nil))) +(p/when-var-exists clojure.core/bit-flip + (deftest test-bit-flip + #?(:clj (is (thrown? NullPointerException (bit-flip nil 1))) + :cljs (is (bit-flip nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-flip 1 nil))) + :cljs (is (bit-flip 1 nil))) - (t/are [ex a b] (= ex (bit-flip a b)) - 2r1111 2r1011 2 - 2r1011 2r1111 2)) + (are [ex a b] (= ex (bit-flip a b)) + 2r1111 2r1011 2 + 2r1011 2r1111 2))) diff --git a/test/clojure/core_test/bit_not.cljc b/test/clojure/core_test/bit_not.cljc index 61b00ab3..ac851600 100644 --- a/test/clojure/core_test/bit_not.cljc +++ b/test/clojure/core_test/bit_not.cljc @@ -1,10 +1,12 @@ (ns clojure.core-test.bit-not - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common -#?(:clj (t/is (thrown? NullPointerException (bit-not nil))) - :cljs (t/is (bit-not nil))) +(p/when-var-exists clojure.core/bit-not + (deftest test-bit-not + #?(:clj (is (thrown? NullPointerException (bit-not nil))) + :cljs (is (bit-not nil))) - (t/are [ex a] (= ex (bit-not a)) - -2r1000 2r0111 - 2r0111 -2r1000)) + (are [ex a] (= ex (bit-not a)) + -2r1000 2r0111 + 2r0111 -2r1000))) diff --git a/test/clojure/core_test/bit_or.cljc b/test/clojure/core_test/bit_or.cljc index bee5eeb6..c6c54cbf 100644 --- a/test/clojure/core_test/bit_or.cljc +++ b/test/clojure/core_test/bit_or.cljc @@ -1,21 +1,23 @@ (ns clojure.core-test.bit-or - (:require [clojure.test :as t] - [clojure.core-test.number-range :as r])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-or nil 1))) - :cljs (t/is (bit-or nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-or 1 nil))) - :cljs (t/is (bit-or 1 nil))) +(p/when-var-exists clojure.core/bit-or + (deftest test-bit-or + #?(:clj (is (thrown? NullPointerException (bit-or nil 1))) + :cljs (is (bit-or nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-or 1 nil))) + :cljs (is (bit-or 1 nil))) - (t/are [ex a b] (= ex (bit-or a b)) - 2r1101 2r1100 2r1001 - 1 1 0 - r/all-ones-int r/all-ones-int 0 - r/all-ones-int 0 r/all-ones-int - r/all-ones-int r/all-ones-int r/all-ones-int - r/full-width-checker-pos r/full-width-checker-pos 0 - r/full-width-checker-pos r/full-width-checker-pos r/full-width-checker-pos - r/all-ones-int r/full-width-checker-pos r/all-ones-int - r/all-ones-int r/full-width-checker-pos r/full-width-checker-neg)) + (are [ex a b] (= ex (bit-or a b)) + 2r1101 2r1100 2r1001 + 1 1 0 + r/all-ones-int r/all-ones-int 0 + r/all-ones-int 0 r/all-ones-int + r/all-ones-int r/all-ones-int r/all-ones-int + r/full-width-checker-pos r/full-width-checker-pos 0 + r/full-width-checker-pos r/full-width-checker-pos r/full-width-checker-pos + r/all-ones-int r/full-width-checker-pos r/all-ones-int + r/all-ones-int r/full-width-checker-pos r/full-width-checker-neg))) diff --git a/test/clojure/core_test/bit_set.cljc b/test/clojure/core_test/bit_set.cljc index d7492488..db606374 100644 --- a/test/clojure/core_test/bit_set.cljc +++ b/test/clojure/core_test/bit_set.cljc @@ -1,16 +1,18 @@ (ns clojure.core-test.bit-set - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-set nil 1))) - :cljs (t/is (bit-set nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-set 1 nil))) - :cljs (t/is (bit-set 1 nil))) +(p/when-var-exists clojure.core/bit-set + (deftest test-bit-set + #?(:clj (is (thrown? NullPointerException (bit-set nil 1))) + :cljs (is (bit-set nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-set 1 nil))) + :cljs (is (bit-set 1 nil))) - (t/are [ex a b] (= ex (bit-set a b)) - 2r1111 2r1011 2 - -9223372036854775808 0 63 - 4294967296 0 32 - 65536 0 16 - 256 0 8 - 16 0 4)) + (are [ex a b] (= ex (bit-set a b)) + 2r1111 2r1011 2 + -9223372036854775808 0 63 + 4294967296 0 32 + 65536 0 16 + 256 0 8 + 16 0 4))) diff --git a/test/clojure/core_test/bit_shift_left.cljc b/test/clojure/core_test/bit_shift_left.cljc index 4c5c6093..5aa8dda1 100644 --- a/test/clojure/core_test/bit_shift_left.cljc +++ b/test/clojure/core_test/bit_shift_left.cljc @@ -1,12 +1,14 @@ (ns clojure.core-test.bit-shift-left - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-shift-left nil 1))) - :cljs (t/is (bit-shift-left nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-shift-left 1 nil))) - :cljs (t/is (bit-shift-left 1 nil))) +(p/when-var-exists clojure.core/bit-shift-left + (deftest test-bit-shift-left + #?(:clj (is (thrown? NullPointerException (bit-shift-left nil 1))) + :cljs (is (bit-shift-left nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-shift-left 1 nil))) + :cljs (is (bit-shift-left 1 nil))) - (t/are [ex a b] (= ex (bit-shift-left a b)) - 1024 1 10 - 2r110100 2r1101 2)) + (are [ex a b] (= ex (bit-shift-left a b)) + 1024 1 10 + 2r110100 2r1101 2))) diff --git a/test/clojure/core_test/bit_shift_right.cljc b/test/clojure/core_test/bit_shift_right.cljc index d551a66d..6e2eba80 100644 --- a/test/clojure/core_test/bit_shift_right.cljc +++ b/test/clojure/core_test/bit_shift_right.cljc @@ -1,16 +1,18 @@ (ns clojure.core-test.bit-shift-right - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-shift-right nil 1))) - :cljs (t/is (bit-shift-right nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-shift-right 1 nil))) - :cljs (t/is (bit-shift-right 1 nil))) +(p/when-var-exists clojure.core/bit-shift-right + (deftest test-bit-shift-right + #?(:clj (is (thrown? NullPointerException (bit-shift-right nil 1))) + :cljs (is (bit-shift-right nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-shift-right 1 nil))) + :cljs (is (bit-shift-right 1 nil))) - (t/are [ex a b] (= ex (bit-shift-right a b)) - 2r1101 2r1101 0 - 2r110 2r1101 1 - 2r11 2r1101 2 - 2r1 2r1101 3 - 2r0 2r1101 4 - 2r0 2r1101 63)) + (are [ex a b] (= ex (bit-shift-right a b)) + 2r1101 2r1101 0 + 2r110 2r1101 1 + 2r11 2r1101 2 + 2r1 2r1101 3 + 2r0 2r1101 4 + 2r0 2r1101 63))) diff --git a/test/clojure/core_test/bit_test.cljc b/test/clojure/core_test/bit_test.cljc index 2f94438a..7cf237a2 100644 --- a/test/clojure/core_test/bit_test.cljc +++ b/test/clojure/core_test/bit_test.cljc @@ -1,16 +1,18 @@ (ns clojure.core-test.bit-test - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-test nil 1))) - :cljs (t/is (bit-test nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-test 1 nil))) - :cljs (t/is (bit-test 1 nil))) +(p/when-var-exists clojure.core/bit-test + (deftest test-bit-test + #?(:clj (is (thrown? NullPointerException (bit-test nil 1))) + :cljs (is (bit-test nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-test 1 nil))) + :cljs (is (bit-test 1 nil))) - (t/are [ex a b] (= ex (bit-test a b)) - true 2r1001 0 - false 2r1001 1 - false 2r1001 2 - true 2r1001 3 - false 2r1001 4 - false 2r1001 63)) + (are [ex a b] (= ex (bit-test a b)) + true 2r1001 0 + false 2r1001 1 + false 2r1001 2 + true 2r1001 3 + false 2r1001 4 + false 2r1001 63))) diff --git a/test/clojure/core_test/bit_xor.cljc b/test/clojure/core_test/bit_xor.cljc index 14f0a304..baf99236 100644 --- a/test/clojure/core_test/bit_xor.cljc +++ b/test/clojure/core_test/bit_xor.cljc @@ -1,19 +1,21 @@ (ns clojure.core-test.bit-xor - (:require [clojure.test :as t] - [clojure.core-test.number-range :as r])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (bit-xor nil 1))) - :cljs (t/is (bit-xor nil 1))) - #?(:clj (t/is (thrown? NullPointerException (bit-xor 1 nil))) - :cljs (t/is (bit-xor 1 nil))) +(p/when-var-exists clojure.core/bit-xor + (deftest test-bit-xor + #?(:clj (is (thrown? NullPointerException (bit-xor nil 1))) + :cljs (is (bit-xor nil 1))) + #?(:clj (is (thrown? NullPointerException (bit-xor 1 nil))) + :cljs (is (bit-xor 1 nil))) - (t/are [ex a b] (= ex (bit-xor a b)) - 2r0101 2r1100 2r1001 - r/all-ones-int r/all-ones-int 0 - r/all-ones-int 0 r/all-ones-int - 0 r/all-ones-int r/all-ones-int - r/full-width-checker-pos r/full-width-checker-pos 0 - 0 r/full-width-checker-pos r/full-width-checker-pos - r/full-width-checker-neg r/full-width-checker-pos r/all-ones-int - r/all-ones-int r/full-width-checker-pos r/full-width-checker-neg)) + (are [ex a b] (= ex (bit-xor a b)) + 2r0101 2r1100 2r1001 + r/all-ones-int r/all-ones-int 0 + r/all-ones-int 0 r/all-ones-int + 0 r/all-ones-int r/all-ones-int + r/full-width-checker-pos r/full-width-checker-pos 0 + 0 r/full-width-checker-pos r/full-width-checker-pos + r/full-width-checker-neg r/full-width-checker-pos r/all-ones-int + r/all-ones-int r/full-width-checker-pos r/full-width-checker-neg))) diff --git a/test/clojure/core_test/boolean.cljc b/test/clojure/core_test/boolean.cljc index 7e08f108..d38b6179 100644 --- a/test/clojure/core_test/boolean.cljc +++ b/test/clojure/core_test/boolean.cljc @@ -1,56 +1,58 @@ (ns clojure.core-test.boolean (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-false? - (are [expected x] (= expected (boolean x)) - true 0 - true 1 - true -1 - true r/max-int - true r/min-int - true 0.0 - true 1.0 - true -1.0 - true (float 0.0) - true (float 1.0) - true (float -1.0) - true (double 0.0) - true (double 1.0) - true (double -1.0) - true r/max-double - true r/min-double - true ##Inf - true ##-Inf - true ##NaN - true 0N - true 1N - true -1N - true 0/2 - true 1/2 - true -1/2 - true 0.0M - true 1.0M - true -1.0M - false nil - true true - false false - true "a string" - true "0" - true "1" - true "-1" - true "true" - true "false" - true {:a :map} - true #{:a-set} - true [:a :vector] - true '(:a :list) - true \0 - true \1 - true :a-keyword - true :true - true :false - true :0 - true :1 - true :-1 - true 'a-sym)) +(p/when-var-exists clojure.core/boolean + (deftest test-boolean + (are [expected x] (= expected (boolean x)) + true 0 + true 1 + true -1 + true r/max-int + true r/min-int + true 0.0 + true 1.0 + true -1.0 + true (float 0.0) + true (float 1.0) + true (float -1.0) + true (double 0.0) + true (double 1.0) + true (double -1.0) + true r/max-double + true r/min-double + true ##Inf + true ##-Inf + true ##NaN + true 0N + true 1N + true -1N + true 0/2 + true 1/2 + true -1/2 + true 0.0M + true 1.0M + true -1.0M + false nil + true true + false false + true "a string" + true "0" + true "1" + true "-1" + true "true" + true "false" + true {:a :map} + true #{:a-set} + true [:a :vector] + true '(:a :list) + true \0 + true \1 + true :a-keyword + true :true + true :false + true :0 + true :1 + true :-1 + true 'a-sym))) diff --git a/test/clojure/core_test/byte.cljc b/test/clojure/core_test/byte.cljc index bcbc480e..bff5ee20 100644 --- a/test/clojure/core_test/byte.cljc +++ b/test/clojure/core_test/byte.cljc @@ -1,46 +1,47 @@ (ns clojure.core-test.byte - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-byte - ;; There is no platform independent predicate to test for a - ;; byte (e.g., `byte?`). In ClojureJVM, it's an instance of - ;; `java.lang.Byte`, but there is no predicate for it. Here, we just - ;; test whether it's a fixed-length integer of some sort. - (is (int? (byte 0))) - #?@(:cljs nil - :default - [(is (instance? java.lang.Byte (byte 0)))]) +(p/when-var-exists clojure.core/byte + (deftest test-byte + ;; There is no platform independent predicate to test for a + ;; byte (e.g., `byte?`). In ClojureJVM, it's an instance of + ;; `java.lang.Byte`, but there is no predicate for it. Here, we just + ;; test whether it's a fixed-length integer of some sort. + (is (int? (byte 0))) + #?@(:cljs nil + :default + [(is (instance? java.lang.Byte (byte 0)))]) - ;; Check conversions and rounding from other numeric types - (are [expected x] (= expected (byte x)) - -128 -128 - 0 0 - 127 127 - 1 1N - 0 0N - -1 -1N - 1 1.0M - 0 0.0M - -1 -1.0M - 1 1.1 - -1 -1.1 - 1 1.9 - 1 3/2 - -1 -3/2 - 0 1/10 - 0 -1/10 - 1 1.1M - -1 -1.1M) + ;; Check conversions and rounding from other numeric types + (are [expected x] (= expected (byte x)) + -128 -128 + 0 0 + 127 127 + 1 1N + 0 0N + -1 -1N + 1 1.0M + 0 0.0M + -1 -1.0M + 1 1.1 + -1 -1.1 + 1 1.9 + 1 3/2 + -1 -3/2 + 0 1/10 + 0 -1/10 + 1 1.1M + -1 -1.1M) - ;; `byte` throws outside the range of 127 ... -128. - (is (thrown? IllegalArgumentException (byte -128.000001))) - (is (thrown? IllegalArgumentException (byte -129))) - (is (thrown? IllegalArgumentException (byte 128))) - (is (thrown? IllegalArgumentException (byte 127.000001))) - - ;; Check handling of other types - (is (thrown? ClassCastException (byte "0"))) - (is (thrown? ClassCastException (byte :0))) - (is (thrown? ClassCastException (byte [0]))) - (is (thrown? Exception (byte nil)))) + ;; `byte` throws outside the range of 127 ... -128. + (is (thrown? IllegalArgumentException (byte -128.000001))) + (is (thrown? IllegalArgumentException (byte -129))) + (is (thrown? IllegalArgumentException (byte 128))) + (is (thrown? IllegalArgumentException (byte 127.000001))) + ;; Check handling of other types + (is (thrown? ClassCastException (byte "0"))) + (is (thrown? ClassCastException (byte :0))) + (is (thrown? ClassCastException (byte [0]))) + (is (thrown? Exception (byte nil))))) diff --git a/test/clojure/core_test/char.cljc b/test/clojure/core_test/char.cljc index 53c0eadf..fdf5d14e 100644 --- a/test/clojure/core_test/char.cljc +++ b/test/clojure/core_test/char.cljc @@ -1,16 +1,17 @@ (ns clojure.core-test.char - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-char - (are [expected x] (= expected (char x)) - ;; Assumes ASCII / Unicode - \space 32 - \@ 64 - \A 65 - \A \A - ;; TODO: Add Unicode tests - ) - - (is (thrown? IllegalArgumentException (char -1))) - (is (thrown? Exception (char nil)))) +(p/when-var-exists clojure.core/char + (deftest test-char + (are [expected x] (= expected (char x)) + ;; Assumes ASCII / Unicode + \space 32 + \@ 64 + \A 65 + \A \A + ;; TODO: Add Unicode tests + ) + (is (thrown? IllegalArgumentException (char -1))) + (is (thrown? Exception (char nil))))) diff --git a/test/clojure/core_test/char_questionmark.cljc b/test/clojure/core_test/char_questionmark.cljc index 85b6bca7..cf6735c4 100644 --- a/test/clojure/core_test/char_questionmark.cljc +++ b/test/clojure/core_test/char_questionmark.cljc @@ -1,54 +1,57 @@ (ns clojure.core-test.char-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-char? - (are [expected x] (= expected (char? x)) - false 0 - false 1 - false -1 - false r/max-int - false r/min-int - false 0.0 - false 1.0 - false -1.0 - false (float 0.0) - false (float 1.0) - false (float -1.0) - false (double 0.0) - false (double 1.0) - false (double -1.0) - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - false 0N - false 1N - false -1N - false 0/2 - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - true \0 - true \1 - true \A - true \space - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/char? + (deftest test-char? + (are [expected x] (= expected (char? x)) + false 0 + false 1 + false -1 + false r/max-int + false r/min-int + false 0.0 + false 1.0 + false -1.0 + false (float 0.0) + false (float 1.0) + false (float -1.0) + false (double 0.0) + false (double 1.0) + false (double -1.0) + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + false 1N + false -1N + false 0/2 + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + true \0 + true \1 + true \A + true \space + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym)) + ) diff --git a/test/clojure/core_test/compare.cljc b/test/clojure/core_test/compare.cljc index 9735eccd..d71e62cd 100644 --- a/test/clojure/core_test/compare.cljc +++ b/test/clojure/core_test/compare.cljc @@ -1,55 +1,58 @@ (ns clojure.core-test.compare - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest numeric-types - (t/are [r args] (= r (compare (first args) (second args))) - -1 [0 10] - 0 [0 0] - 1 [0 -100N] - 0 [1 1.0] - -1 [1 100/3] - -1 [0 0x01] - -1 [0 2r01] - 1 [1 nil]) +(p/when-var-exists clojure.core/compare + (deftest test-compare + (testing "numeric-types" + (are [r args] (= r (compare (first args) (second args))) + -1 [0 10] + 0 [0 0] + 1 [0 -100N] + 0 [1 1.0] + -1 [1 100/3] + -1 [0 0x01] + -1 [0 2r01] + 1 [1 nil]) - (t/is (thrown? Exception (compare 1 [])))) + (is (thrown? Exception (compare 1 [])))) -(t/deftest lexical-types - (t/are [r args] (= r (compare (first args) (second args))) - -1 [\a \b] - 0 [\0 \0] - 25 [\z \a] - -1 ["cat" "dog"] - -1 ['cat 'dog] - -1 [:cat :dog] - 0 [:dog :dog] - -1 [:cat :animal/cat] - 1 ['a nil]) + (testing "lexical-types" + (are [r args] (= r (compare (first args) (second args))) + -1 [\a \b] + 0 [\0 \0] + 25 [\z \a] + -1 ["cat" "dog"] + -1 ['cat 'dog] + -1 [:cat :dog] + 0 [:dog :dog] + -1 [:cat :animal/cat] + 1 ['a nil]) - (t/is (thrown? Exception (compare "a" []))) - (t/is (thrown? Exception (compare "cat" '(\c \a \t))))) + (is (thrown? Exception (compare "a" []))) + (is (thrown? Exception (compare "cat" '(\c \a \t))))) -(t/deftest collection-types - (t/are [r args] (= r (compare (first args) (second args))) - 0 [[] []] - 1 [[3] [1]] - -1 [[] [1 2]] - -1 [[] [[]]] - 0 [#{} #{}] - 0 [{} {}] - 0 [(array-map) (array-map)] - 0 [(hash-map) (hash-map)] - 0 [{} (hash-map)] - 0 [{} (array-map)] - 0 ['() '()] - 1 [[] nil]) + (testing "collection-types" + (are [r args] (= r (compare (first args) (second args))) + 0 [[] []] + 1 [[3] [1]] + -1 [[] [1 2]] + -1 [[] [[]]] + 0 [#{} #{}] + 0 [{} {}] + 0 [(array-map) (array-map)] + 0 [(hash-map) (hash-map)] + 0 [{} (hash-map)] + 0 [{} (array-map)] + 0 ['() '()] + 1 [[] nil]) - (t/is (thrown? Exception (compare [] '()))) - (t/is (thrown? Exception (compare [1] [[]]))) - (t/is (thrown? Exception (compare [] {}))) - (t/is (thrown? Exception (compare [] #{}))) - (t/is (thrown? Exception (compare #{} (sorted-set)))) - (t/is (thrown? Exception (compare #{1} #{1}))) - (t/is (thrown? Exception (compare {1 2} {1 2}))) - (t/is (thrown? Exception (compare (range 5) (range 5)))) - (t/is (thrown? Exception (compare (range 5) (range))))) + (is (thrown? Exception (compare [] '()))) + (is (thrown? Exception (compare [1] [[]]))) + (is (thrown? Exception (compare [] {}))) + (is (thrown? Exception (compare [] #{}))) + (is (thrown? Exception (compare #{} (sorted-set)))) + (is (thrown? Exception (compare #{1} #{1}))) + (is (thrown? Exception (compare {1 2} {1 2}))) + (is (thrown? Exception (compare (range 5) (range 5)))) + (is (thrown? Exception (compare (range 5) (range))))))) diff --git a/test/clojure/core_test/dec.cljc b/test/clojure/core_test/dec.cljc index d082731b..bceb9bb5 100644 --- a/test/clojure/core_test/dec.cljc +++ b/test/clojure/core_test/dec.cljc @@ -1,27 +1,30 @@ (ns clojure.core-test.dec - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest common - (are [in ex] (= (dec in) ex) - 1 0 - 0 -1 - 1N 0N - 0N -1N - 14412 14411 - -3 -4 - 7.4 6.4 ; risky - 3/2 1/2 - 1/2 -1/2 - ##Inf ##Inf - ##-Inf ##-Inf) +(p/when-var-exists clojure.core/dec + (deftest test-dec + (testing "common" + (are [in ex] (= (dec in) ex) + 1 0 + 0 -1 + 1N 0N + 0N -1N + 14412 14411 + -3 -4 + 7.4 6.4 ; risky + 3/2 1/2 + 1/2 -1/2 + ##Inf ##Inf + ##-Inf ##-Inf) - (is (NaN? (dec ##NaN)))) + (is (NaN? (dec ##NaN)))) -(deftest underflow - #?(:clj (is (thrown? ArithmeticException (dec Long/MIN_VALUE))) - :cljs (is (= (dec js/Number.MIN_SAFE_INTEGER) (- js/Number.MIN_SAFE_INTEGER 2))))) + (testing "underflow" + #?(:clj (is (thrown? ArithmeticException (dec Long/MIN_VALUE))) + :cljs (is (= (dec js/Number.MIN_SAFE_INTEGER) (- js/Number.MIN_SAFE_INTEGER 2))))) -(deftest dec-nil - ;; ClojureScript says (= -1 (dec nil)) because JavaScript casts null to 0 - #?(:clj (is (thrown? NullPointerException (dec #_:clj-kondo/ignore nil))) - :cljs (is (= -1 (dec #_:clj-kondo/ignore nil))))) + (testing "dec-nil" + ;; ClojureScript says (= -1 (dec nil)) because JavaScript casts null to 0 + #?(:clj (is (thrown? NullPointerException (dec #_:clj-kondo/ignore nil))) + :cljs (is (= -1 (dec #_:clj-kondo/ignore nil))))))) diff --git a/test/clojure/core_test/decimal_questionmark.cljc b/test/clojure/core_test/decimal_questionmark.cljc index 5d865010..9f40f03c 100644 --- a/test/clojure/core_test/decimal_questionmark.cljc +++ b/test/clojure/core_test/decimal_questionmark.cljc @@ -1,46 +1,48 @@ (ns clojure.core-test.decimal-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-decimal? - (are [expected x] (= expected (decimal? x)) - false 0 - false 1 - false -1 - false r/max-int - false r/min-int - false 0.0 - false 1.0 - false -1.0 - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - false 0N - false 1N - false -1N - false 0/2 - false 1/2 - false -1/2 - true 0.0M - true 1.0M - true -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/decimal? + (deftest test-decimal? + (are [expected x] (= expected (decimal? x)) + false 0 + false 1 + false -1 + false r/max-int + false r/min-int + false 0.0 + false 1.0 + false -1.0 + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + false 1N + false -1N + false 0/2 + false 1/2 + false -1/2 + true 0.0M + true 1.0M + true -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/denominator.cljc b/test/clojure/core_test/denominator.cljc index fd000788..bcdde3e8 100644 --- a/test/clojure/core_test/denominator.cljc +++ b/test/clojure/core_test/denominator.cljc @@ -2,7 +2,7 @@ (:require [clojure.test :as t :refer [deftest testing is are]] [clojure.core-test.portability :as p])) -(p/when-var-exists 'clojure.core/denominator +(p/when-var-exists clojure.core/denominator (deftest test-denominator (is (= 2 (denominator 1/2))) (is (= 3 (denominator 2/3))) diff --git a/test/clojure/core_test/double.cljc b/test/clojure/core_test/double.cljc index eaef8584..cd5b8dfa 100644 --- a/test/clojure/core_test/double.cljc +++ b/test/clojure/core_test/double.cljc @@ -1,27 +1,29 @@ (ns clojure.core-test.double - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-double - (are [expected x] (= expected (double x)) - (double 1.0) 1 - (double 0.0) 0 - (double -1.0) -1 - (double 1.0) 1N - (double 0.0) 0N - (double -1.0) -1N - (double 1.0) 12/12 - (double 0.0) 0/12 - (double -1.0) -12/12 - (double 1.0) 1.0M - (double 0.0) 0.0M - (double -1.0) -1.0M) - (is (NaN? (double ##NaN))) +(p/when-var-exists clojure.core/double + (deftest test-double + (are [expected x] (= expected (double x)) + (double 1.0) 1 + (double 0.0) 0 + (double -1.0) -1 + (double 1.0) 1N + (double 0.0) 0N + (double -1.0) -1N + (double 1.0) 12/12 + (double 0.0) 0/12 + (double -1.0) -12/12 + (double 1.0) 1.0M + (double 0.0) 0.0M + (double -1.0) -1.0M) + (is (NaN? (double ##NaN))) - #?@(:cljs nil - :default - [(is (instance? java.lang.Double (double 0))) - (is (instance? java.lang.Double (double 0.0))) - (is (instance? java.lang.Double (double 0N))) - (is (instance? java.lang.Double (double 0.0M)))]) - (is (thrown? ClassCastException (double "0"))) - (is (thrown? ClassCastException (double :0)))) + #?@(:cljs nil + :default + [(is (instance? java.lang.Double (double 0))) + (is (instance? java.lang.Double (double 0.0))) + (is (instance? java.lang.Double (double 0N))) + (is (instance? java.lang.Double (double 0.0M)))]) + (is (thrown? ClassCastException (double "0"))) + (is (thrown? ClassCastException (double :0))))) diff --git a/test/clojure/core_test/double_questionmark.cljc b/test/clojure/core_test/double_questionmark.cljc index ba109b48..889628db 100644 --- a/test/clojure/core_test/double_questionmark.cljc +++ b/test/clojure/core_test/double_questionmark.cljc @@ -1,52 +1,54 @@ (ns clojure.core-test.double-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-double? - (are [expected x] (= expected (double? x)) - false 0 - false 1 - false -1 - false r/max-int - false r/min-int - true 0.0 - true 1.0 - true -1.0 - false (float 0.0) ; surprising since (float? (double 0.0)) = true - false (float 1.0) ; surprising since (float? (double 1.0)) = true - false (float -1.0) ; surprising since (float? (double -1.0)) = true - true (double 0.0) - true (double 1.0) - true (double -1.0) - true r/max-double - true r/min-double - true ##Inf - true ##-Inf - true ##NaN - false 0N - false 1N - false -1N - false 0/2 - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/double? + (deftest test-double? + (are [expected x] (= expected (double? x)) + false 0 + false 1 + false -1 + false r/max-int + false r/min-int + true 0.0 + true 1.0 + true -1.0 + false (float 0.0) ; surprising since (float? (double 0.0)) = true + false (float 1.0) ; surprising since (float? (double 1.0)) = true + false (float -1.0) ; surprising since (float? (double -1.0)) = true + true (double 0.0) + true (double 1.0) + true (double -1.0) + true r/max-double + true r/min-double + true ##Inf + true ##-Inf + true ##NaN + false 0N + false 1N + false -1N + false 0/2 + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/even_questionmark.cljc b/test/clojure/core_test/even_questionmark.cljc index 0eaca022..dfe16d9c 100644 --- a/test/clojure/core_test/even_questionmark.cljc +++ b/test/clojure/core_test/even_questionmark.cljc @@ -1,25 +1,28 @@ (ns clojure.core-test.even-questionmark - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - (t/are [in ex] (= (even? in) ex) - 0 true - -0 true - 12 true - 17 false - -118 true - -119 false - 123N false - 122N true - -121N false - -120N true)) +(p/when-var-exists clojure.core/even? + (deftest test-even? + (testing "common" + (are [in ex] (= (even? in) ex) + 0 true + -0 true + 12 true + 17 false + -118 true + -119 false + 123N false + 122N true + -121N false + -120N true)) -(t/deftest invalid - (t/are [x] (thrown? #?(:clj IllegalArgumentException :cljs js/Error) (even? x)) - #_:clj-kondo/ignore nil - ##Inf - ##-Inf - ##NaN - 1.5 - 1/2 - 0.2M)) + (testing "invalid" + (are [x] (thrown? #?(:clj IllegalArgumentException :cljs js/Error) (even? x)) + #_:clj-kondo/ignore nil + ##Inf + ##-Inf + ##NaN + 1.5 + 1/2 + 0.2M)))) diff --git a/test/clojure/core_test/false_questionmark.cljc b/test/clojure/core_test/false_questionmark.cljc index 61f7d33f..2702109e 100644 --- a/test/clojure/core_test/false_questionmark.cljc +++ b/test/clojure/core_test/false_questionmark.cljc @@ -1,56 +1,58 @@ (ns clojure.core-test.false-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-false? - (are [expected x] (= expected (false? x)) - false 0 - false 1 - false -1 - false r/max-int - false r/min-int - false 0.0 - false 1.0 - false -1.0 - false (float 0.0) - false (float 1.0) - false (float -1.0) - false (double 0.0) - false (double 1.0) - false (double -1.0) - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - false 0N - false 1N - false -1N - false 0/2 - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - true false - false "a string" - false "0" - false "1" - false "-1" - false "true" - false "false" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :true - false :false - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/false? + (deftest test-false? + (are [expected x] (= expected (false? x)) + false 0 + false 1 + false -1 + false r/max-int + false r/min-int + false 0.0 + false 1.0 + false -1.0 + false (float 0.0) + false (float 1.0) + false (float -1.0) + false (double 0.0) + false (double 1.0) + false (double -1.0) + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + false 1N + false -1N + false 0/2 + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + true false + false "a string" + false "0" + false "1" + false "-1" + false "true" + false "false" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :true + false :false + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/float.cljc b/test/clojure/core_test/float.cljc index 0a1cb50f..b81db7e0 100644 --- a/test/clojure/core_test/float.cljc +++ b/test/clojure/core_test/float.cljc @@ -1,33 +1,35 @@ (ns clojure.core-test.float (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-float - (are [expected x] (= expected (float x)) - (float 1.0) 1 - (float 0.0) 0 - (float -1.0) -1 - (float 1.0) 1N - (float 0.0) 0N - (float -1.0) -1N - (float 1.0) 12/12 - (float 0.0) 0/12 - (float -1.0) -12/12 - (float 1.0) 1.0M - (float 0.0) 0.0M - (float -1.0) -1.0M - (float 0.0) r/min-double) - (is (NaN? (float ##NaN))) +(p/when-var-exists clojure.core/float + (deftest test-float + (are [expected x] (= expected (float x)) + (float 1.0) 1 + (float 0.0) 0 + (float -1.0) -1 + (float 1.0) 1N + (float 0.0) 0N + (float -1.0) -1N + (float 1.0) 12/12 + (float 0.0) 0/12 + (float -1.0) -12/12 + (float 1.0) 1.0M + (float 0.0) 0.0M + (float -1.0) -1.0M + (float 0.0) r/min-double) + (is (NaN? (float ##NaN))) - #?@(:cljs nil - :default - [(is (instance? java.lang.Float (float 0))) - (is (instance? java.lang.Float (float 0.0))) - (is (instance? java.lang.Float (float 0N))) - (is (instance? java.lang.Float (float 0.0M)))]) + #?@(:cljs nil + :default + [(is (instance? java.lang.Float (float 0))) + (is (instance? java.lang.Float (float 0.0))) + (is (instance? java.lang.Float (float 0N))) + (is (instance? java.lang.Float (float 0.0M)))]) - (is (thrown? IllegalArgumentException (float r/max-double))) - (is (thrown? IllegalArgumentException (float ##Inf))) - (is (thrown? IllegalArgumentException (float ##-Inf))) - (is (thrown? ClassCastException (float "0"))) - (is (thrown? ClassCastException (float :0)))) + (is (thrown? IllegalArgumentException (float r/max-double))) + (is (thrown? IllegalArgumentException (float ##Inf))) + (is (thrown? IllegalArgumentException (float ##-Inf))) + (is (thrown? ClassCastException (float "0"))) + (is (thrown? ClassCastException (float :0))))) diff --git a/test/clojure/core_test/float_questionmark.cljc b/test/clojure/core_test/float_questionmark.cljc index 5e309f90..ab38a22a 100644 --- a/test/clojure/core_test/float_questionmark.cljc +++ b/test/clojure/core_test/float_questionmark.cljc @@ -1,52 +1,54 @@ (ns clojure.core-test.float-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-float? - (are [expected x] (= expected (float? x)) - false 0 - false 1 - false -1 - false r/max-int - false r/min-int - true 0.0 - true 1.0 - true -1.0 - true (float 0.0) - true (float 1.0) - true (float -1.0) - true (double 0.0) - true (double 1.0) - true (double -1.0) - true r/max-double - true r/min-double - true ##Inf - true ##-Inf - true ##NaN - false 0N - false 1N - false -1N - false 0/2 - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/float? + (deftest test-float? + (are [expected x] (= expected (float? x)) + false 0 + false 1 + false -1 + false r/max-int + false r/min-int + true 0.0 + true 1.0 + true -1.0 + true (float 0.0) + true (float 1.0) + true (float -1.0) + true (double 0.0) + true (double 1.0) + true (double -1.0) + true r/max-double + true r/min-double + true ##Inf + true ##-Inf + true ##NaN + false 0N + false 1N + false -1N + false 0/2 + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/fnil.cljc b/test/clojure/core_test/fnil.cljc index 57c8dc66..c91ee5b7 100644 --- a/test/clojure/core_test/fnil.cljc +++ b/test/clojure/core_test/fnil.cljc @@ -1,31 +1,33 @@ (ns clojure.core-test.fnil - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(defn test-fn [& x] - (into [] x)) +(p/when-var-exists clojure.core/fnil + (defn test-fn [& x] + (into [] x)) -(def arg 'not-nil) + (def arg 'not-nil) -(t/deftest fnil-test - (let [arity-1 (fnil test-fn 100)] - (t/is (= [100] (arity-1 nil))) - (t/is (= [arg] (arity-1 arg)))) - (let [arity-2 (fnil test-fn 100 200)] - (t/is (= [100 200] (arity-2 nil nil))) - (t/is (= [arg 200] (arity-2 arg nil))) - (t/is (= [100 arg] (arity-2 nil arg))) - (t/is (= [arg arg] (arity-2 arg arg)))) - (let [arity-3 (fnil test-fn 100 200 300)] - (t/is (= [100 200 300] (arity-3 nil nil nil))) - (t/is (= [arg 200 300] (arity-3 arg nil nil))) - (t/is (= [100 arg 300] (arity-3 nil arg nil))) - (t/is (= [100 200 arg] (arity-3 nil nil arg))) - (t/is (= [arg arg 300] (arity-3 arg arg nil))) - (t/is (= [100 arg arg] (arity-3 nil arg arg))) - (t/is (= [arg 200 arg] (arity-3 arg nil arg))) - (t/is (= [arg arg arg] (arity-3 arg arg arg)))) - (let [arity-+ (fnil test-fn 100 200 300)] - (t/is (= [100 200 300 arg] (arity-+ nil nil nil arg))) - (t/is (= [arg 200 300 arg] (arity-+ arg nil nil arg))) - (t/is (= [100 arg 300 arg] (arity-+ nil arg nil arg))) - (t/is (= [100 200 arg arg] (arity-+ nil nil arg arg))))) + (deftest fnil-test + (let [arity-1 (fnil test-fn 100)] + (is (= [100] (arity-1 nil))) + (is (= [arg] (arity-1 arg)))) + (let [arity-2 (fnil test-fn 100 200)] + (is (= [100 200] (arity-2 nil nil))) + (is (= [arg 200] (arity-2 arg nil))) + (is (= [100 arg] (arity-2 nil arg))) + (is (= [arg arg] (arity-2 arg arg)))) + (let [arity-3 (fnil test-fn 100 200 300)] + (is (= [100 200 300] (arity-3 nil nil nil))) + (is (= [arg 200 300] (arity-3 arg nil nil))) + (is (= [100 arg 300] (arity-3 nil arg nil))) + (is (= [100 200 arg] (arity-3 nil nil arg))) + (is (= [arg arg 300] (arity-3 arg arg nil))) + (is (= [100 arg arg] (arity-3 nil arg arg))) + (is (= [arg 200 arg] (arity-3 arg nil arg))) + (is (= [arg arg arg] (arity-3 arg arg arg)))) + (let [arity-+ (fnil test-fn 100 200 300)] + (is (= [100 200 300 arg] (arity-+ nil nil nil arg))) + (is (= [arg 200 300 arg] (arity-+ arg nil nil arg))) + (is (= [100 arg 300 arg] (arity-+ nil arg nil arg))) + (is (= [100 200 arg arg] (arity-+ nil nil arg arg)))))) diff --git a/test/clojure/core_test/format.cljc b/test/clojure/core_test/format.cljc index b681c8ce..290e7ecd 100644 --- a/test/clojure/core_test/format.cljc +++ b/test/clojure/core_test/format.cljc @@ -1,6 +1,8 @@ (ns clojure.core-test.format - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) +(p/when-var-exists clojure.core/format ;;; Note that `format` presents a bit of a conundrum for ;;; testing. Clojure JVM delegates the formatting task to ;;; Java. ClojureScript doesn't implement `format`. Other Clojure @@ -12,8 +14,7 @@ ;;; characters passes through `format` unharmed. ;;; See: https://clojurians.slack.com/archives/C03SRH97FDK/p1733853098700809 -(deftest test-format - #?@(:cljs nil ; CLJS doesn't have `format` - :default - [(is (= "test" (format "test")))]) - ) + (deftest test-format + #?@(:cljs nil ; CLJS doesn't have `format` + :default + [(is (= "test" (format "test")))]))) diff --git a/test/clojure/core_test/ident_questionmark.cljc b/test/clojure/core_test/ident_questionmark.cljc index 3cd0da36..1cde8161 100644 --- a/test/clojure/core_test/ident_questionmark.cljc +++ b/test/clojure/core_test/ident_questionmark.cljc @@ -1,18 +1,20 @@ (ns clojure.core-test.ident-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-ident? - (are [expected x] (= expected (ident? x)) - true :a-keyword - true 'a-symbol - true :a-ns/a-keyword - true 'a-ns/a-keyword - false "a string" - false 0 - false 0N - false 0.0 - false 1/2 - false 0.0M - false false - false true - false nil)) +(p/when-var-exists clojure.core/ident? + (deftest test-ident? + (are [expected x] (= expected (ident? x)) + true :a-keyword + true 'a-symbol + true :a-ns/a-keyword + true 'a-ns/a-keyword + false "a string" + false 0 + false 0N + false 0.0 + false 1/2 + false 0.0M + false false + false true + false nil))) diff --git a/test/clojure/core_test/identical_questionmark.cljc b/test/clojure/core_test/identical_questionmark.cljc index 059fab42..1f6be9c2 100644 --- a/test/clojure/core_test/identical_questionmark.cljc +++ b/test/clojure/core_test/identical_questionmark.cljc @@ -1,15 +1,17 @@ (ns clojure.core-test.identical-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-identical? - ;; objects that are the same object are identical - (let [x (hash-map) - ;; this forces y to be a different object than x - y (-> (hash-map :a-key :a-val) - (dissoc :a-key))] - ;; x and y are equal, but they are not identical - (is (= x y)) - (is (not (identical? x y))) - ;; but each is identical with itself - (is (identical? x x)) - (is (identical? y y)))) +(p/when-var-exists clojure.core/identical? + (deftest test-identical? + ;; objects that are the same object are identical + (let [x (hash-map) + ;; this forces y to be a different object than x + y (-> (hash-map :a-key :a-val) + (dissoc :a-key))] + ;; x and y are equal, but they are not identical + (is (= x y)) + (is (not (identical? x y))) + ;; but each is identical with itself + (is (identical? x x)) + (is (identical? y y))))) diff --git a/test/clojure/core_test/inc.cljc b/test/clojure/core_test/inc.cljc index 80f45808..4b94200d 100644 --- a/test/clojure/core_test/inc.cljc +++ b/test/clojure/core_test/inc.cljc @@ -1,29 +1,32 @@ (ns clojure.core-test.inc - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest common - (are [in ex] (= (inc in) ex) - 0 1 - 1 2 - -1 0 - 0N 1N - -1N 0N - 14411 14412 - -4 -3 - 6.4 7.4 ; risky - 1/2 3/2 - -1/2 1/2 - ##Inf ##Inf - ##-Inf ##-Inf) +(p/when-var-exists clojure.core/inc + (deftest test-inc + (testing "common" + (are [in ex] (= (inc in) ex) + 0 1 + 1 2 + -1 0 + 0N 1N + -1N 0N + 14411 14412 + -4 -3 + 6.4 7.4 ; risky + 1/2 3/2 + -1/2 1/2 + ##Inf ##Inf + ##-Inf ##-Inf) - (is (NaN? (inc ##NaN)))) + (is (NaN? (inc ##NaN)))) -(deftest overflow - #?(:clj (is (thrown? ArithmeticException (inc Long/MAX_VALUE))) - :cljs (is (= (inc js/Number.MAX_SAFE_INTEGER) (+ 2 js/Number.MAX_SAFE_INTEGER))))) + (testing "overflow" + #?(:clj (is (thrown? ArithmeticException (inc Long/MAX_VALUE))) + :cljs (is (= (inc js/Number.MAX_SAFE_INTEGER) (+ 2 js/Number.MAX_SAFE_INTEGER))))) -(deftest inc-nil - ;; ClojureScript says (= 1 (inc nil)) because JavaScript casts null to 0 - ;; https://clojuredocs.org/clojure.core/inc#example-6156a59ee4b0b1e3652d754f - #?(:clj (is (thrown? NullPointerException (inc #_:clj-kondo/ignore nil))) - :cljs (is (= 1 (inc #_:clj-kondo/ignore nil))))) + (testing "inc-nil" + ;; ClojureScript says (= 1 (inc nil)) because JavaScript casts null to 0 + ;; https://clojuredocs.org/clojure.core/inc#example-6156a59ee4b0b1e3652d754f + #?(:clj (is (thrown? NullPointerException (inc #_:clj-kondo/ignore nil))) + :cljs (is (= 1 (inc #_:clj-kondo/ignore nil))))))) diff --git a/test/clojure/core_test/int.cljc b/test/clojure/core_test/int.cljc index 7144cfeb..0866b8e9 100644 --- a/test/clojure/core_test/int.cljc +++ b/test/clojure/core_test/int.cljc @@ -1,48 +1,49 @@ (ns clojure.core-test.int - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-int - ;; There is no platform independent predicate to test specifically - ;; for an int. While `int?` exists, it returns true for any - ;; fixed-range integer type (e.g., byte, short, int, or long). In - ;; ClojureJVM, it's an instance of `java.lang.Int`, but there is no - ;; predicate for it. Here, we just test whether it's a fixed-length - ;; integer of some sort. - (is (int? (int 0))) - #?@(:cljs nil - :default - [(is (instance? java.lang.Integer (int 0)))]) +(p/when-var-exists clojure.core/int + (deftest test-int + ;; There is no platform independent predicate to test specifically + ;; for an int. While `int?` exists, it returns true for any + ;; fixed-range integer type (e.g., byte, short, int, or long). In + ;; ClojureJVM, it's an instance of `java.lang.Int`, but there is no + ;; predicate for it. Here, we just test whether it's a fixed-length + ;; integer of some sort. + (is (int? (int 0))) + #?@(:cljs nil + :default + [(is (instance? java.lang.Integer (int 0)))]) - ;; Check conversions and rounding from other numeric types - (are [expected x] (= expected (int x)) - -2147483648 -2147483648 - 0 0 - 2147483647 2147483647 - 1 1N - 0 0N - -1 -1N - 1 1.0M - 0 0.0M - -1 -1.0M - 1 1.1 - -1 -1.1 - 1 1.9 - 1 3/2 - -1 -3/2 - 0 1/10 - 0 -1/10 - 1 1.1M - -1 -1.1M) + ;; Check conversions and rounding from other numeric types + (are [expected x] (= expected (int x)) + -2147483648 -2147483648 + 0 0 + 2147483647 2147483647 + 1 1N + 0 0N + -1 -1N + 1 1.0M + 0 0.0M + -1 -1.0M + 1 1.1 + -1 -1.1 + 1 1.9 + 1 3/2 + -1 -3/2 + 0 1/10 + 0 -1/10 + 1 1.1M + -1 -1.1M) - ;; `int` throws outside the range of 32767 ... -32768. - (is (thrown? IllegalArgumentException (int -2147483648.000001))) - (is (thrown? ArithmeticException (int -2147483649))) - (is (thrown? ArithmeticException (int 2147483648))) - (is (thrown? IllegalArgumentException (int 2147483647.000001))) - - ;; Check handling of other types - (is (thrown? ClassCastException (int "0"))) - (is (thrown? ClassCastException (int :0))) - (is (thrown? ClassCastException (int [0]))) - (is (thrown? Exception (int nil)))) + ;; `int` throws outside the range of 32767 ... -32768. + (is (thrown? IllegalArgumentException (int -2147483648.000001))) + (is (thrown? ArithmeticException (int -2147483649))) + (is (thrown? ArithmeticException (int 2147483648))) + (is (thrown? IllegalArgumentException (int 2147483647.000001))) + ;; Check handling of other types + (is (thrown? ClassCastException (int "0"))) + (is (thrown? ClassCastException (int :0))) + (is (thrown? ClassCastException (int [0]))) + (is (thrown? Exception (int nil))))) diff --git a/test/clojure/core_test/int_questionmark.cljc b/test/clojure/core_test/int_questionmark.cljc index 31f54215..bdd6abde 100644 --- a/test/clojure/core_test/int_questionmark.cljc +++ b/test/clojure/core_test/int_questionmark.cljc @@ -1,46 +1,48 @@ (ns clojure.core-test.int-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-int? - (are [expected x] (= expected (int? x)) - true 0 - true 1 - true -1 - true r/max-int - true r/min-int - false 0.0 - false 1.0 - false -1.0 - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - false 0N - false 1N - false -1N - true 0/2 ; perhaps surprising - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/int? + (deftest test-int? + (are [expected x] (= expected (int? x)) + true 0 + true 1 + true -1 + true r/max-int + true r/min-int + false 0.0 + false 1.0 + false -1.0 + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + false 1N + false -1N + true 0/2 ; perhaps surprising + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/integer_questionmark.cljc b/test/clojure/core_test/integer_questionmark.cljc index 18c633ac..4ad14619 100644 --- a/test/clojure/core_test/integer_questionmark.cljc +++ b/test/clojure/core_test/integer_questionmark.cljc @@ -1,46 +1,48 @@ (ns clojure.core-test.integer-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-integer? - (are [expected x] (= expected (integer? x)) - true 0 - true 1 - true -1 - true r/max-int - true r/min-int - false 0.0 - false 1.0 - false -1.0 - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - true 0N - true 1N - true -1N - true 0/2 ; perhaps surprising - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/integer? + (deftest test-integer? + (are [expected x] (= expected (integer? x)) + true 0 + true 1 + true -1 + true r/max-int + true r/min-int + false 0.0 + false 1.0 + false -1.0 + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + true 0N + true 1N + true -1N + true 0/2 ; perhaps surprising + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/intern.cljc b/test/clojure/core_test/intern.cljc index 8fe998a5..fff84e2b 100644 --- a/test/clojure/core_test/intern.cljc +++ b/test/clojure/core_test/intern.cljc @@ -1,23 +1,25 @@ (ns clojure.core-test.intern - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-intern - ;; Intern and bind - (let [x-var (intern 'clojure.core-test.intern 'x 42)] - (is (= 42 (var-get x-var)))) +(p/when-var-exists clojure.core/intern + (deftest test-intern + ;; Intern and bind + (let [x-var (intern 'clojure.core-test.intern 'x 42)] + (is (= 42 (var-get x-var)))) - ;; Use intern to return the previously interned var - (let [x-var (intern 'clojure.core-test.intern 'x)] - (is (= 42 (var-get x-var)))) + ;; Use intern to return the previously interned var + (let [x-var (intern 'clojure.core-test.intern 'x)] + (is (= 42 (var-get x-var)))) - ;; Create new namespace and use that as argument to intern - (let [n (create-ns 'avoid-a-clash) - x-var (intern n 'x 42)] - (is (= 42 (var-get x-var)))) + ;; Create new namespace and use that as argument to intern + (let [n (create-ns 'avoid-a-clash) + x-var (intern n 'x 42)] + (is (= 42 (var-get x-var)))) - (let [x-var (intern 'avoid-a-clash 'x)] - (is (= 42 (var-get x-var)))) + (let [x-var (intern 'avoid-a-clash 'x)] + (is (= 42 (var-get x-var)))) - ;; Trying to intern to an unknown namespace should throw - (is (thrown? Exception (intern 'unknown-namespace 'x))) - (is (thrown? Exception (intern 'unknonw-namespace 'x 42)))) + ;; Trying to intern to an unknown namespace should throw + (is (thrown? Exception (intern 'unknown-namespace 'x))) + (is (thrown? Exception (intern 'unknonw-namespace 'x 42))))) diff --git a/test/clojure/core_test/keyword.cljc b/test/clojure/core_test/keyword.cljc index 3183742a..2da917bf 100644 --- a/test/clojure/core_test/keyword.cljc +++ b/test/clojure/core_test/keyword.cljc @@ -1,86 +1,88 @@ (ns clojure.core-test.keyword - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-keyword - ;; "Symbols begin with a non-numeric character and can contain - ;; alphanumeric characters and *, +, !, -, _, ', ?, <, > and = - ;; (other characters may be allowed eventually)." - ;; - ;; "Keywords are like symbols, except: * They can and must begin with a colon, e.g. :fred." - ;; - ;; (see http://clojure.org/reader for details) - ;; - ;; From https://clojuredocs.org/clojure.core/keyword - ;; keyword does not validate input strings for ns and name, and may - ;; return improper keywords with undefined behavior for non-conformant - ;; ns and name. +(p/when-var-exists clojure.core/keyword + (deftest test-keyword + ;; "Symbols begin with a non-numeric character and can contain + ;; alphanumeric characters and *, +, !, -, _, ', ?, <, > and = + ;; (other characters may be allowed eventually)." + ;; + ;; "Keywords are like symbols, except: * They can and must begin with a colon, e.g. :fred." + ;; + ;; (see http://clojure.org/reader for details) + ;; + ;; From https://clojuredocs.org/clojure.core/keyword + ;; keyword does not validate input strings for ns and name, and may + ;; return improper keywords with undefined behavior for non-conformant + ;; ns and name. - (are [expected name] (= expected (keyword name)) - :abc "abc" - :abc 'abc - :abc :abc - :* "*" - :* '* - :* :* - :+ "+" - :+ '+ - :+ :+ - :! "!" - :! '! - :! :! - :- "-" - :- '- - :- :- - :_ "_" - :_ '_ - :_ :_ - :? "?" - :? '? - :? :? - :< "<" - :< '< - :< :< - :> ">" - :> '> - :> :> - := "=" - := '= - := := - :abc*+!-_'?<>= "abc*+!-_'?<>=") + (are [expected name] (= expected (keyword name)) + :abc "abc" + :abc 'abc + :abc :abc + :* "*" + :* '* + :* :* + :+ "+" + :+ '+ + :+ :+ + :! "!" + :! '! + :! :! + :- "-" + :- '- + :- :- + :_ "_" + :_ '_ + :_ :_ + :? "?" + :? '? + :? :? + :< "<" + :< '< + :< :< + :> ">" + :> '> + :> :> + := "=" + := '= + := := + :abc*+!-_'?<>= "abc*+!-_'?<>=") - (are [expected ns name] (= expected (keyword ns name)) - :abc/abc "abc" "abc" - :abc.def/abc "abc.def" "abc" + (are [expected ns name] (= expected (keyword ns name)) + :abc/abc "abc" "abc" + :abc.def/abc "abc.def" "abc" - :*/abc "*" "abc" - :+/abc "+" "abc" - :!/abc "!" "abc" - :-/abc "-" "abc" - :_/abc "_" "abc" - :?/abc "?" "abc" - :/abc ">" "abc" - :=/abc "=" "abc" + :*/abc "*" "abc" + :+/abc "+" "abc" + :!/abc "!" "abc" + :-/abc "-" "abc" + :_/abc "_" "abc" + :?/abc "?" "abc" + :/abc ">" "abc" + :=/abc "=" "abc" - :abc.def/* "abc.def" "*" - :abc.def/+ "abc.def" "+" - :abc.def/! "abc.def" "!" - :abc.def/- "abc.def" "-" - :abc.def/_ "abc.def" "_" - :abc.def/? "abc.def" "?" - :abc.def/< "abc.def" "<" - :abc.def/> "abc.def" ">" - :abc.def/= "abc.def" "=" + :abc.def/* "abc.def" "*" + :abc.def/+ "abc.def" "+" + :abc.def/! "abc.def" "!" + :abc.def/- "abc.def" "-" + :abc.def/_ "abc.def" "_" + :abc.def/? "abc.def" "?" + :abc.def/< "abc.def" "<" + :abc.def/> "abc.def" ">" + :abc.def/= "abc.def" "=" - :abc*+!-_'?<>=/abc*+!-_'?<>= "abc*+!-_'?<>=" "abc*+!-_'?<>=") + :abc*+!-_'?<>=/abc*+!-_'?<>= "abc*+!-_'?<>=" "abc*+!-_'?<>=") - (is (nil? (keyword nil))) ; (keyword nil) => nil, surprisingly - (is (= :abc (keyword nil "abc"))) ; But if ns is nil, it just ignores it. - (is (thrown? Exception (keyword "abc" nil))) ; But if name is nil, then we throw. + (is (nil? (keyword nil))) ; (keyword nil) => nil, surprisingly + (is (= :abc (keyword nil "abc"))) ; But if ns is nil, it just ignores it. + (is (thrown? Exception (keyword "abc" nil))) ; But if name is nil, then we throw. - ;; Two arg version requires namespace and symbol to be a string, not - ;; a symbol or keyword like the one arg version. - (is (thrown? Exception (keyword 'abc "abc"))) - (is (thrown? Exception (keyword "abc" 'abc))) - (is (thrown? Exception (keyword :abc "abc"))) - (is (thrown? Exception (keyword "abc" :abc)))) + ;; Two arg version requires namespace and symbol to be a string, not + ;; a symbol or keyword like the one arg version. + (is (thrown? Exception (keyword 'abc "abc"))) + (is (thrown? Exception (keyword "abc" 'abc))) + (is (thrown? Exception (keyword :abc "abc"))) + (is (thrown? Exception (keyword "abc" :abc))))) diff --git a/test/clojure/core_test/keyword_questionmark.cljc b/test/clojure/core_test/keyword_questionmark.cljc index 509e8cfd..4c4a3dd9 100644 --- a/test/clojure/core_test/keyword_questionmark.cljc +++ b/test/clojure/core_test/keyword_questionmark.cljc @@ -1,18 +1,20 @@ (ns clojure.core-test.keyword-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-keyword? - (are [expected x] (= expected (keyword? x)) - true :a-keyword - false 'a-symbol - true :a-ns/a-keyword - false 'a-ns/a-keyword - false "a string" - false 0 - false 0N - false 0.0 - false 1/2 - false 0.0M - false false - false true - false nil)) +(p/when-var-exists clojure.core/keyword? + (deftest test-keyword? + (are [expected x] (= expected (keyword? x)) + true :a-keyword + false 'a-symbol + true :a-ns/a-keyword + false 'a-ns/a-keyword + false "a string" + false 0 + false 0N + false 0.0 + false 1/2 + false 0.0M + false false + false true + false nil))) diff --git a/test/clojure/core_test/long.cljc b/test/clojure/core_test/long.cljc index 342ce999..6bc74732 100644 --- a/test/clojure/core_test/long.cljc +++ b/test/clojure/core_test/long.cljc @@ -1,44 +1,45 @@ (ns clojure.core-test.long - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-long - ;; There is no platform independent predicate to test specifically - ;; for a long. In ClojureJVM, it's an instance of `java.lang.Long`, - ;; but there is no predicate for it. Here, we just test whether it's - ;; a fixed-length integer of some sort. - (is (int? (int 0))) - #?@(:cljs nil - :default - [(is (instance? java.lang.Long (long 0)))]) +(p/when-var-exists clojure.core/long + (deftest test-long + ;; There is no platform independent predicate to test specifically + ;; for a long. In ClojureJVM, it's an instance of `java.lang.Long`, + ;; but there is no predicate for it. Here, we just test whether it's + ;; a fixed-length integer of some sort. + (is (int? (int 0))) + #?@(:cljs nil + :default + [(is (instance? java.lang.Long (long 0)))]) - ;; Check conversions and rounding from other numeric types - (are [expected x] (= expected (long x)) - -9223372036854775808 -9223372036854775808 - 0 0 - 9223372036854775807 9223372036854775807 - 1 1N - 0 0N - -1 -1N - 1 1.0M - 0 0.0M - -1 -1.0M - 1 1.1 - -1 -1.1 - 1 1.9 - 1 3/2 - -1 -3/2 - 0 1/10 - 0 -1/10 - 1 1.1M - -1 -1.1M) + ;; Check conversions and rounding from other numeric types + (are [expected x] (= expected (long x)) + -9223372036854775808 -9223372036854775808 + 0 0 + 9223372036854775807 9223372036854775807 + 1 1N + 0 0N + -1 -1N + 1 1.0M + 0 0.0M + -1 -1.0M + 1 1.1 + -1 -1.1 + 1 1.9 + 1 3/2 + -1 -3/2 + 0 1/10 + 0 -1/10 + 1 1.1M + -1 -1.1M) - ;; `long` throws outside the range of 9223372036854775807 ... -9223372036854775808 - (is (thrown? IllegalArgumentException (long -9223372036854775809))) - (is (thrown? IllegalArgumentException (long 9223372036854775808))) - - ;; Check handling of other types - (is (thrown? ClassCastException (long "0"))) - (is (thrown? ClassCastException (long :0))) - (is (thrown? ClassCastException (long [0]))) - (is (thrown? Exception (long nil)))) + ;; `long` throws outside the range of 9223372036854775807 ... -9223372036854775808 + (is (thrown? IllegalArgumentException (long -9223372036854775809))) + (is (thrown? IllegalArgumentException (long 9223372036854775808))) + ;; Check handling of other types + (is (thrown? ClassCastException (long "0"))) + (is (thrown? ClassCastException (long :0))) + (is (thrown? ClassCastException (long [0]))) + (is (thrown? Exception (long nil))))) diff --git a/test/clojure/core_test/max.cljc b/test/clojure/core_test/max.cljc index 4fabeb76..d8ab38d1 100644 --- a/test/clojure/core_test/max.cljc +++ b/test/clojure/core_test/max.cljc @@ -1,37 +1,39 @@ (ns clojure.core-test.max - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-max - (are [expected x y] (= expected (max x y) (max y x)) - 2 1 2 - 2N 1N 2N - 2 1N 2 - 2N 1 2N - 2.0 1.0 2.0 - 2.0 1 2.0 - 2 1.0 2 - 1 1/2 1 - ##Inf 1 ##Inf - 1 1 ##-Inf - ##Inf ##-Inf ##Inf) +(p/when-var-exists clojure.core/max + (deftest test-max + (are [expected x y] (= expected (max x y) (max y x)) + 2 1 2 + 2N 1N 2N + 2 1N 2 + 2N 1 2N + 2.0 1.0 2.0 + 2.0 1 2.0 + 2 1.0 2 + 1 1/2 1 + ##Inf 1 ##Inf + 1 1 ##-Inf + ##Inf ##-Inf ##Inf) - ;; Single arg just returns argument - (is (= 1 (max 1))) - (is (= 2 (max 2))) - (is (= "x" (max "x"))) ; doesn't check single arg for Number + ;; Single arg just returns argument + (is (= 1 (max 1))) + (is (= 2 (max 2))) + (is (= "x" (max "x"))) ; doesn't check single arg for Number - ;; Multi-arg - (is (= 5 (max 1 2 3 4 5))) - (is (= 5 (max 5 4 3 2 1))) - (is (= 5 (max 1 2 3 4 5 ##-Inf))) - (is (= ##Inf (max 1 2 3 4 5 ##Inf))) + ;; Multi-arg + (is (= 5 (max 1 2 3 4 5))) + (is (= 5 (max 5 4 3 2 1))) + (is (= 5 (max 1 2 3 4 5 ##-Inf))) + (is (= ##Inf (max 1 2 3 4 5 ##Inf))) - (is (NaN? (max ##NaN 1))) - (is (NaN? (max 1 ##NaN))) - (is (NaN? (max 1 2 3 4 ##NaN))) - (is (NaN? (max ##-Inf ##NaN ##Inf))) - (is (NaN? (max ##NaN))) + (is (NaN? (max ##NaN 1))) + (is (NaN? (max 1 ##NaN))) + (is (NaN? (max 1 2 3 4 ##NaN))) + (is (NaN? (max ##-Inf ##NaN ##Inf))) + (is (NaN? (max ##NaN))) - (is (thrown? Exception (max "x" "y"))) - (is (thrown? Exception (max nil 1))) - (is (thrown? Exception (max 1 nil)))) + (is (thrown? Exception (max "x" "y"))) + (is (thrown? Exception (max nil 1))) + (is (thrown? Exception (max 1 nil))))) diff --git a/test/clojure/core_test/min.cljc b/test/clojure/core_test/min.cljc index 1352e628..d3977d8c 100644 --- a/test/clojure/core_test/min.cljc +++ b/test/clojure/core_test/min.cljc @@ -1,37 +1,39 @@ (ns clojure.core-test.min - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-min - (are [expected x y] (= expected (min x y) (min y x)) - 1 1 2 - 1N 1N 2N - 1N 1N 2 - 1 1 2N - 1.0 1.0 2.0 - 1 1 2.0 - 1.0 1.0 2 - 1/2 1/2 1 - 1 1 ##Inf - ##-Inf 1 ##-Inf - ##-Inf ##-Inf ##Inf) +(p/when-var-exists clojure.core/min + (deftest test-min + (are [expected x y] (= expected (min x y) (min y x)) + 1 1 2 + 1N 1N 2N + 1N 1N 2 + 1 1 2N + 1.0 1.0 2.0 + 1 1 2.0 + 1.0 1.0 2 + 1/2 1/2 1 + 1 1 ##Inf + ##-Inf 1 ##-Inf + ##-Inf ##-Inf ##Inf) -;; Single arg just returns argument - (is (= 1 (min 1))) - (is (= 2 (min 2))) - (is (= "x" (min "x"))) ; doesn't check single arg for Number + ;; Single arg just returns argument + (is (= 1 (min 1))) + (is (= 2 (min 2))) + (is (= "x" (min "x"))) ; doesn't check single arg for Number - ;; Multi-arg - (is (= 1 (min 1 2 3 4 5))) - (is (= 1 (min 5 4 3 2 1))) - (is (= ##-Inf (min 1 2 3 4 5 ##-Inf))) - (is (= 1 (min 1 2 3 4 5 ##Inf))) + ;; Multi-arg + (is (= 1 (min 1 2 3 4 5))) + (is (= 1 (min 5 4 3 2 1))) + (is (= ##-Inf (min 1 2 3 4 5 ##-Inf))) + (is (= 1 (min 1 2 3 4 5 ##Inf))) - (is (NaN? (min ##NaN 1))) - (is (NaN? (min 1 ##NaN))) - (is (NaN? (min 1 2 3 4 ##NaN))) - (is (NaN? (min ##-Inf ##NaN ##Inf))) - (is (NaN? (min ##NaN))) + (is (NaN? (min ##NaN 1))) + (is (NaN? (min 1 ##NaN))) + (is (NaN? (min 1 2 3 4 ##NaN))) + (is (NaN? (min ##-Inf ##NaN ##Inf))) + (is (NaN? (min ##NaN))) - (is (thrown? Exception (min "x" "y"))) - (is (thrown? Exception (min nil 1))) - (is (thrown? Exception (min 1 nil)))) + (is (thrown? Exception (min "x" "y"))) + (is (thrown? Exception (min nil 1))) + (is (thrown? Exception (min 1 nil))))) diff --git a/test/clojure/core_test/minus.cljc b/test/clojure/core_test/minus.cljc index 3af057bd..fcb6f57d 100644 --- a/test/clojure/core_test/minus.cljc +++ b/test/clojure/core_test/minus.cljc @@ -1,193 +1,196 @@ (ns clojure.core-test.minus (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) - -(deftest common - (are [expected x y] (= expected (- x y)) - ;; longs - 0 0 0 - 1 1 0 - -1 -1 0 - 0 1 1 - -1 0 1 - -2 -1 1 - 2 1 -1 - 1 0 -1 - 0 -1 -1 - 1 2 1 - 5 6 1 - 5 10 5 - -1 1 2 - - ;; doubles - 0.0 0.0 0.0 - 1.0 1.0 0.0 - -1.0 -1.0 0.0 - 0.0 1.0 1.0 - -1.0 0.0 1.0 - -2.0 -1.0 1.0 - 2.0 1.0 -1.0 - 1.0 0.0 -1.0 - 0.0 -1.0 -1.0 - 1.0 2.0 1.0 - 5.0 6.0 1.0 - 5.0 10.0 5.0 - -1.0 1.0 2.0 - - ;; BigInts - 0N 0N 0N - 1N 1N 0N - -1N -1N 0N - 0N 1N 1N - -1N 0N 1N - -2N -1N 1N - 2N 1N -1N - 1N 0N -1N - 0N -1N -1N - 1N 2N 1N - 5N 6N 1N - 5N 10N 5N - -1N 1N 2N - - ;; BigDecimals - 0.0M 0.0M 0.0M - 1.0M 1.0M 0.0M - -1.0M -1.0M 0.0M - 0.0M 1.0M 1.0M - -1.0M 0.0M 1.0M - -2.0M -1.0M 1.0M - 2.0M 1.0M -1.0M - 1.0M 0.0M -1.0M - 0.0M -1.0M -1.0M - 1.0M 2.0M 1.0M - 5.0M 6.0M 1.0M - 5.0M 10.0M 5.0M - -1.0M 1.0M 2.0M) - - ;; Zero arg - (is (thrown? Exception (-))) - - ;; Single arg - (is (= -3 (- 3))) - (is (= 3 (- -3))) - - ;; Multi-arg - (is (= -45 (- 0 1 2 3 4 5 6 7 8 9))) - - (is (thrown? Exception (- nil 1))) - (is (thrown? Exception (- 1 nil))) - (is (thrown? Exception (- nil 1N))) - (is (thrown? Exception (- 1N nil))) - (is (thrown? Exception (- nil 1.0))) - (is (thrown? Exception (- 1.0 nil))) - (is (thrown? Exception (- nil 1.0M))) - (is (thrown? Exception (- 1.0M nil))) - - #?@(:cljs nil - :default - [(is (thrown? Exception (- r/min-int 1))) - (is (thrown? Exception (- r/max-int -1)))])) - - -(deftest rationals - (are [expected x y] (= expected (- x y)) - 1/2 1 1/2 - 1/3 1 2/3 - 1/4 1 3/4 - 1/5 1 4/5 - 1/6 1 5/6 - 1/7 1 6/7 - 1/8 1 7/8 - 1/9 1 8/9 - - 1 1/2 -1/2 - 1 1/3 -2/3 - 1 1/4 -3/4 - 1 1/5 -4/5 - 1 1/6 -5/6 - 1 1/7 -6/7 - 1 1/8 -7/8 - 1 1/9 -8/9 - - 1 3/2 1/2 - 1 5/3 2/3 - 1 7/4 3/4 - 1 9/5 4/5 - 1 11/6 5/6 - 1 13/7 6/7 - 1 15/8 7/8 - 1 17/9 8/9 - - 3/2 2 1/2 - 4/3 2 2/3 - - ;; Be careful here because floating point rounding can bite us. - ;; This case is pretty safe. - 1.0 1.5 1/2) - - ;; Single arg - (is (= -1/2 (- 1/2))) - (is (= 1/2 (- -1/2))) - - ;; Multi arg - (is (= -2089/2520 (- 1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9))) - - (is (thrown? Exception (- nil 1/2))) - (is (thrown? Exception (- 1/2 nil))) - - #?@(:cljs nil - :default - [(is (- r/max-int -1/2)) ; test that these don't throw - (is (- r/min-int 1/2)) - (is (= (- r/max-double) (- (- r/max-double) 1/2))) ; should silently round - (is (= r/max-double (- r/max-double -1/2))) - (is (= -0.5 (- r/min-double 1/2))) - (is (= 0.5 (- r/min-double -1/2))) - (is (instance? clojure.lang.Ratio (- 0 1/3))) - (is (instance? clojure.lang.Ratio (- 0N 1/3))) - (is (instance? clojure.lang.Ratio (- 1 1/3))) - (is (instance? clojure.lang.Ratio (- 1N 1/3))) - ;; Note that we use `double?` here because JVM Clojure uses - ;; java.lang.Double instead of clojure.lang.Double and we'd - ;; like to keep this test as generic as possible. - (is (double? (- 0.0 1/3))) - (is (double? (- 1.0 1/3)))])) - -(deftest inf-nan - (are [expected x y] (= expected (- x y)) - ##Inf 1 ##-Inf - ##Inf 1N ##-Inf - ##Inf 1.0 ##-Inf - ##Inf 1/2 ##-Inf - ##-Inf 1 ##Inf - ##-Inf 1N ##Inf - ##-Inf 1.0 ##Inf - ##-Inf 1/2 ##Inf - - ##-Inf ##-Inf 1 - ##-Inf ##-Inf 1N - ##-Inf ##-Inf 1.0 - ##-Inf ##-Inf 1/2 - ##Inf ##Inf 1 - ##Inf ##Inf 1N - ##Inf ##Inf 1.0 - ##Inf ##Inf 1/2) - - (are [x y] (and (NaN? (- x y)) - (NaN? (- y x))) - ##-Inf ##-Inf - 1 ##NaN - 1N ##NaN - 1.0 ##NaN - 1/2 ##NaN - ##Inf ##NaN - ##-Inf ##NaN - ##NaN ##NaN) - - ;; Single arg - (is (= ##-Inf (- ##Inf))) - (is (= ##Inf (- ##-Inf))) - (is (NaN? (- ##NaN))) - - (is (thrown? Exception (- ##NaN nil))) - (is (thrown? Exception (- ##Inf nil)))) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) + +(p/when-var-exists clojure.core/- + (deftest test-- + (testing "common" + (are [expected x y] (= expected (- x y)) + ;; longs + 0 0 0 + 1 1 0 + -1 -1 0 + 0 1 1 + -1 0 1 + -2 -1 1 + 2 1 -1 + 1 0 -1 + 0 -1 -1 + 1 2 1 + 5 6 1 + 5 10 5 + -1 1 2 + + ;; doubles + 0.0 0.0 0.0 + 1.0 1.0 0.0 + -1.0 -1.0 0.0 + 0.0 1.0 1.0 + -1.0 0.0 1.0 + -2.0 -1.0 1.0 + 2.0 1.0 -1.0 + 1.0 0.0 -1.0 + 0.0 -1.0 -1.0 + 1.0 2.0 1.0 + 5.0 6.0 1.0 + 5.0 10.0 5.0 + -1.0 1.0 2.0 + + ;; BigInts + 0N 0N 0N + 1N 1N 0N + -1N -1N 0N + 0N 1N 1N + -1N 0N 1N + -2N -1N 1N + 2N 1N -1N + 1N 0N -1N + 0N -1N -1N + 1N 2N 1N + 5N 6N 1N + 5N 10N 5N + -1N 1N 2N + + ;; BigDecimals + 0.0M 0.0M 0.0M + 1.0M 1.0M 0.0M + -1.0M -1.0M 0.0M + 0.0M 1.0M 1.0M + -1.0M 0.0M 1.0M + -2.0M -1.0M 1.0M + 2.0M 1.0M -1.0M + 1.0M 0.0M -1.0M + 0.0M -1.0M -1.0M + 1.0M 2.0M 1.0M + 5.0M 6.0M 1.0M + 5.0M 10.0M 5.0M + -1.0M 1.0M 2.0M) + + ;; Zero arg + (is (thrown? Exception (-))) + + ;; Single arg + (is (= -3 (- 3))) + (is (= 3 (- -3))) + + ;; Multi-arg + (is (= -45 (- 0 1 2 3 4 5 6 7 8 9))) + + (is (thrown? Exception (- nil 1))) + (is (thrown? Exception (- 1 nil))) + (is (thrown? Exception (- nil 1N))) + (is (thrown? Exception (- 1N nil))) + (is (thrown? Exception (- nil 1.0))) + (is (thrown? Exception (- 1.0 nil))) + (is (thrown? Exception (- nil 1.0M))) + (is (thrown? Exception (- 1.0M nil))) + + #?@(:cljs nil + :default + [(is (thrown? Exception (- r/min-int 1))) + (is (thrown? Exception (- r/max-int -1)))])) + + + (testing "rationals" + (are [expected x y] (= expected (- x y)) + 1/2 1 1/2 + 1/3 1 2/3 + 1/4 1 3/4 + 1/5 1 4/5 + 1/6 1 5/6 + 1/7 1 6/7 + 1/8 1 7/8 + 1/9 1 8/9 + + 1 1/2 -1/2 + 1 1/3 -2/3 + 1 1/4 -3/4 + 1 1/5 -4/5 + 1 1/6 -5/6 + 1 1/7 -6/7 + 1 1/8 -7/8 + 1 1/9 -8/9 + + 1 3/2 1/2 + 1 5/3 2/3 + 1 7/4 3/4 + 1 9/5 4/5 + 1 11/6 5/6 + 1 13/7 6/7 + 1 15/8 7/8 + 1 17/9 8/9 + + 3/2 2 1/2 + 4/3 2 2/3 + + ;; Be careful here because floating point rounding can bite us. + ;; This case is pretty safe. + 1.0 1.5 1/2) + + ;; Single arg + (is (= -1/2 (- 1/2))) + (is (= 1/2 (- -1/2))) + + ;; Multi arg + (is (= -2089/2520 (- 1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9))) + + (is (thrown? Exception (- nil 1/2))) + (is (thrown? Exception (- 1/2 nil))) + + #?@(:cljs nil + :default + [(is (- r/max-int -1/2)) ; test that these don't throw + (is (- r/min-int 1/2)) + (is (= (- r/max-double) (- (- r/max-double) 1/2))) ; should silently round + (is (= r/max-double (- r/max-double -1/2))) + (is (= -0.5 (- r/min-double 1/2))) + (is (= 0.5 (- r/min-double -1/2))) + (is (instance? clojure.lang.Ratio (- 0 1/3))) + (is (instance? clojure.lang.Ratio (- 0N 1/3))) + (is (instance? clojure.lang.Ratio (- 1 1/3))) + (is (instance? clojure.lang.Ratio (- 1N 1/3))) + ;; Note that we use `double?` here because JVM Clojure uses + ;; java.lang.Double instead of clojure.lang.Double and we'd + ;; like to keep this test as generic as possible. + (is (double? (- 0.0 1/3))) + (is (double? (- 1.0 1/3)))])) + + (testing "inf-nan" + (are [expected x y] (= expected (- x y)) + ##Inf 1 ##-Inf + ##Inf 1N ##-Inf + ##Inf 1.0 ##-Inf + ##Inf 1/2 ##-Inf + ##-Inf 1 ##Inf + ##-Inf 1N ##Inf + ##-Inf 1.0 ##Inf + ##-Inf 1/2 ##Inf + + ##-Inf ##-Inf 1 + ##-Inf ##-Inf 1N + ##-Inf ##-Inf 1.0 + ##-Inf ##-Inf 1/2 + ##Inf ##Inf 1 + ##Inf ##Inf 1N + ##Inf ##Inf 1.0 + ##Inf ##Inf 1/2) + + (are [x y] (and (NaN? (- x y)) + (NaN? (- y x))) + ##-Inf ##-Inf + 1 ##NaN + 1N ##NaN + 1.0 ##NaN + 1/2 ##NaN + ##Inf ##NaN + ##-Inf ##NaN + ##NaN ##NaN) + + ;; Single arg + (is (= ##-Inf (- ##Inf))) + (is (= ##Inf (- ##-Inf))) + (is (NaN? (- ##NaN))) + + (is (thrown? Exception (- ##NaN nil))) + (is (thrown? Exception (- ##Inf nil)))))) diff --git a/test/clojure/core_test/mod.cljc b/test/clojure/core_test/mod.cljc index f7ada9b7..19569573 100644 --- a/test/clojure/core_test/mod.cljc +++ b/test/clojure/core_test/mod.cljc @@ -1,85 +1,87 @@ (ns clojure.core-test.mod (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p] [clojure.core-test.portability :as p])) -(deftest test-mod - (are [type-pred expected x y] (let [r (mod x y)] - (and (type-pred r) - (= expected r))) - int? 1 10 3 - int? 2 -10 3 - int? -1 -10 -3 - int? -2 10 -3 +(p/when-var-exists clojure.core/mod + (deftest test-mod + (are [type-pred expected x y] (let [r (mod x y)] + (and (type-pred r) + (= expected r))) + int? 1 10 3 + int? 2 -10 3 + int? -1 -10 -3 + int? -2 10 -3 - p/big-int? 1N 10 3N - p/big-int? 2N -10 3N - p/big-int? -1N -10 -3N - p/big-int? -2N 10 -3N + p/big-int? 1N 10 3N + p/big-int? 2N -10 3N + p/big-int? -1N -10 -3N + p/big-int? -2N 10 -3N - p/big-int? 1N 10N 3 - p/big-int? 2N -10N 3 - p/big-int? -1N -10N -3 - p/big-int? -2N 10N -3 + p/big-int? 1N 10N 3 + p/big-int? 2N -10N 3 + p/big-int? -1N -10N -3 + p/big-int? -2N 10N -3 - p/big-int? 1N 10N 3N - p/big-int? 2N -10N 3N - p/big-int? -1N -10N -3N - p/big-int? -2N 10N -3N + p/big-int? 1N 10N 3N + p/big-int? 2N -10N 3N + p/big-int? -1N -10N -3N + p/big-int? -2N 10N -3N - double? 1.0 10 3.0 - double? 2.0 -10 3.0 - double? -1.0 -10 -3.0 - double? -2.0 10 -3.0 - double? 1.0 10.0 3 - double? 2.0 -10.0 3 - double? -1.0 -10.0 -3 - double? -2.0 10.0 -3 - double? 1.0 10.0 3.0 - double? 2.0 -10.0 3.0 - double? -1.0 -10.0 -3.0 - double? -2.0 10.0 -3.0 + double? 1.0 10 3.0 + double? 2.0 -10 3.0 + double? -1.0 -10 -3.0 + double? -2.0 10 -3.0 + double? 1.0 10.0 3 + double? 2.0 -10.0 3 + double? -1.0 -10.0 -3 + double? -2.0 10.0 -3 + double? 1.0 10.0 3.0 + double? 2.0 -10.0 3.0 + double? -1.0 -10.0 -3.0 + double? -2.0 10.0 -3.0 - decimal? 1.0M 10 3.0M - decimal? 2.0M -10 3.0M - decimal? -1.0M -10 -3.0M - decimal? -2.0M 10 -3.0M - decimal? 1.0M 10.0M 3 - decimal? 2.0M -10.0M 3 - decimal? -1.0M -10.0M -3 - decimal? -2.0M 10.0M -3 - decimal? 1.0M 10.0M 3.0M - decimal? 2.0M -10.0M 3.0M - decimal? -1.0M -10.0M -3.0M - decimal? -2.0M 10.0M -3.0M + decimal? 1.0M 10 3.0M + decimal? 2.0M -10 3.0M + decimal? -1.0M -10 -3.0M + decimal? -2.0M 10 -3.0M + decimal? 1.0M 10.0M 3 + decimal? 2.0M -10.0M 3 + decimal? -1.0M -10.0M -3 + decimal? -2.0M 10.0M -3 + decimal? 1.0M 10.0M 3.0M + decimal? 2.0M -10.0M 3.0M + decimal? -1.0M -10.0M -3.0M + decimal? -2.0M 10.0M -3.0M - ;; Unexpectedly downconverts result to double, rather than BigDecimal - double? 1.0 10.0M 3.0 - double? 2.0 -10.0M 3.0 - double? -1.0 -10.0M -3.0 - double? -2.0 10.0M -3.0 - double? 1.0 10.0 3.0M - double? 2.0 -10.0 3.0M - double? -1.0 -10.0 -3.0M - double? -2.0 10.0 -3.0M + ;; Unexpectedly downconverts result to double, rather than BigDecimal + double? 1.0 10.0M 3.0 + double? 2.0 -10.0M 3.0 + double? -1.0 -10.0M -3.0 + double? -2.0 10.0M -3.0 + double? 1.0 10.0 3.0M + double? 2.0 -10.0 3.0M + double? -1.0 -10.0 -3.0M + double? -2.0 10.0 -3.0M - p/big-int? 0N 3 1/2 - ratio? 1/3 3 4/3 - ratio? 7/2 37/2 15 - p/big-int? 0N 3 -1/2 - p/big-int? -1N 3 -4/3 - ratio? -23/2 37/2 -15 - p/big-int? 0N -3 1/2 - p/big-int? 1N -3 4/3 - ratio? 23/2 -37/2 15 - p/big-int? 0N -3 -1/2 - ratio? -1/3 -3 -4/3 - ratio? -7/2 -37/2 -15) + p/big-int? 0N 3 1/2 + ratio? 1/3 3 4/3 + ratio? 7/2 37/2 15 + p/big-int? 0N 3 -1/2 + p/big-int? -1N 3 -4/3 + ratio? -23/2 37/2 -15 + p/big-int? 0N -3 1/2 + p/big-int? 1N -3 4/3 + ratio? 23/2 -37/2 15 + p/big-int? 0N -3 -1/2 + ratio? -1/3 -3 -4/3 + ratio? -7/2 -37/2 -15) - (is (thrown? Exception (mod 10 0))) - (is (thrown? Exception (mod ##Inf 1))) ; surprising since (/ ##Inf 1) = ##Inf - (is (NaN? (mod 1 ##Inf))) - (is (thrown? Exception (mod ##-Inf 1))) ; surprising since (/ ##-Inf 1) = ##-Inf - (is (NaN? (mod 1 ##-Inf))) - (is (thrown? Exception (mod ##NaN 1))) - (is (thrown? Exception (mod 1 ##NaN))) - (is (thrown? Exception (mod ##NaN 1)))) + (is (thrown? Exception (mod 10 0))) + (is (thrown? Exception (mod ##Inf 1))) ; surprising since (/ ##Inf 1) = ##Inf + (is (NaN? (mod 1 ##Inf))) + (is (thrown? Exception (mod ##-Inf 1))) ; surprising since (/ ##-Inf 1) = ##-Inf + (is (NaN? (mod 1 ##-Inf))) + (is (thrown? Exception (mod ##NaN 1))) + (is (thrown? Exception (mod 1 ##NaN))) + (is (thrown? Exception (mod ##NaN 1))))) diff --git a/test/clojure/core_test/name.cljc b/test/clojure/core_test/name.cljc index 379c81b6..52103cfb 100644 --- a/test/clojure/core_test/name.cljc +++ b/test/clojure/core_test/name.cljc @@ -1,14 +1,16 @@ (ns clojure.core-test.name - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-name - (are [expected x] (= expected (name x)) - "abc" "abc" - "abc" :abc - "abc" 'abc - "def" :abc/def - "def" 'abc/def - "abc*+!-_'?<>=" :abc/abc*+!-_'?<>= - "abc*+!-_'?<>=" 'abc/abc*+!-_'?<>=) +(p/when-var-exists clojure.core/name + (deftest test-name + (are [expected x] (= expected (name x)) + "abc" "abc" + "abc" :abc + "abc" 'abc + "def" :abc/def + "def" 'abc/def + "abc*+!-_'?<>=" :abc/abc*+!-_'?<>= + "abc*+!-_'?<>=" 'abc/abc*+!-_'?<>=) - (is (thrown? Exception (name nil)))) + (is (thrown? Exception (name nil))))) diff --git a/test/clojure/core_test/namespace.cljc b/test/clojure/core_test/namespace.cljc index a434da61..ef37eec6 100644 --- a/test/clojure/core_test/namespace.cljc +++ b/test/clojure/core_test/namespace.cljc @@ -1,12 +1,14 @@ (ns clojure.core-test.namespace - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-namespace - (are [expected sym-or-kw] (= expected (namespace sym-or-kw)) - "clojure.core" 'clojure.core/+ - "abc" :abc/def - "abc" 'abc/def - nil :abc - nil 'abc) +(p/when-var-exists clojure.core/namespace + (deftest test-namespace + (are [expected sym-or-kw] (= expected (namespace sym-or-kw)) + "clojure.core" 'clojure.core/+ + "abc" :abc/def + "abc" 'abc/def + nil :abc + nil 'abc) - (is (thrown? Exception (namespace nil)))) + (is (thrown? Exception (namespace nil))))) diff --git a/test/clojure/core_test/nan.cljc b/test/clojure/core_test/nan.cljc deleted file mode 100644 index 0da0861e..00000000 --- a/test/clojure/core_test/nan.cljc +++ /dev/null @@ -1,21 +0,0 @@ -(ns clojure.core-test.nan - (:require [clojure.test :as t :refer [deftest testing is are]])) - -(deftest common - (is (thrown? Exception (NaN? nil))) - (is (thrown? Exception (NaN? "##NaN"))) - (is (double? ##NaN)) - ;; NaN is not equal to anything, even itself. - ;; See: https://clojure.org/guides/equality - ;; Note that we use `(not (= ...))` rather than `(not= ...)` because - ;; of a bug in clojure.core. - (is (not (= ##NaN ##NaN))) - (are [in ex] (= ex (NaN? in)) - 0 false - 1.0 false - -1.0 false - (double 1.0) false - (double -1.0) false - ##Inf false - ##-Inf false - ##NaN true)) diff --git a/test/clojure/core_test/nan_questionmark.cljc b/test/clojure/core_test/nan_questionmark.cljc new file mode 100644 index 00000000..ea3730ab --- /dev/null +++ b/test/clojure/core_test/nan_questionmark.cljc @@ -0,0 +1,23 @@ +(ns clojure.core-test.nan-questionmark + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) + +(p/when-var-exists clojure.core/NaN? + (deftest test-NaN? + (is (thrown? Exception (NaN? nil))) + (is (thrown? Exception (NaN? "##NaN"))) + (is (double? ##NaN)) + ;; NaN is not equal to anything, even itself. + ;; See: https://clojure.org/guides/equality + ;; Note that we use `(not (= ...))` rather than `(not= ...)` because + ;; of a bug in clojure.core. + (is (not (= ##NaN ##NaN))) + (are [in ex] (= ex (NaN? in)) + 0 false + 1.0 false + -1.0 false + (double 1.0) false + (double -1.0) false + ##Inf false + ##-Inf false + ##NaN true))) diff --git a/test/clojure/core_test/neg_int_questionmark.cljc b/test/clojure/core_test/neg_int_questionmark.cljc index b47dc548..6dad5f8a 100644 --- a/test/clojure/core_test/neg_int_questionmark.cljc +++ b/test/clojure/core_test/neg_int_questionmark.cljc @@ -1,46 +1,48 @@ (ns clojure.core-test.neg-int-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-neg-int? - (are [expected x] (= expected (neg-int? x)) - false 0 - false 1 - true -1 - false r/max-int - true r/min-int - false 0.0 - false 1.0 - false -1.0 - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - false 0N - false 1N - false -1N - false 0/2 - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/neg-int? + (deftest test-neg-int? + (are [expected x] (= expected (neg-int? x)) + false 0 + false 1 + true -1 + false r/max-int + true r/min-int + false 0.0 + false 1.0 + false -1.0 + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + false 1N + false -1N + false 0/2 + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/neg_questionmark.cljc b/test/clojure/core_test/neg_questionmark.cljc index 4e0e63a7..1981d8c2 100644 --- a/test/clojure/core_test/neg_questionmark.cljc +++ b/test/clojure/core_test/neg_questionmark.cljc @@ -1,32 +1,34 @@ (ns clojure.core-test.neg-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-neg? - (are [expected x] (= expected (neg? x)) - false 0 - false 1 - true -1 - true r/min-int - false r/max-int - false 0.0 - false 1.0 - true -1.0 - false r/min-double - false r/max-double - false ##Inf - true ##-Inf - false ##NaN - false 0N - false 1N - true -1N - false 0/2 - false 1/2 - true -1/2 - false 0.0M - false 1.0M - true -1.0M) +(p/when-var-exists clojure.core/neg? + (deftest test-neg? + (are [expected x] (= expected (neg? x)) + false 0 + false 1 + true -1 + true r/min-int + false r/max-int + false 0.0 + false 1.0 + true -1.0 + false r/min-double + false r/max-double + false ##Inf + true ##-Inf + false ##NaN + false 0N + false 1N + true -1N + false 0/2 + false 1/2 + true -1/2 + false 0.0M + false 1.0M + true -1.0M) - (is (thrown? Exception (neg? nil))) - (is (thrown? Exception (neg? false))) - (is (thrown? Exception (neg? true)))) + (is (thrown? Exception (neg? nil))) + (is (thrown? Exception (neg? false))) + (is (thrown? Exception (neg? true))))) diff --git a/test/clojure/core_test/nil_questionmark.cljc b/test/clojure/core_test/nil_questionmark.cljc index b840c785..33902306 100644 --- a/test/clojure/core_test/nil_questionmark.cljc +++ b/test/clojure/core_test/nil_questionmark.cljc @@ -1,20 +1,23 @@ (ns clojure.core-test.nil-questionmark - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - (t/are [in ex] (= (nil? in) ex) - nil true - 0 false - false false - "" false - "nil" false - :nil false - ##Inf false - ##NaN false - 0.0 false - {} false - '() false - [] false)) +(p/when-var-exists clojure.core/nil? + (deftest test-nil? + (testing "common" + (are [in ex] (= (nil? in) ex) + nil true + 0 false + false false + "" false + "nil" false + :nil false + ##Inf false + ##NaN false + 0.0 false + {} false + '() false + [] false)) -(t/deftest infinite-sequence - (t/is (= false (nil? (range))))) + (testing "infinite-sequence" + (is (= false (nil? (range))))))) diff --git a/test/clojure/core_test/not.cljc b/test/clojure/core_test/not.cljc index 927fd2e5..4386bc55 100644 --- a/test/clojure/core_test/not.cljc +++ b/test/clojure/core_test/not.cljc @@ -1,15 +1,18 @@ (ns clojure.core-test.not (:require - [clojure.test :as t])) + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - (t/are [given expected] (= expected (not given)) - nil true - true false - false true - #?(:clj (Object.) - :cljs #js {} - :default :anything) false)) +(p/when-var-exists clojure.core/not + (deftest test-not + (testing "common" + (are [given expected] (= expected (not given)) + nil true + true false + false true + #?(:clj (Object.) + :cljs #js {} + :default :anything) false)) -(t/deftest infinite-sequence - (t/is (= false (not (range))))) + (testing "infinite-sequence" + (is (= false (not (range))))))) diff --git a/test/clojure/core_test/num.cljc b/test/clojure/core_test/num.cljc index 25ceba53..3fe405af 100644 --- a/test/clojure/core_test/num.cljc +++ b/test/clojure/core_test/num.cljc @@ -1,14 +1,16 @@ (ns clojure.core-test.num - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-num - #?@(:cljs nil - :default - ;; The compiler should pass `x` as a primitive to `num`. - [(let [x 1.0] - (is (instance? java.lang.Double (num x)))) - (let [x 1] - (is (instance? java.lang.Long (num x)))) - ;; `BigInt` and `BigDecimal` are always boxed and `num` just returns them as-is. - (is (instance? clojure.lang.BigInt (num 1N))) - (is (instance? java.math.BigDecimal (num 1.0M)))])) +(p/when-var-exists clojure.core/num + (deftest test-num + #?@(:cljs nil + :default + ;; The compiler should pass `x` as a primitive to `num`. + [(let [x 1.0] + (is (instance? java.lang.Double (num x)))) + (let [x 1] + (is (instance? java.lang.Long (num x)))) + ;; `BigInt` and `BigDecimal` are always boxed and `num` just returns them as-is. + (is (instance? clojure.lang.BigInt (num 1N))) + (is (instance? java.math.BigDecimal (num 1.0M)))]))) diff --git a/test/clojure/core_test/number_questionmark.cljc b/test/clojure/core_test/number_questionmark.cljc index 069e9578..f298827f 100644 --- a/test/clojure/core_test/number_questionmark.cljc +++ b/test/clojure/core_test/number_questionmark.cljc @@ -1,46 +1,48 @@ (ns clojure.core-test.number-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-number? - (are [expected x] (= expected (number? x)) - true 0 - true 1 - true -1 - true r/max-int - true r/min-int - true 0.0 - true 1.0 - true -1.0 - true r/max-double - true r/min-double - true ##Inf - true ##-Inf - true ##NaN - true 0N - true 1N - true -1N - true 0/2 - true 1/2 - true -1/2 - true 0.0M - true 1.0M - true -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/number? + (deftest test-number? + (are [expected x] (= expected (number? x)) + true 0 + true 1 + true -1 + true r/max-int + true r/min-int + true 0.0 + true 1.0 + true -1.0 + true r/max-double + true r/min-double + true ##Inf + true ##-Inf + true ##NaN + true 0N + true 1N + true -1N + true 0/2 + true 1/2 + true -1/2 + true 0.0M + true 1.0M + true -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/numerator.cljc b/test/clojure/core_test/numerator.cljc index 6f2d2bf0..163f0ddd 100644 --- a/test/clojure/core_test/numerator.cljc +++ b/test/clojure/core_test/numerator.cljc @@ -2,7 +2,7 @@ (:require [clojure.test :as t :refer [deftest testing is are]] [clojure.core-test.portability :as p])) -(p/when-var-exists 'clojure.core/numerator +(p/when-var-exists clojure.core/numerator (deftest test-numerator (is (= 1 (numerator 1/2))) (is (= 2 (numerator 2/3))) diff --git a/test/clojure/core_test/odd_questionmark.cljc b/test/clojure/core_test/odd_questionmark.cljc index 34fa50d0..2084512d 100644 --- a/test/clojure/core_test/odd_questionmark.cljc +++ b/test/clojure/core_test/odd_questionmark.cljc @@ -1,25 +1,28 @@ (ns clojure.core-test.odd-questionmark - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - (t/are [in ex] (= (odd? in) ex) - 0 false - -0 false - 12 false - 17 true - -118 false - -119 true - 123N true - 122N false - -121N true - -120N false)) +(p/when-var-exists clojure.core/odd? + (deftest test-odd? + (testing "common" + (are [in ex] (= (odd? in) ex) + 0 false + -0 false + 12 false + 17 true + -118 false + -119 true + 123N true + 122N false + -121N true + -120N false)) -(t/deftest invalid - (t/are [x] (thrown? #?(:clj IllegalArgumentException :cljs js/Error) (odd? x)) - #_:clj-kondo/ignore nil - ##Inf - ##-Inf - ##NaN - 1.5 - 1/2 - 0.2M)) + (testing "invalid" + (are [x] (thrown? #?(:clj IllegalArgumentException :cljs js/Error) (odd? x)) + #_:clj-kondo/ignore nil + ##Inf + ##-Inf + ##NaN + 1.5 + 1/2 + 0.2M)))) diff --git a/test/clojure/core_test/or.cljc b/test/clojure/core_test/or.cljc index 5366104f..63122799 100644 --- a/test/clojure/core_test/or.cljc +++ b/test/clojure/core_test/or.cljc @@ -1,33 +1,36 @@ (ns clojure.core-test.or - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - (t/is (= nil (or))) - (t/are [x] (= x (or x)) - true - false - nil - :example) - (t/are [ex a b] (= ex (or a b)) - true true true - true true false - true false true - false false false - true true true - true true nil - true nil true - nil nil nil) - (t/testing "binds values before comparing" - (let [counter (volatile! 0)] - (t/is (= 1 (or nil (vswap! counter inc)))) - (t/is (= 1 @counter)))) - (t/testing "early exits" - (let [counter (volatile! 0)] - (t/is (= true (or true (vswap! counter inc)))) - (t/is (= 0 @counter)))) - (t/testing "handles varargs" - (t/is (= 3 (or nil nil 3))) - (t/is (= true (or nil nil nil nil nil nil nil nil nil nil nil nil true))))) +(p/when-var-exists clojure.core/or + (deftest test-or + (testing "common" + (is (= nil (or))) + (are [x] (= x (or x)) + true + false + nil + :example) + (are [ex a b] (= ex (or a b)) + true true true + true true false + true false true + false false false + true true true + true true nil + true nil true + nil nil nil) + (testing "binds values before comparing" + (let [counter (volatile! 0)] + (is (= 1 (or nil (vswap! counter inc)))) + (is (= 1 @counter)))) + (testing "early exits" + (let [counter (volatile! 0)] + (is (= true (or true (vswap! counter inc)))) + (is (= 0 @counter)))) + (testing "handles varargs" + (is (= 3 (or nil nil 3))) + (is (= true (or nil nil nil nil nil nil nil nil nil nil nil nil true))))) -(t/deftest infinite-sequence - (t/is (some? (or (range))))) + (testing "infinite-sequence" + (is (some? (or (range))))))) diff --git a/test/clojure/core_test/partial.cljc b/test/clojure/core_test/partial.cljc index c9e49e97..f14d9f11 100644 --- a/test/clojure/core_test/partial.cljc +++ b/test/clojure/core_test/partial.cljc @@ -1,25 +1,27 @@ (ns clojure.core-test.partial - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(defn test-fn [& args] - (into [] args)) + (defn test-fn [& args] + (into [] args)) -(t/deftest test-partial - (let [simple-use (partial inc 2)] - (t/is (= 3 (simple-use)))) - (let [lazily-evaluated (partial inc 2 3)] - #?(:clj (t/is (thrown? Exception (lazily-evaluated))) - :cljs (t/is (thrown? js/Error (lazily-evaluated))))) - (let [variadic (partial test-fn 1 2 3)] - (t/is (= [1 2 3 4] (variadic 4))) - (t/is (= [1 2 3 4 5] (variadic 4 5)))) - (let [infinite-sequence (partial #(take %2 %1) (range))] - (t/is (= '(0 1 2 3 4) (infinite-sequence 5))) - (t/is (= '(0 1 2) (infinite-sequence 3)))) - (let [partial-partial ((partial partial) test-fn) - pppartial (partial partial-partial :inner)] - (t/is (= [:inner :outer] (partial-partial :inner :outer))) - (t/is (= [:inner :outer] (pppartial :outer)))) - (let [seq-of-partials (map #(partial * %1 %2) (range) (range))] - (t/is (= (map #(* % % %) (range 5)) - (map #(%1 %2) seq-of-partials (range 5)))))) +(p/when-var-exists clojure.core/partial + (deftest test-partial + (let [simple-use (partial inc 2)] + (is (= 3 (simple-use)))) + (let [lazily-evaluated (partial inc 2 3)] + #?(:clj (is (thrown? Exception (lazily-evaluated))) + :cljs (is (thrown? js/Error (lazily-evaluated))))) + (let [variadic (partial test-fn 1 2 3)] + (is (= [1 2 3 4] (variadic 4))) + (is (= [1 2 3 4 5] (variadic 4 5)))) + (let [infinite-sequence (partial #(take %2 %1) (range))] + (is (= '(0 1 2 3 4) (infinite-sequence 5))) + (is (= '(0 1 2) (infinite-sequence 3)))) + (let [partial-partial ((partial partial) test-fn) + pppartial (partial partial-partial :inner)] + (is (= [:inner :outer] (partial-partial :inner :outer))) + (is (= [:inner :outer] (pppartial :outer)))) + (let [seq-of-partials (map #(partial * %1 %2) (range) (range))] + (is (= (map #(* % % %) (range 5)) + (map #(%1 %2) seq-of-partials (range 5))))))) diff --git a/test/clojure/core_test/plus.cljc b/test/clojure/core_test/plus.cljc index 24b1dd76..75e834f7 100644 --- a/test/clojure/core_test/plus.cljc +++ b/test/clojure/core_test/plus.cljc @@ -1,178 +1,179 @@ (ns clojure.core-test.plus (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) - -(deftest common - (are [sum x y] (and (= sum (+ x y)) - (= sum (+ y x))) ; addition should be commutative - 0 0 0 - 1 1 0 - 2 1 1 - 6 1 5 - 10 5 5 - 0 1 -1 - -2 -1 -1 - -1 -1 0 - - 0.0 0.0 0.0 - 1.0 1.0 0.0 - 2.0 1.0 1.0 - 6.0 1.0 5.0 - 10.0 5.0 5.0 - 0.0 1.0 -1.0 - -2.0 -1.0 -1.0 - -1.0 -1.0 0.0 - - 0.0 0.0 0 - 1.0 1.0 0 - 1.0 0.0 1 - 2.0 1.0 1 - 6.0 1.0 5 - 6.0 5.0 1 - 10.0 5.0 5 - 0.0 1.0 -1 - 0.0 -1.0 1 - -2.0 -1.0 -1 - -1.0 -1.0 0 - -1.0 0.0 -1 - - 0.0 0 0.0 - 1.0 1 0.0 - 1.0 0 1.0 - 2.0 1 1.0 - 6.0 1 5.0 - 6.0 5 1.0 - 10.0 5 5.0 - 0.0 1 -1.0 - 0.0 -1 1.0 - -2.0 -1 -1.0 - -1.0 -1 0.0 - -1.0 0 -1.0 - - 1N 0 1N - 1N 0N 1 - 1N 0N 1N - 2N 1N 1 - 2N 1 1N - 2N 1N 1N - 6N 1 5N - 6N 1N 5 - 6N 1N 5N) - - ;; Zero arg - (is (= 0 (+))) - - ;; One arg - (is (= 1 (+ 1))) - (is (= 2 (+ 2))) - - ;; Multi arg - (is (= 45 (+ 0 1 2 3 4 5 6 7 8 9))) - - - (is (thrown? Exception (+ 1 nil))) - (is (thrown? Exception (+ nil 1))) - (is (thrown? Exception (+ 1N nil))) - (is (thrown? Exception (+ nil 1N))) - (is (thrown? Exception (+ 1.0 nil))) - (is (thrown? Exception (+ nil 1.0))) - - #?@(:cljs nil - :default - [(is (thrown? Exception (+ r/max-int 1))) - (is (thrown? Exception (+ r/min-int -1))) - (is (instance? clojure.lang.BigInt (+ 0 1N))) - (is (instance? clojure.lang.BigInt (+ 0N 1))) - (is (instance? clojure.lang.BigInt (+ 0N 1N))) - (is (instance? clojure.lang.BigInt (+ 1N 1))) - (is (instance? clojure.lang.BigInt (+ 1 1N))) - (is (instance? clojure.lang.BigInt (+ 1N 1N))) - (is (instance? clojure.lang.BigInt (+ 1 5N))) - (is (instance? clojure.lang.BigInt (+ 1N 5))) - (is (instance? clojure.lang.BigInt (+ 1N 5N)))])) - - -(deftest rationals - (are [sum x y] (and (= sum (+ x y)) - (= sum (+ y x))) ; addition should be commutative - 1 1/2 1/2 - 1 1/3 2/3 - 1 1/4 3/4 - 1 1/5 4/5 - 1 1/6 5/6 - 1 1/7 6/7 - 1 1/8 7/8 - 1 1/9 8/9 - - 1/2 1 -1/2 - 1/3 1 -2/3 - 1/4 1 -3/4 - 1/5 1 -4/5 - 1/6 1 -5/6 - 1/7 1 -6/7 - 1/8 1 -7/8 - 1/9 1 -8/9 - - 3/2 1 1/2 - 5/3 1 2/3 - 7/4 1 3/4 - 9/5 1 4/5 - 11/6 1 5/6 - 13/7 1 6/7 - 15/8 1 7/8 - 17/9 1 8/9 - - 2 3/2 1/2 - 2 4/3 2/3 - - ;; Be careful here because floating point rounding can bite us. - ;; This case is pretty safe. - 1.5 1.0 1/2) - - (is (thrown? Exception (+ 1/2 nil))) - (is (thrown? Exception (+ nil 1/2))) - - #?@(:cljs nil - :default - [(is (+ r/max-int 1/2)) ; test that these don't throw - (is (+ r/min-int -1/2)) - (is (= r/max-double (+ r/max-double 1/2))) ; should silently round - (is (= (- r/max-double) (+ (- r/max-double) -1/2))) - (is (= 0.5 (+ r/min-double 1/2))) - (is (= -0.5 (+ r/min-double -1/2))) - (is (instance? clojure.lang.Ratio (+ 0 1/3))) - (is (instance? clojure.lang.Ratio (+ 0N 1/3))) - (is (instance? clojure.lang.Ratio (+ 1 1/3))) - (is (instance? clojure.lang.Ratio (+ 1N 1/3))) - ;; Note that we use `double?` here because JVM Clojure uses - ;; java.lang.Double instead of clojure.lang.Double and we'd - ;; like to keep this test as generic as possible. - (is (double? (+ 0.0 1/3))) - (is (double? (+ 1.0 1/3)))])) - -(deftest inf-nan - (are [sum x y] (and (= sum (+ x y)) - (= sum (+ y x))) ; addition should be commutative - - ##Inf 1 ##Inf - ##Inf 1N ##Inf - ##Inf 1.0 ##Inf - ##Inf 1/2 ##Inf - ##-Inf 1 ##-Inf - ##-Inf 1N ##-Inf - ##-Inf 1.0 ##-Inf - ##-Inf 1/2 ##-Inf) - - (are [x y] (and (NaN? (+ x y)) - (NaN? (+ y x))) - ##Inf ##-Inf - 1 ##NaN - 1N ##NaN - 1.0 ##NaN - 1/2 ##NaN - ##Inf ##NaN - ##-Inf ##NaN - ##NaN ##NaN) - - (is (thrown? Exception (+ ##NaN nil))) - (is (thrown? Exception (+ ##Inf nil)))) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) + +(p/when-var-exists clojure.core/+ + (deftest test-+ + (testing "common" + (are [sum x y] (and (= sum (+ x y)) + (= sum (+ y x))) ; addition should be commutative + 0 0 0 + 1 1 0 + 2 1 1 + 6 1 5 + 10 5 5 + 0 1 -1 + -2 -1 -1 + -1 -1 0 + + 0.0 0.0 0.0 + 1.0 1.0 0.0 + 2.0 1.0 1.0 + 6.0 1.0 5.0 + 10.0 5.0 5.0 + 0.0 1.0 -1.0 + -2.0 -1.0 -1.0 + -1.0 -1.0 0.0 + + 0.0 0.0 0 + 1.0 1.0 0 + 1.0 0.0 1 + 2.0 1.0 1 + 6.0 1.0 5 + 6.0 5.0 1 + 10.0 5.0 5 + 0.0 1.0 -1 + 0.0 -1.0 1 + -2.0 -1.0 -1 + -1.0 -1.0 0 + -1.0 0.0 -1 + + 0.0 0 0.0 + 1.0 1 0.0 + 1.0 0 1.0 + 2.0 1 1.0 + 6.0 1 5.0 + 6.0 5 1.0 + 10.0 5 5.0 + 0.0 1 -1.0 + 0.0 -1 1.0 + -2.0 -1 -1.0 + -1.0 -1 0.0 + -1.0 0 -1.0 + + 1N 0 1N + 1N 0N 1 + 1N 0N 1N + 2N 1N 1 + 2N 1 1N + 2N 1N 1N + 6N 1 5N + 6N 1N 5 + 6N 1N 5N) + + ;; Zero arg + (is (= 0 (+))) + + ;; One arg + (is (= 1 (+ 1))) + (is (= 2 (+ 2))) + + ;; Multi arg + (is (= 45 (+ 0 1 2 3 4 5 6 7 8 9))) + + (is (thrown? Exception (+ 1 nil))) + (is (thrown? Exception (+ nil 1))) + (is (thrown? Exception (+ 1N nil))) + (is (thrown? Exception (+ nil 1N))) + (is (thrown? Exception (+ 1.0 nil))) + (is (thrown? Exception (+ nil 1.0))) + + #?@(:cljs nil + :default + [(is (thrown? Exception (+ r/max-int 1))) + (is (thrown? Exception (+ r/min-int -1))) + (is (instance? clojure.lang.BigInt (+ 0 1N))) + (is (instance? clojure.lang.BigInt (+ 0N 1))) + (is (instance? clojure.lang.BigInt (+ 0N 1N))) + (is (instance? clojure.lang.BigInt (+ 1N 1))) + (is (instance? clojure.lang.BigInt (+ 1 1N))) + (is (instance? clojure.lang.BigInt (+ 1N 1N))) + (is (instance? clojure.lang.BigInt (+ 1 5N))) + (is (instance? clojure.lang.BigInt (+ 1N 5))) + (is (instance? clojure.lang.BigInt (+ 1N 5N)))])) + + (testing "rationals" + (are [sum x y] (and (= sum (+ x y)) + (= sum (+ y x))) ; addition should be commutative + 1 1/2 1/2 + 1 1/3 2/3 + 1 1/4 3/4 + 1 1/5 4/5 + 1 1/6 5/6 + 1 1/7 6/7 + 1 1/8 7/8 + 1 1/9 8/9 + + 1/2 1 -1/2 + 1/3 1 -2/3 + 1/4 1 -3/4 + 1/5 1 -4/5 + 1/6 1 -5/6 + 1/7 1 -6/7 + 1/8 1 -7/8 + 1/9 1 -8/9 + + 3/2 1 1/2 + 5/3 1 2/3 + 7/4 1 3/4 + 9/5 1 4/5 + 11/6 1 5/6 + 13/7 1 6/7 + 15/8 1 7/8 + 17/9 1 8/9 + + 2 3/2 1/2 + 2 4/3 2/3 + + ;; Be careful here because floating point rounding can bite us. + ;; This case is pretty safe. + 1.5 1.0 1/2) + + (is (thrown? Exception (+ 1/2 nil))) + (is (thrown? Exception (+ nil 1/2))) + + #?@(:cljs nil + :default + [(is (+ r/max-int 1/2)) ; test that these don't throw + (is (+ r/min-int -1/2)) + (is (= r/max-double (+ r/max-double 1/2))) ; should silently round + (is (= (- r/max-double) (+ (- r/max-double) -1/2))) + (is (= 0.5 (+ r/min-double 1/2))) + (is (= -0.5 (+ r/min-double -1/2))) + (is (instance? clojure.lang.Ratio (+ 0 1/3))) + (is (instance? clojure.lang.Ratio (+ 0N 1/3))) + (is (instance? clojure.lang.Ratio (+ 1 1/3))) + (is (instance? clojure.lang.Ratio (+ 1N 1/3))) + ;; Note that we use `double?` here because JVM Clojure uses + ;; java.lang.Double instead of clojure.lang.Double and we'd + ;; like to keep this test as generic as possible. + (is (double? (+ 0.0 1/3))) + (is (double? (+ 1.0 1/3)))])) + + (testing "inf-nan" + (are [sum x y] (and (= sum (+ x y)) + (= sum (+ y x))) ; addition should be commutative + + ##Inf 1 ##Inf + ##Inf 1N ##Inf + ##Inf 1.0 ##Inf + ##Inf 1/2 ##Inf + ##-Inf 1 ##-Inf + ##-Inf 1N ##-Inf + ##-Inf 1.0 ##-Inf + ##-Inf 1/2 ##-Inf) + + (are [x y] (and (NaN? (+ x y)) + (NaN? (+ y x))) + ##Inf ##-Inf + 1 ##NaN + 1N ##NaN + 1.0 ##NaN + 1/2 ##NaN + ##Inf ##NaN + ##-Inf ##NaN + ##NaN ##NaN) + + (is (thrown? Exception (+ ##NaN nil))) + (is (thrown? Exception (+ ##Inf nil)))))) diff --git a/test/clojure/core_test/plus_singlequote.cljc b/test/clojure/core_test/plus_singlequote.cljc index baf70cb7..7588ba19 100644 --- a/test/clojure/core_test/plus_singlequote.cljc +++ b/test/clojure/core_test/plus_singlequote.cljc @@ -1,88 +1,87 @@ (ns clojure.core-test.plus-singlequote - (:require [clojure.test :as t :refer [is are]] - [clojure.core-test.number-range :as r])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -#?(:cljs nil - :default - (t/deftest common - (are [sum addend summand] (= sum (+' addend summand)) - 0 0 0 - 1 1 0 - 1 0 1 - 2 1 1 - 6 1 5 - 6 5 1 - 10 5 5 - 0 1 -1 - 0 -1 1 - -2 -1 -1 - -1 -1 0 - -1 0 -1 - (+ 1N r/max-int) r/max-int 1 - (- r/min-int 1N) -1 r/min-int +(p/when-var-exists clojure.core/+' + (deftest test-+' + (are [sum addend summand] (= sum (+' addend summand)) + 0 0 0 + 1 1 0 + 1 0 1 + 2 1 1 + 6 1 5 + 6 5 1 + 10 5 5 + 0 1 -1 + 0 -1 1 + -2 -1 -1 + -1 -1 0 + -1 0 -1 + (+ 1N r/max-int) r/max-int 1 + (- r/min-int 1N) -1 r/min-int - 0.0 0.0 0.0 - 1.0 1.0 0.0 - 1.0 0.0 1.0 - 2.0 1.0 1.0 - 6.0 1.0 5.0 - 6.0 5.0 1.0 - 10.0 5.0 5.0 - 0.0 1.0 -1.0 - 0.0 -1.0 1.0 - -2.0 -1.0 -1.0 - -1.0 -1.0 0.0 - -1.0 0.0 -1.0 + 0.0 0.0 0.0 + 1.0 1.0 0.0 + 1.0 0.0 1.0 + 2.0 1.0 1.0 + 6.0 1.0 5.0 + 6.0 5.0 1.0 + 10.0 5.0 5.0 + 0.0 1.0 -1.0 + 0.0 -1.0 1.0 + -2.0 -1.0 -1.0 + -1.0 -1.0 0.0 + -1.0 0.0 -1.0 - 0.0 0.0 0 - 1.0 1.0 0 - 1.0 0.0 1 - 2.0 1.0 1 - 6.0 1.0 5 - 6.0 5.0 1 - 10.0 5.0 5 - 0.0 1.0 -1 - 0.0 -1.0 1 - -2.0 -1.0 -1 - -1.0 -1.0 0 - -1.0 0.0 -1 + 0.0 0.0 0 + 1.0 1.0 0 + 1.0 0.0 1 + 2.0 1.0 1 + 6.0 1.0 5 + 6.0 5.0 1 + 10.0 5.0 5 + 0.0 1.0 -1 + 0.0 -1.0 1 + -2.0 -1.0 -1 + -1.0 -1.0 0 + -1.0 0.0 -1 - 0.0 0 0.0 - 1.0 1 0.0 - 1.0 0 1.0 - 2.0 1 1.0 - 6.0 1 5.0 - 6.0 5 1.0 - 10.0 5 5.0 - 0.0 1 -1.0 - 0.0 -1 1.0 - -2.0 -1 -1.0 - -1.0 -1 0.0 - -1.0 0 -1.0 + 0.0 0 0.0 + 1.0 1 0.0 + 1.0 0 1.0 + 2.0 1 1.0 + 6.0 1 5.0 + 6.0 5 1.0 + 10.0 5 5.0 + 0.0 1 -1.0 + 0.0 -1 1.0 + -2.0 -1 -1.0 + -1.0 -1 0.0 + -1.0 0 -1.0 - 1N 0 1N - 1N 0N 1 - 1N 0N 1N - 2N 1N 1 - 2N 1 1N - 2N 1N 1N - 6N 1 5N - 6N 1N 5 - 6N 1N 5N) + 1N 0 1N + 1N 0N 1 + 1N 0N 1N + 2N 1N 1 + 2N 1 1N + 2N 1N 1N + 6N 1 5N + 6N 1N 5 + 6N 1N 5N) - (is (thrown? Exception (+' 1 nil))) - (is (thrown? Exception (+' nil 1))) + (is (thrown? Exception (+' 1 nil))) + (is (thrown? Exception (+' nil 1))) - (is (instance? clojure.lang.BigInt (+' 0 1N))) - (is (instance? clojure.lang.BigInt (+' 0N 1))) - (is (instance? clojure.lang.BigInt (+' 0N 1N))) - (is (instance? clojure.lang.BigInt (+' 1N 1))) - (is (instance? clojure.lang.BigInt (+' 1 1N))) - (is (instance? clojure.lang.BigInt (+' 1N 1N))) - (is (instance? clojure.lang.BigInt (+' 1 5N))) - (is (instance? clojure.lang.BigInt (+' 1N 5))) - (is (instance? clojure.lang.BigInt (+' 1N 5N))) - - (is (instance? clojure.lang.BigInt (+' -1 r/min-int))) - (is (instance? clojure.lang.BigInt (+' r/min-int -1))))) + (is (instance? clojure.lang.BigInt (+' 0 1N))) + (is (instance? clojure.lang.BigInt (+' 0N 1))) + (is (instance? clojure.lang.BigInt (+' 0N 1N))) + (is (instance? clojure.lang.BigInt (+' 1N 1))) + (is (instance? clojure.lang.BigInt (+' 1 1N))) + (is (instance? clojure.lang.BigInt (+' 1N 1N))) + (is (instance? clojure.lang.BigInt (+' 1 5N))) + (is (instance? clojure.lang.BigInt (+' 1N 5))) + (is (instance? clojure.lang.BigInt (+' 1N 5N))) + (is (instance? clojure.lang.BigInt (+' -1 r/min-int))) + (is (instance? clojure.lang.BigInt (+' r/min-int -1))))) diff --git a/test/clojure/core_test/portability.cljc b/test/clojure/core_test/portability.cljc index 89aee6c9..573e7c32 100644 --- a/test/clojure/core_test/portability.cljc +++ b/test/clojure/core_test/portability.cljc @@ -1,7 +1,7 @@ (ns clojure.core-test.portability) (defmacro when-var-exists [var-sym & body] - `(let [s# ~var-sym + `(let [s# '~var-sym v# (resolve s#)] (if v# (do diff --git a/test/clojure/core_test/pos_int_questionmark.cljc b/test/clojure/core_test/pos_int_questionmark.cljc index 77f82805..70b33d90 100644 --- a/test/clojure/core_test/pos_int_questionmark.cljc +++ b/test/clojure/core_test/pos_int_questionmark.cljc @@ -1,46 +1,48 @@ (ns clojure.core-test.pos-int-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-pos-int? - (are [expected x] (= expected (pos-int? x)) - false 0 - true 1 - false -1 - true r/max-int - false r/min-int - false 0.0 - false 1.0 - false -1.0 - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - false 0N - false 1N - false -1N - false 0/2 - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/pos-int? + (deftest test-pos-int? + (are [expected x] (= expected (pos-int? x)) + false 0 + true 1 + false -1 + true r/max-int + false r/min-int + false 0.0 + false 1.0 + false -1.0 + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + false 1N + false -1N + false 0/2 + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/pos_questionmark.cljc b/test/clojure/core_test/pos_questionmark.cljc index 66e19b47..60d9e91a 100644 --- a/test/clojure/core_test/pos_questionmark.cljc +++ b/test/clojure/core_test/pos_questionmark.cljc @@ -1,32 +1,34 @@ (ns clojure.core-test.pos-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-pos? - (are [expected x] (= expected (pos? x)) - false 0 - true 1 - false -1 - false r/min-int - true r/max-int - false 0.0 - true 1.0 - false -1.0 - true r/min-double - true r/max-double - true ##Inf - false ##-Inf - false ##NaN - false 0N - true 1N - false -1N - false 0/2 - true 1/2 - false -1/2 - false 0.0M - true 1.0M - false -1.0M) +(p/when-var-exists clojure.core/pos? + (deftest test-pos? + (are [expected x] (= expected (pos? x)) + false 0 + true 1 + false -1 + false r/min-int + true r/max-int + false 0.0 + true 1.0 + false -1.0 + true r/min-double + true r/max-double + true ##Inf + false ##-Inf + false ##NaN + false 0N + true 1N + false -1N + false 0/2 + true 1/2 + false -1/2 + false 0.0M + true 1.0M + false -1.0M) - (is (thrown? Exception (pos? nil))) - (is (thrown? Exception (pos? false))) - (is (thrown? Exception (pos? true)))) + (is (thrown? Exception (pos? nil))) + (is (thrown? Exception (pos? false))) + (is (thrown? Exception (pos? true))))) diff --git a/test/clojure/core_test/pr_str.cljc b/test/clojure/core_test/pr_str.cljc index 64060970..6f274fcb 100644 --- a/test/clojure/core_test/pr_str.cljc +++ b/test/clojure/core_test/pr_str.cljc @@ -1,7 +1,9 @@ (ns clojure.core-test.pr-str - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-pr-str - (is (= "\"a\" \"string\"" (pr-str "a" "string"))) - (is (= "nil \"a\" \"string\" \\A \\space 1 17.0 [:a :b] {:c :d} #{:e}" - (pr-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e})))) +(p/when-var-exists clojure.core/pr-str + (deftest test-pr-str + (is (= "\"a\" \"string\"" (pr-str "a" "string"))) + (is (= "nil \"a\" \"string\" \\A \\space 1 17.0 [:a :b] {:c :d} #{:e}" + (pr-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e}))))) diff --git a/test/clojure/core_test/print_str.cljc b/test/clojure/core_test/print_str.cljc index f6efc5b2..dde601b4 100644 --- a/test/clojure/core_test/print_str.cljc +++ b/test/clojure/core_test/print_str.cljc @@ -1,7 +1,9 @@ (ns clojure.core-test.print-str - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-print-str - (is (= "a string" (print-str "a" "string"))) - (is (= "nil a string A 1 17.0 [:a :b] {:c :d} #{:e}" - (print-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e})))) +(p/when-var-exists clojure.core/print-str + (deftest test-print-str + (is (= "a string" (print-str "a" "string"))) + (is (= "nil a string A 1 17.0 [:a :b] {:c :d} #{:e}" + (print-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e}))))) diff --git a/test/clojure/core_test/println_str.cljc b/test/clojure/core_test/println_str.cljc index 65b319a6..cd8c405b 100644 --- a/test/clojure/core_test/println_str.cljc +++ b/test/clojure/core_test/println_str.cljc @@ -1,13 +1,15 @@ (ns clojure.core-test.println-str - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-println-str - (let [nl (println-str)] - ;; `nl` grabs the platform specific newline without calling out to - ;; platform-specific code (e.g., Java) since we want this to run - ;; in all environments. Note that we're not actually testing - ;; whether the newline sequence itself is correct, only that - ;; `println-str` adds it to the end of the string. - (is (= (str "a string" nl) (println-str "a" "string"))) - (is (= (str "nil a string A 1 17.0 [:a :b] {:c :d} #{:e}" nl) - (println-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e}))))) +(p/when-var-exists clojure.core/println-str + (deftest test-println-str + (let [nl (println-str)] + ;; `nl` grabs the platform specific newline without calling out to + ;; platform-specific code (e.g., Java) since we want this to run + ;; in all environments. Note that we're not actually testing + ;; whether the newline sequence itself is correct, only that + ;; `println-str` adds it to the end of the string. + (is (= (str "a string" nl) (println-str "a" "string"))) + (is (= (str "nil a string A 1 17.0 [:a :b] {:c :d} #{:e}" nl) + (println-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e})))))) diff --git a/test/clojure/core_test/prn_str.cljc b/test/clojure/core_test/prn_str.cljc index f52f69cd..a07d5d61 100644 --- a/test/clojure/core_test/prn_str.cljc +++ b/test/clojure/core_test/prn_str.cljc @@ -1,13 +1,15 @@ (ns clojure.core-test.prn-str - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-prn-str - (let [nl (prn-str)] - ;; `nl` grabs the platform specific newline without calling out to - ;; platform-specific code (e.g., Java) since we want this to run - ;; in all environments. Note that we're not actually testing - ;; whether the newline sequence itself is correct, only that - ;; `prn-str` adds it to the end of the string. - (is (= (str "\"a\" \"string\"" nl) (prn-str "a" "string"))) - (is (= (str "nil \"a\" \"string\" \\A \\space 1 17.0 [:a :b] {:c :d} #{:e}" nl) - (prn-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e}))))) +(p/when-var-exists clojure.core/prn-str + (deftest test-prn-str + (let [nl (prn-str)] + ;; `nl` grabs the platform specific newline without calling out to + ;; platform-specific code (e.g., Java) since we want this to run + ;; in all environments. Note that we're not actually testing + ;; whether the newline sequence itself is correct, only that + ;; `prn-str` adds it to the end of the string. + (is (= (str "\"a\" \"string\"" nl) (prn-str "a" "string"))) + (is (= (str "nil \"a\" \"string\" \\A \\space 1 17.0 [:a :b] {:c :d} #{:e}" nl) + (prn-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e})))))) diff --git a/test/clojure/core_test/qualified_ident_questionmark.cljc b/test/clojure/core_test/qualified_ident_questionmark.cljc index d6642bfe..97ef14d3 100644 --- a/test/clojure/core_test/qualified_ident_questionmark.cljc +++ b/test/clojure/core_test/qualified_ident_questionmark.cljc @@ -1,18 +1,20 @@ (ns clojure.core-test.qualified-ident-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-qualified-ident? - (are [expected x] (= expected (qualified-ident? x)) - false :a-keyword - false 'a-symbol - true :a-ns/a-keyword - true 'a-ns/a-keyword - false "a string" - false 0 - false 0N - false 0.0 - false 1/2 - false 0.0M - false false - false true - false nil)) +(p/when-var-exists clojure.core/qualified-ident? + (deftest test-qualified-ident? + (are [expected x] (= expected (qualified-ident? x)) + false :a-keyword + false 'a-symbol + true :a-ns/a-keyword + true 'a-ns/a-keyword + false "a string" + false 0 + false 0N + false 0.0 + false 1/2 + false 0.0M + false false + false true + false nil))) diff --git a/test/clojure/core_test/qualified_keyword_questionmark.cljc b/test/clojure/core_test/qualified_keyword_questionmark.cljc index bbe16f46..892f1bd3 100644 --- a/test/clojure/core_test/qualified_keyword_questionmark.cljc +++ b/test/clojure/core_test/qualified_keyword_questionmark.cljc @@ -1,18 +1,20 @@ (ns clojure.core-test.qualified-keyword-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-qualified-keyword? - (are [expected x] (= expected (qualified-keyword? x)) - false :a-keyword - false 'a-symbol - true :a-ns/a-keyword - false 'a-ns/a-keyword - false "a string" - false 0 - false 0N - false 0.0 - false 1/2 - false 0.0M - false false - false true - false nil)) +(p/when-var-exists clojure.core/qualified-keyword? + (deftest test-qualified-keyword? + (are [expected x] (= expected (qualified-keyword? x)) + false :a-keyword + false 'a-symbol + true :a-ns/a-keyword + false 'a-ns/a-keyword + false "a string" + false 0 + false 0N + false 0.0 + false 1/2 + false 0.0M + false false + false true + false nil))) diff --git a/test/clojure/core_test/qualified_symbol_questionmark.cljc b/test/clojure/core_test/qualified_symbol_questionmark.cljc index b902f826..d3c1ecac 100644 --- a/test/clojure/core_test/qualified_symbol_questionmark.cljc +++ b/test/clojure/core_test/qualified_symbol_questionmark.cljc @@ -1,18 +1,20 @@ (ns clojure.core-test.qualified-symbol-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-qualified-symbol? - (are [expected x] (= expected (qualified-symbol? x)) - false :a-keyword - false 'a-symbol - false :a-ns/a-keyword - true 'a-ns/a-keyword - false "a string" - false 0 - false 0N - false 0.0 - false 1/2 - false 0.0M - false false - false true - false nil)) +(p/when-var-exists clojure.core/qualified-symbol? + (deftest test-qualified-symbol? + (are [expected x] (= expected (qualified-symbol? x)) + false :a-keyword + false 'a-symbol + false :a-ns/a-keyword + true 'a-ns/a-keyword + false "a string" + false 0 + false 0N + false 0.0 + false 1/2 + false 0.0M + false false + false true + false nil))) diff --git a/test/clojure/core_test/quot.cljc b/test/clojure/core_test/quot.cljc index aac2a4d5..58581aa9 100644 --- a/test/clojure/core_test/quot.cljc +++ b/test/clojure/core_test/quot.cljc @@ -1,86 +1,87 @@ (ns clojure.core-test.quot (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p] [clojure.core-test.portability :as p])) -(deftest test-quot - (are [type-pred expected x y] (let [r (quot x y)] - (and (type-pred r) - (= expected r))) - int? 3 10 3 - int? -3 -10 3 - int? 3 -10 -3 - int? -3 10 -3 +(p/when-var-exists clojure.core/quot + (deftest test-quot + (are [type-pred expected x y] (let [r (quot x y)] + (and (type-pred r) + (= expected r))) + int? 3 10 3 + int? -3 -10 3 + int? 3 -10 -3 + int? -3 10 -3 - p/big-int? 3N 10 3N - p/big-int? -3N -10 3N - p/big-int? 3N -10 -3N - p/big-int? -3N 10 -3N - p/big-int? 3N 10N 3 - p/big-int? -3N -10N 3 - p/big-int? 3N -10N -3 - p/big-int? -3N 10N -3 - p/big-int? 3N 10N 3N - p/big-int? -3N -10N 3N - p/big-int? 3N -10N -3N - p/big-int? -3N 10N -3N + p/big-int? 3N 10 3N + p/big-int? -3N -10 3N + p/big-int? 3N -10 -3N + p/big-int? -3N 10 -3N + p/big-int? 3N 10N 3 + p/big-int? -3N -10N 3 + p/big-int? 3N -10N -3 + p/big-int? -3N 10N -3 + p/big-int? 3N 10N 3N + p/big-int? -3N -10N 3N + p/big-int? 3N -10N -3N + p/big-int? -3N 10N -3N - double? 3.0 10 3.0 - double? -3.0 -10 3.0 - double? 3.0 -10 -3.0 - double? -3.0 10 -3.0 - double? 3.0 10.0 3 - double? -3.0 -10.0 3 - double? 3.0 -10.0 -3 - double? -3.0 10.0 -3 - double? 3.0 10.0 3.0 - double? -3.0 -10.0 3.0 - double? 3.0 -10.0 -3.0 - double? -3.0 10.0 -3.0 + double? 3.0 10 3.0 + double? -3.0 -10 3.0 + double? 3.0 -10 -3.0 + double? -3.0 10 -3.0 + double? 3.0 10.0 3 + double? -3.0 -10.0 3 + double? 3.0 -10.0 -3 + double? -3.0 10.0 -3 + double? 3.0 10.0 3.0 + double? -3.0 -10.0 3.0 + double? 3.0 -10.0 -3.0 + double? -3.0 10.0 -3.0 - decimal? 3.0M 10 3.0M - decimal? -3.0M -10 3.0M - decimal? 3.0M -10 -3.0M - decimal? -3.0M 10 -3.0M - decimal? 3.0M 10.0M 3 - decimal? -3.0M -10.0M 3 - decimal? 3.0M -10.0M -3 - decimal? -3.0M 10.0M -3 - decimal? 3.0M 10.0M 3.0M - decimal? -3.0M -10.0M 3.0M - decimal? 3.0M -10.0M -3.0M - decimal? -3.0M 10.0M -3.0M + decimal? 3.0M 10 3.0M + decimal? -3.0M -10 3.0M + decimal? 3.0M -10 -3.0M + decimal? -3.0M 10 -3.0M + decimal? 3.0M 10.0M 3 + decimal? -3.0M -10.0M 3 + decimal? 3.0M -10.0M -3 + decimal? -3.0M 10.0M -3 + decimal? 3.0M 10.0M 3.0M + decimal? -3.0M -10.0M 3.0M + decimal? 3.0M -10.0M -3.0M + decimal? -3.0M 10.0M -3.0M - ;; Unexpectedly downconverts result to double, rather than BigDecimal - double? 3.0 10.0M 3.0 - double? -3.0 -10.0M 3.0 - double? 3.0 -10.0M -3.0 - double? -3.0 10.0M -3.0 - double? 3.0 10.0 3.0M - double? -3.0 -10.0 3.0M - double? 3.0 -10.0 -3.0M - double? -3.0 10.0 -3.0M + ;; Unexpectedly downconverts result to double, rather than BigDecimal + double? 3.0 10.0M 3.0 + double? -3.0 -10.0M 3.0 + double? 3.0 -10.0M -3.0 + double? -3.0 10.0M -3.0 + double? 3.0 10.0 3.0M + double? -3.0 -10.0 3.0M + double? 3.0 -10.0 -3.0M + double? -3.0 10.0 -3.0M - ;; Anything with a ratio seems to convert to BigInt - p/big-int? 6N 3 1/2 - p/big-int? 2N 3 4/3 - p/big-int? 1N 37/2 15 - p/big-int? -6N 3 -1/2 - p/big-int? -2N 3 -4/3 - p/big-int? -1N 37/2 -15 - p/big-int? -6N -3 1/2 - p/big-int? -2N -3 4/3 - p/big-int? -1N -37/2 15 - p/big-int? 6N -3 -1/2 - p/big-int? 2N -3 -4/3 - p/big-int? 1N -37/2 -15 + ;; Anything with a ratio seems to convert to BigInt + p/big-int? 6N 3 1/2 + p/big-int? 2N 3 4/3 + p/big-int? 1N 37/2 15 + p/big-int? -6N 3 -1/2 + p/big-int? -2N 3 -4/3 + p/big-int? -1N 37/2 -15 + p/big-int? -6N -3 1/2 + p/big-int? -2N -3 4/3 + p/big-int? -1N -37/2 15 + p/big-int? 6N -3 -1/2 + p/big-int? 2N -3 -4/3 + p/big-int? 1N -37/2 -15 - double? 0.0 1 ##Inf - double? 0.0 1 ##-Inf) - - (is (thrown? Exception (quot 10 0))) - (is (thrown? Exception (quot ##Inf 1))) ; surprising since (/ ##Inf 1) = ##Inf - (is (thrown? Exception (quot ##-Inf 1))) ; surprising since (/ ##-Inf 1) = ##-Inf - (is (thrown? Exception (quot ##NaN 1))) - (is (thrown? Exception (quot 1 ##NaN))) - (is (thrown? Exception (quot ##NaN 1)))) + double? 0.0 1 ##Inf + double? 0.0 1 ##-Inf) + (is (thrown? Exception (quot 10 0))) + (is (thrown? Exception (quot ##Inf 1))) ; surprising since (/ ##Inf 1) = ##Inf + (is (thrown? Exception (quot ##-Inf 1))) ; surprising since (/ ##-Inf 1) = ##-Inf + (is (thrown? Exception (quot ##NaN 1))) + (is (thrown? Exception (quot 1 ##NaN))) + (is (thrown? Exception (quot ##NaN 1))))) diff --git a/test/clojure/core_test/ratio_questionmark.cljc b/test/clojure/core_test/ratio_questionmark.cljc index ddc33941..bd571bb0 100644 --- a/test/clojure/core_test/ratio_questionmark.cljc +++ b/test/clojure/core_test/ratio_questionmark.cljc @@ -1,46 +1,48 @@ (ns clojure.core-test.ratio-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-ratio? - (are [expected x] (= expected (ratio? x)) - false 0 - false 1 - false -1 - false r/max-int - false r/min-int - false 0.0 - false 1.0 - false -1.0 - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - false 0N - false 1N - false -1N - false 0/2 ; perhaps surprising - true 1/2 - true -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/ratio? + (deftest test-ratio? + (are [expected x] (= expected (ratio? x)) + false 0 + false 1 + false -1 + false r/max-int + false r/min-int + false 0.0 + false 1.0 + false -1.0 + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + false 1N + false -1N + false 0/2 ; perhaps surprising + true 1/2 + true -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/rational_questionmark.cljc b/test/clojure/core_test/rational_questionmark.cljc index 31d0cb62..bfff583a 100644 --- a/test/clojure/core_test/rational_questionmark.cljc +++ b/test/clojure/core_test/rational_questionmark.cljc @@ -1,46 +1,48 @@ (ns clojure.core-test.rational-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-rational? - (are [expected x] (= expected (rational? x)) - true 0 - true 1 - true -1 - true r/max-int - true r/min-int - false 0.0 - false 1.0 - false -1.0 - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - true 0N - true 1N - true -1N - true 0/2 ; perhaps surprising - true 1/2 - true -1/2 - true 0.0M ; perhaps surprising - true 1.0M ; perhaps surprising - true -1.0M ; perhaps surprising - false nil - false true - false false - false "a string" - false "0" - false "1" - false "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/rational? + (deftest test-rational? + (are [expected x] (= expected (rational? x)) + true 0 + true 1 + true -1 + true r/max-int + true r/min-int + false 0.0 + false 1.0 + false -1.0 + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + true 0N + true 1N + true -1N + true 0/2 ; perhaps surprising + true 1/2 + true -1/2 + true 0.0M ; perhaps surprising + true 1.0M ; perhaps surprising + true -1.0M ; perhaps surprising + false nil + false true + false false + false "a string" + false "0" + false "1" + false "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/rationalize.cljc b/test/clojure/core_test/rationalize.cljc index 14d560ee..261fe808 100644 --- a/test/clojure/core_test/rationalize.cljc +++ b/test/clojure/core_test/rationalize.cljc @@ -1,24 +1,26 @@ (ns clojure.core-test.rationalize - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-rationalize - (are [expected x] (let [x' (rationalize x)] - (and (= expected x') - (or (integer? x') - (ratio? x')))) - 1 1 - 0 0 - -1 -1 - 1N 1N - 0N 0N - -1N -1N - 1 1.0 - 0 0.0 - -1 -1.0 - 3/2 1.5 - 11/10 1.1 - 3333333333333333/10000000000000000 (/ 1.0 3.0) - 1 1.0M - 0 0.0M - 3/2 1.5M - 11/10 1.1M)) +(p/when-var-exists clojure.core/rationalize + (deftest test-rationalize + (are [expected x] (let [x' (rationalize x)] + (and (= expected x') + (or (integer? x') + (ratio? x')))) + 1 1 + 0 0 + -1 -1 + 1N 1N + 0N 0N + -1N -1N + 1 1.0 + 0 0.0 + -1 -1.0 + 3/2 1.5 + 11/10 1.1 + 3333333333333333/10000000000000000 (/ 1.0 3.0) + 1 1.0M + 0 0.0M + 3/2 1.5M + 11/10 1.1M))) diff --git a/test/clojure/core_test/rem.cljc b/test/clojure/core_test/rem.cljc index 6d197261..e0231e15 100644 --- a/test/clojure/core_test/rem.cljc +++ b/test/clojure/core_test/rem.cljc @@ -1,83 +1,85 @@ (ns clojure.core-test.rem (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p] [clojure.core-test.portability :as p])) -(deftest test-rem - (are [type-pred expected x y] (let [r (rem x y)] - (and (type-pred r) - (= expected r))) - int? 1 10 3 - int? -1 -10 3 - int? -1 -10 -3 - int? 1 10 -3 +(p/when-var-exists clojure.core/rem + (deftest test-rem + (are [type-pred expected x y] (let [r (rem x y)] + (and (type-pred r) + (= expected r))) + int? 1 10 3 + int? -1 -10 3 + int? -1 -10 -3 + int? 1 10 -3 - p/big-int? 1N 10 3N - p/big-int? -1N -10 3N - p/big-int? -1N -10 -3N - p/big-int? 1N 10 -3N - p/big-int? 1N 10N 3 - p/big-int? -1N -10N 3 - p/big-int? -1N -10N -3 - p/big-int? 1N 10N -3 - p/big-int? 1N 10N 3N - p/big-int? -1N -10N 3N - p/big-int? -1N -10N -3N - p/big-int? 1N 10N -3N + p/big-int? 1N 10 3N + p/big-int? -1N -10 3N + p/big-int? -1N -10 -3N + p/big-int? 1N 10 -3N + p/big-int? 1N 10N 3 + p/big-int? -1N -10N 3 + p/big-int? -1N -10N -3 + p/big-int? 1N 10N -3 + p/big-int? 1N 10N 3N + p/big-int? -1N -10N 3N + p/big-int? -1N -10N -3N + p/big-int? 1N 10N -3N - double? 1.0 10 3.0 - double? -1.0 -10 3.0 - double? -1.0 -10 -3.0 - double? 1.0 10 -3.0 - double? 1.0 10.0 3 - double? -1.0 -10.0 3 - double? -1.0 -10.0 -3 - double? 1.0 10.0 -3 - double? 1.0 10.0 3.0 - double? -1.0 -10.0 3.0 - double? -1.0 -10.0 -3.0 - double? 1.0 10.0 -3.0 + double? 1.0 10 3.0 + double? -1.0 -10 3.0 + double? -1.0 -10 -3.0 + double? 1.0 10 -3.0 + double? 1.0 10.0 3 + double? -1.0 -10.0 3 + double? -1.0 -10.0 -3 + double? 1.0 10.0 -3 + double? 1.0 10.0 3.0 + double? -1.0 -10.0 3.0 + double? -1.0 -10.0 -3.0 + double? 1.0 10.0 -3.0 - decimal? 1.0M 10 3.0M - decimal? -1.0M -10 3.0M - decimal? -1.0M -10 -3.0M - decimal? 1.0M 10 -3.0M - decimal? 1.0M 10.0M 3 - decimal? -1.0M -10.0M 3 - decimal? -1.0M -10.0M -3 - decimal? 1.0M 10.0M -3 - decimal? 1.0M 10.0M 3.0M - decimal? -1.0M -10.0M 3.0M - decimal? -1.0M -10.0M -3.0M - decimal? 1.0M 10.0M -3.0M + decimal? 1.0M 10 3.0M + decimal? -1.0M -10 3.0M + decimal? -1.0M -10 -3.0M + decimal? 1.0M 10 -3.0M + decimal? 1.0M 10.0M 3 + decimal? -1.0M -10.0M 3 + decimal? -1.0M -10.0M -3 + decimal? 1.0M 10.0M -3 + decimal? 1.0M 10.0M 3.0M + decimal? -1.0M -10.0M 3.0M + decimal? -1.0M -10.0M -3.0M + decimal? 1.0M 10.0M -3.0M - ;; Unexpectedly downconverts result to double, rather than BigDecimal - double? 1.0 10.0M 3.0 - double? -1.0 -10.0M 3.0 - double? -1.0 -10.0M -3.0 - double? 1.0 10.0M -3.0 - double? 1.0 10.0 3.0M - double? -1.0 -10.0 3.0M - double? -1.0 -10.0 -3.0M - double? 1.0 10.0 -3.0M + ;; Unexpectedly downconverts result to double, rather than BigDecimal + double? 1.0 10.0M 3.0 + double? -1.0 -10.0M 3.0 + double? -1.0 -10.0M -3.0 + double? 1.0 10.0M -3.0 + double? 1.0 10.0 3.0M + double? -1.0 -10.0 3.0M + double? -1.0 -10.0 -3.0M + double? 1.0 10.0 -3.0M - p/big-int? 0N 3 1/2 - ratio? 1/3 3 4/3 - ratio? 7/2 37/2 15 - p/big-int? 0N 3 -1/2 - ratio? 1/3 3 -4/3 - ratio? 7/2 37/2 -15 - p/big-int? 0N -3 1/2 - ratio? -1/3 -3 4/3 - ratio? -7/2 -37/2 15 - p/big-int? 0N -3 -1/2 - ratio? -1/3 -3 -4/3 - ratio? -7/2 -37/2 -15) + p/big-int? 0N 3 1/2 + ratio? 1/3 3 4/3 + ratio? 7/2 37/2 15 + p/big-int? 0N 3 -1/2 + ratio? 1/3 3 -4/3 + ratio? 7/2 37/2 -15 + p/big-int? 0N -3 1/2 + ratio? -1/3 -3 4/3 + ratio? -7/2 -37/2 15 + p/big-int? 0N -3 -1/2 + ratio? -1/3 -3 -4/3 + ratio? -7/2 -37/2 -15) - (is (thrown? Exception (rem 10 0))) - (is (thrown? Exception (rem ##Inf 1))) ; surprising since (/ ##Inf 1) = ##Inf - (is (NaN? (rem 1 ##Inf))) - (is (thrown? Exception (rem ##-Inf 1))) ; surprising since (/ ##-Inf 1) = ##-Inf - (is (NaN? (rem 1 ##-Inf))) - (is (thrown? Exception (rem ##NaN 1))) - (is (thrown? Exception (rem 1 ##NaN))) - (is (thrown? Exception (rem ##NaN 1)))) + (is (thrown? Exception (rem 10 0))) + (is (thrown? Exception (rem ##Inf 1))) ; surprising since (/ ##Inf 1) = ##Inf + (is (NaN? (rem 1 ##Inf))) + (is (thrown? Exception (rem ##-Inf 1))) ; surprising since (/ ##-Inf 1) = ##-Inf + (is (NaN? (rem 1 ##-Inf))) + (is (thrown? Exception (rem ##NaN 1))) + (is (thrown? Exception (rem 1 ##NaN))) + (is (thrown? Exception (rem ##NaN 1))))) diff --git a/test/clojure/core_test/seq.cljc b/test/clojure/core_test/seq.cljc index 3b76227f..204be0fb 100644 --- a/test/clojure/core_test/seq.cljc +++ b/test/clojure/core_test/seq.cljc @@ -1,34 +1,36 @@ (ns clojure.core-test.seq - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-seq - ;; Sourced via canSeq https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L581 - (are [in expected] (= expected (seq in)) - "test" '(\t \e \s \t) - [1 2 3 4] '(1 2 3 4) - '(:a :b :c :d) '(:a :b :c :d) - '() nil - nil nil - (sorted-set 3.0 1.0 -2.5 4.0) '(-2.5 1.0 3.0 4.0) - (range 5 10) '(5 6 7 8 9) - (int-array 3) '(0 0 0)) - (testing "sets and maps" - (let [input #{440M 55000M 80000} - input-hash (into (hash-set) input) - input-map {:a {:b "4"} - :c 800 - nil 40} - input-sorted-map (into (sorted-map) input-map) - input-hash-map (into (hash-map) input-map)] - (is (= input (into #{} (seq input)))) - (is (= input-hash (into (hash-set) (seq input)))) - (is (= input-sorted-map (into (sorted-map) (seq input-sorted-map)))) - (is (= input-hash-map (into (hash-map) (seq input-hash-map)))) - (is (= input-map (into {} (seq input-map)))))) - (testing "nonseqables" - (is (thrown? IllegalArgumentException (seq 1))) - (is (thrown? IllegalArgumentException (seq (fn []))))) - (testing "infinite sequences are produced by seq" - (let [infinite-seq (seq (range))] - (is (seq? infinite-seq)) - (is (= (range 10000) (take 10000 infinite-seq)))))) +(p/when-var-exists clojure.core/seq + (deftest test-seq + ;; Sourced via canSeq https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L581 + (are [in expected] (= expected (seq in)) + "test" '(\t \e \s \t) + [1 2 3 4] '(1 2 3 4) + '(:a :b :c :d) '(:a :b :c :d) + '() nil + nil nil + (sorted-set 3.0 1.0 -2.5 4.0) '(-2.5 1.0 3.0 4.0) + (range 5 10) '(5 6 7 8 9) + (int-array 3) '(0 0 0)) + (testing "sets and maps" + (let [input #{440M 55000M 80000} + input-hash (into (hash-set) input) + input-map {:a {:b "4"} + :c 800 + nil 40} + input-sorted-map (into (sorted-map) input-map) + input-hash-map (into (hash-map) input-map)] + (is (= input (into #{} (seq input)))) + (is (= input-hash (into (hash-set) (seq input)))) + (is (= input-sorted-map (into (sorted-map) (seq input-sorted-map)))) + (is (= input-hash-map (into (hash-map) (seq input-hash-map)))) + (is (= input-map (into {} (seq input-map)))))) + (testing "nonseqables" + (is (thrown? IllegalArgumentException (seq 1))) + (is (thrown? IllegalArgumentException (seq (fn []))))) + (testing "infinite sequences are produced by seq" + (let [infinite-seq (seq (range))] + (is (seq? infinite-seq)) + (is (= (range 10000) (take 10000 infinite-seq))))))) diff --git a/test/clojure/core_test/short.cljc b/test/clojure/core_test/short.cljc index 05530b92..35c335fc 100644 --- a/test/clojure/core_test/short.cljc +++ b/test/clojure/core_test/short.cljc @@ -1,46 +1,47 @@ (ns clojure.core-test.short - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-short - ;; There is no platform independent predicate to test for a - ;; short (e.g., `short?`). In ClojureJVM, it's an instance of - ;; `java.lang.Short`, but there is no predicate for it. Here, we just - ;; test whether it's a fixed-length integer of some sort. - (is (int? (short 0))) - #?@(:cljs nil - :default - [(is (instance? java.lang.Short (short 0)))]) +(p/when-var-exists clojure.core/short + (deftest test-short + ;; There is no platform independent predicate to test for a + ;; short (e.g., `short?`). In ClojureJVM, it's an instance of + ;; `java.lang.Short`, but there is no predicate for it. Here, we just + ;; test whether it's a fixed-length integer of some sort. + (is (int? (short 0))) + #?@(:cljs nil + :default + [(is (instance? java.lang.Short (short 0)))]) - ;; Check conversions and rounding from other numeric types - (are [expected x] (= expected (short x)) - -32768 -32768 - 0 0 - 32767 32767 - 1 1N - 0 0N - -1 -1N - 1 1.0M - 0 0.0M - -1 -1.0M - 1 1.1 - -1 -1.1 - 1 1.9 - 1 3/2 - -1 -3/2 - 0 1/10 - 0 -1/10 - 1 1.1M - -1 -1.1M) + ;; Check conversions and rounding from other numeric types + (are [expected x] (= expected (short x)) + -32768 -32768 + 0 0 + 32767 32767 + 1 1N + 0 0N + -1 -1N + 1 1.0M + 0 0.0M + -1 -1.0M + 1 1.1 + -1 -1.1 + 1 1.9 + 1 3/2 + -1 -3/2 + 0 1/10 + 0 -1/10 + 1 1.1M + -1 -1.1M) - ;; `short` throws outside the range of 32767 ... -32768. - (is (thrown? IllegalArgumentException (short -32768.000001))) - (is (thrown? IllegalArgumentException (short -32769))) - (is (thrown? IllegalArgumentException (short 32768))) - (is (thrown? IllegalArgumentException (short 32767.000001))) - - ;; Check handling of other types - (is (thrown? ClassCastException (short "0"))) - (is (thrown? ClassCastException (short :0))) - (is (thrown? ClassCastException (short [0]))) - (is (thrown? Exception (short nil)))) + ;; `short` throws outside the range of 32767 ... -32768. + (is (thrown? IllegalArgumentException (short -32768.000001))) + (is (thrown? IllegalArgumentException (short -32769))) + (is (thrown? IllegalArgumentException (short 32768))) + (is (thrown? IllegalArgumentException (short 32767.000001))) + ;; Check handling of other types + (is (thrown? ClassCastException (short "0"))) + (is (thrown? ClassCastException (short :0))) + (is (thrown? ClassCastException (short [0]))) + (is (thrown? Exception (short nil))))) diff --git a/test/clojure/core_test/simple_ident_questionmark.cljc b/test/clojure/core_test/simple_ident_questionmark.cljc index a99bd31a..e2c383ce 100644 --- a/test/clojure/core_test/simple_ident_questionmark.cljc +++ b/test/clojure/core_test/simple_ident_questionmark.cljc @@ -1,18 +1,20 @@ (ns clojure.core-test.simple-ident-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-simple-ident? - (are [expected x] (= expected (simple-ident? x)) - true :a-keyword - true 'a-symbol - false :a-ns/a-keyword - false 'a-ns/a-keyword - false "a string" - false 0 - false 0N - false 0.0 - false 1/2 - false 0.0M - false false - false true - false nil)) +(p/when-var-exists clojure.core/simple-ident? + (deftest test-simple-ident? + (are [expected x] (= expected (simple-ident? x)) + true :a-keyword + true 'a-symbol + false :a-ns/a-keyword + false 'a-ns/a-keyword + false "a string" + false 0 + false 0N + false 0.0 + false 1/2 + false 0.0M + false false + false true + false nil))) diff --git a/test/clojure/core_test/simple_keyword_questionmark.cljc b/test/clojure/core_test/simple_keyword_questionmark.cljc index b4597b6d..81490678 100644 --- a/test/clojure/core_test/simple_keyword_questionmark.cljc +++ b/test/clojure/core_test/simple_keyword_questionmark.cljc @@ -1,18 +1,20 @@ (ns clojure.core-test.simple-keyword-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-simple-keyword? - (are [expected x] (= expected (simple-keyword? x)) - true :a-keyword - false 'a-symbol - false :a-ns/a-keyword - false 'a-ns/a-keyword - false "a string" - false 0 - false 0N - false 0.0 - false 1/2 - false 0.0M - false false - false true - false nil)) +(p/when-var-exists clojure.core/simple-keyword? + (deftest test-simple-keyword? + (are [expected x] (= expected (simple-keyword? x)) + true :a-keyword + false 'a-symbol + false :a-ns/a-keyword + false 'a-ns/a-keyword + false "a string" + false 0 + false 0N + false 0.0 + false 1/2 + false 0.0M + false false + false true + false nil))) diff --git a/test/clojure/core_test/simple_symbol_questionmark.cljc b/test/clojure/core_test/simple_symbol_questionmark.cljc index 000e73fb..f43c3ace 100644 --- a/test/clojure/core_test/simple_symbol_questionmark.cljc +++ b/test/clojure/core_test/simple_symbol_questionmark.cljc @@ -1,18 +1,20 @@ (ns clojure.core-test.simple-symbol-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-simple-symbol? - (are [expected x] (= expected (simple-symbol? x)) - false :a-keyword - true 'a-symbol - false :a-ns/a-keyword - false 'a-ns/a-keyword - false "a string" - false 0 - false 0N - false 0.0 - false 1/2 - false 0.0M - false false - false true - false nil)) +(p/when-var-exists clojure.core/simple-symbol? + (deftest test-simple-symbol? + (are [expected x] (= expected (simple-symbol? x)) + false :a-keyword + true 'a-symbol + false :a-ns/a-keyword + false 'a-ns/a-keyword + false "a string" + false 0 + false 0N + false 0.0 + false 1/2 + false 0.0M + false false + false true + false nil))) diff --git a/test/clojure/core_test/slash.cljc b/test/clojure/core_test/slash.cljc index 39592504..43ee0604 100644 --- a/test/clojure/core_test/slash.cljc +++ b/test/clojure/core_test/slash.cljc @@ -1,207 +1,210 @@ (ns clojure.core-test.slash - (:require [clojure.test :as t :refer [deftest testing is are]])) - -(deftest common - (are [expected x y] (= expected (/ x y)) - 2 2 1 - 1 2 2 - 3 15 5 - 5 15 3 - - 2 2N 1N - 1 2N 2N - 3 15N 5N - 5 15N 3N - - 2 2 1N - 1 2 2N - 3 15 5N - 5 15 3N - - 2 2N 1 - 1 2N 2 - 3 15N 5 - 5 15N 3 - - 2.0 2.0 1.0 - 1.0 2.0 2.0 - 3.0 15.0 5.0 - 5.0 15.0 3.0 - 7.5 15.0 2.0 - - 2.0 2 1.0 - 1.0 2 2.0 - 3.0 15 5.0 - 5.0 15 3.0 - 7.5 15 2.0 - - 2.0 2.0 1 - 1.0 2.0 2 - 3.0 15.0 5 - 5.0 15.0 3 - 7.5 15.0 2 - - 2.0 2.0M 1.0 ; Unexpected downcast to double - 1.0 2.0M 2.0 - 3.0 15.0M 5.0 - 5.0 15.0M 3.0 - 7.5 15.0M 2.0 - - 2.0 2.0 1.0M ; Unexpected downcast to double - 1.0 2.0 2.0M - 3.0 15.0 5.0M - 5.0 15.0 3.0M - 7.5 15.0 2.0M - - 2.0M 2.0M 1.0M - 1.0M 2.0M 2.0M - 3.0M 15.0M 5.0M - 5.0M 15.0M 3.0M - 7.5M 15.0M 2.0M - - 2.0M 2 1.0M - 1.0M 2 2.0M - 3.0M 15 5.0M - 5.0M 15 3.0M - 7.5M 15 2.0M - - 2.0M 2.0M 1 - 1.0M 2.0M 2 - 3.0M 15.0M 5 - 5.0M 15.0M 3 - 7.5M 15.0M 2 - - 2.0 2N 1.0 - 1.0 2N 2.0 - 3.0 15N 5.0 - 5.0 15N 3.0 - 7.5 15N 2.0 - - 2.0 2.0 1N - 1.0 2.0 2N - 3.0 15.0 5N - 5.0 15.0 3N - 7.5 15.0 2N - - 2.0M 2N 1.0M - 1.0M 2N 2.0M - 3.0M 15N 5.0M - 5.0M 15N 3.0M - 7.5M 15N 2.0M - - 2.0M 2.0M 1N - 1.0M 2.0M 2N - 3.0M 15.0M 5N - 5.0M 15.0M 3N - 7.5M 15.0M 2N - - ;; test signs - -1 1 -1 - -1 -1 1 - 1 -1 -1 - -1.0 1.0 -1.0 - -1.0 -1.0 1.0 - 1.0 -1.0 -1.0 - -1N 1N -1N - -1N -1N 1N - 1N -1N -1N - -1.0M 1.0M -1.0M - -1.0M -1.0M 1.0M - 1.0M -1.0M -1.0M) - - ;; Zero arg - (is (thrown? Exception (/))) - - ;; Single arg - (is (= 1/2 (/ 2))) - (is (= 0.5 (/ 2.0))) - - ;; Multi arg - (is (= 1/362880 (/ 1 2 3 4 5 6 7 8 9))) - - (is (thrown? Exception (/ 1 0))) - (is (thrown? Exception (/ nil 1))) - (is (thrown? Exception (/ 1 nil)))) - -(deftest rationals - (are [expected x y] (= expected (/ x y)) - 10 10 1 - 5 10 2 - 10/3 10 3 - 1 2 2 - 4 2 1/2 - 1/4 1/2 2 - 4.0 2.0 1/2 - 0.25 1/2 2.0 - 4M 2.0M 1/2 - 0.25M 1/2 2.0M) - - ;; Single arg - (is (= 2N (/ 1/2))) - (is (= 3N (/ 1/3))) - - ;; Multi arg - (is (= 362880N (/ 1/1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9))) - - (is (thrown? Exception (/ 1/2 nil))) - (is (thrown? Exception (/ nil 1/2)))) - -(deftest inf-nan - (are [expected x y] (= expected (/ x y)) - ##Inf ##Inf 1 - ##-Inf ##-Inf 1 - 0.0 1 ##Inf ; Note conversion to double - 0.0 1 ##-Inf - 0.0 -1 ##Inf - 0.0 -1 ##-Inf - ##Inf ##Inf 0 ; Surprisingly, these down't throw - ##-Inf ##-Inf 0 - - ##Inf ##Inf 1N - ##-Inf ##-Inf 1N - 0.0 1N ##Inf ; Note conversion to double - 0.0 1N ##-Inf - 0.0 -1N ##Inf - 0.0 -1N ##-Inf - ##Inf ##Inf 0N ; Surprisingly, these down't throw - ##-Inf ##-Inf 0N - - ##Inf ##Inf 1.0 - ##-Inf ##-Inf 1.0 - 0.0 1.0 ##Inf - 0.0 1.0 ##-Inf - 0.0 -1.0 ##Inf - 0.0 -1.0 ##-Inf - ##Inf ##Inf 0.0 ; Surprisingly, these down't throw - ##-Inf ##-Inf 0.0 - - ##Inf ##Inf 1.0M - ##-Inf ##-Inf 1.0M - 0.0 1.0M ##Inf ; Note conversion back double - 0.0 1.0M ##-Inf - 0.0 -1.0M ##Inf - 0.0 -1.0M ##-Inf - ##Inf ##Inf 0.0M ; Surprisingly, these down't throw - ##-Inf ##-Inf 0.0M - - 0.0 1/2 ##Inf - 0.0 -1/2 ##Inf - 0.0 1/2 ##-Inf - 0.0 -1/2 ##-Inf) - - ;; These all result in ##NaN, but we can't test for that with `=`. - (are [x y] (NaN? (/ x y)) - ##NaN 0 ; Note that this doesn't throw - 0 ##NaN - ##NaN 0N - 0N ##NaN - ##NaN 1.0 - 1.0 ##NaN - ##NaN 1.0M - 1.0M ##NaN - ##NaN 1/2 - 1/2 ##NaN - ##Inf ##Inf - ##Inf ##-Inf - ##-Inf ##Inf - ##-Inf ##-Inf)) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) + +(p/when-var-exists clojure.core// + (deftest test-slash + (testing "common" + (are [expected x y] (= expected (/ x y)) + 2 2 1 + 1 2 2 + 3 15 5 + 5 15 3 + + 2 2N 1N + 1 2N 2N + 3 15N 5N + 5 15N 3N + + 2 2 1N + 1 2 2N + 3 15 5N + 5 15 3N + + 2 2N 1 + 1 2N 2 + 3 15N 5 + 5 15N 3 + + 2.0 2.0 1.0 + 1.0 2.0 2.0 + 3.0 15.0 5.0 + 5.0 15.0 3.0 + 7.5 15.0 2.0 + + 2.0 2 1.0 + 1.0 2 2.0 + 3.0 15 5.0 + 5.0 15 3.0 + 7.5 15 2.0 + + 2.0 2.0 1 + 1.0 2.0 2 + 3.0 15.0 5 + 5.0 15.0 3 + 7.5 15.0 2 + + 2.0 2.0M 1.0 ; Unexpected downcast to double + 1.0 2.0M 2.0 + 3.0 15.0M 5.0 + 5.0 15.0M 3.0 + 7.5 15.0M 2.0 + + 2.0 2.0 1.0M ; Unexpected downcast to double + 1.0 2.0 2.0M + 3.0 15.0 5.0M + 5.0 15.0 3.0M + 7.5 15.0 2.0M + + 2.0M 2.0M 1.0M + 1.0M 2.0M 2.0M + 3.0M 15.0M 5.0M + 5.0M 15.0M 3.0M + 7.5M 15.0M 2.0M + + 2.0M 2 1.0M + 1.0M 2 2.0M + 3.0M 15 5.0M + 5.0M 15 3.0M + 7.5M 15 2.0M + + 2.0M 2.0M 1 + 1.0M 2.0M 2 + 3.0M 15.0M 5 + 5.0M 15.0M 3 + 7.5M 15.0M 2 + + 2.0 2N 1.0 + 1.0 2N 2.0 + 3.0 15N 5.0 + 5.0 15N 3.0 + 7.5 15N 2.0 + + 2.0 2.0 1N + 1.0 2.0 2N + 3.0 15.0 5N + 5.0 15.0 3N + 7.5 15.0 2N + + 2.0M 2N 1.0M + 1.0M 2N 2.0M + 3.0M 15N 5.0M + 5.0M 15N 3.0M + 7.5M 15N 2.0M + + 2.0M 2.0M 1N + 1.0M 2.0M 2N + 3.0M 15.0M 5N + 5.0M 15.0M 3N + 7.5M 15.0M 2N + + ;; test signs + -1 1 -1 + -1 -1 1 + 1 -1 -1 + -1.0 1.0 -1.0 + -1.0 -1.0 1.0 + 1.0 -1.0 -1.0 + -1N 1N -1N + -1N -1N 1N + 1N -1N -1N + -1.0M 1.0M -1.0M + -1.0M -1.0M 1.0M + 1.0M -1.0M -1.0M) + + ;; Zero arg + (is (thrown? Exception (/))) + + ;; Single arg + (is (= 1/2 (/ 2))) + (is (= 0.5 (/ 2.0))) + + ;; Multi arg + (is (= 1/362880 (/ 1 2 3 4 5 6 7 8 9))) + + (is (thrown? Exception (/ 1 0))) + (is (thrown? Exception (/ nil 1))) + (is (thrown? Exception (/ 1 nil)))) + + (testing "rationals" + (are [expected x y] (= expected (/ x y)) + 10 10 1 + 5 10 2 + 10/3 10 3 + 1 2 2 + 4 2 1/2 + 1/4 1/2 2 + 4.0 2.0 1/2 + 0.25 1/2 2.0 + 4M 2.0M 1/2 + 0.25M 1/2 2.0M) + + ;; Single arg + (is (= 2N (/ 1/2))) + (is (= 3N (/ 1/3))) + + ;; Multi arg + (is (= 362880N (/ 1/1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9))) + + (is (thrown? Exception (/ 1/2 nil))) + (is (thrown? Exception (/ nil 1/2)))) + + (testing "inf-nan" + (are [expected x y] (= expected (/ x y)) + ##Inf ##Inf 1 + ##-Inf ##-Inf 1 + 0.0 1 ##Inf ; Note conversion to double + 0.0 1 ##-Inf + 0.0 -1 ##Inf + 0.0 -1 ##-Inf + ##Inf ##Inf 0 ; Surprisingly, these down't throw + ##-Inf ##-Inf 0 + + ##Inf ##Inf 1N + ##-Inf ##-Inf 1N + 0.0 1N ##Inf ; Note conversion to double + 0.0 1N ##-Inf + 0.0 -1N ##Inf + 0.0 -1N ##-Inf + ##Inf ##Inf 0N ; Surprisingly, these down't throw + ##-Inf ##-Inf 0N + + ##Inf ##Inf 1.0 + ##-Inf ##-Inf 1.0 + 0.0 1.0 ##Inf + 0.0 1.0 ##-Inf + 0.0 -1.0 ##Inf + 0.0 -1.0 ##-Inf + ##Inf ##Inf 0.0 ; Surprisingly, these down't throw + ##-Inf ##-Inf 0.0 + + ##Inf ##Inf 1.0M + ##-Inf ##-Inf 1.0M + 0.0 1.0M ##Inf ; Note conversion back double + 0.0 1.0M ##-Inf + 0.0 -1.0M ##Inf + 0.0 -1.0M ##-Inf + ##Inf ##Inf 0.0M ; Surprisingly, these down't throw + ##-Inf ##-Inf 0.0M + + 0.0 1/2 ##Inf + 0.0 -1/2 ##Inf + 0.0 1/2 ##-Inf + 0.0 -1/2 ##-Inf) + + ;; These all result in ##NaN, but we can't test for that with `=`. + (are [x y] (NaN? (/ x y)) + ##NaN 0 ; Note that this doesn't throw + 0 ##NaN + ##NaN 0N + 0N ##NaN + ##NaN 1.0 + 1.0 ##NaN + ##NaN 1.0M + 1.0M ##NaN + ##NaN 1/2 + 1/2 ##NaN + ##Inf ##Inf + ##Inf ##-Inf + ##-Inf ##Inf + ##-Inf ##-Inf)))) diff --git a/test/clojure/core_test/some_q.cljc b/test/clojure/core_test/some_q.cljc deleted file mode 100644 index a0874f89..00000000 --- a/test/clojure/core_test/some_q.cljc +++ /dev/null @@ -1,15 +0,0 @@ -(ns clojure.core-test.some-q - (:require - [clojure.test :as t])) - -(t/deftest common - (t/are [given expected] (= expected (some? given)) - nil false - true true - false true - #?(:clj (Object.) - :cljs #js {} - :default :anything) true)) - -(t/deftest infinite-sequence - (t/is (= true (some? (range))))) diff --git a/test/clojure/core_test/some_questionmark.cljc b/test/clojure/core_test/some_questionmark.cljc new file mode 100644 index 00000000..8033e53b --- /dev/null +++ b/test/clojure/core_test/some_questionmark.cljc @@ -0,0 +1,18 @@ +(ns clojure.core-test.some-questionmark + (:require + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) + +(p/when-var-exists clojure.core/some? + (deftest test-some? + (testing "common" + (are [given expected] (= expected (some? given)) + nil false + true true + false true + #?(:clj (Object.) + :cljs #js {} + :default :anything) true)) + + (testing "infinite-sequence" + (is (= true (some? (range))))))) diff --git a/test/clojure/core_test/star.cljc b/test/clojure/core_test/star.cljc index 5e507293..8775e647 100644 --- a/test/clojure/core_test/star.cljc +++ b/test/clojure/core_test/star.cljc @@ -1,160 +1,162 @@ (ns clojure.core-test.star (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) - -(deftest common - (are [prod x y] (= prod (* x y) (* y x)) - 0 0 0 - 0 0 1 - 1 1 1 - 5 1 5 - 25 5 5 - -1 1 -1 - 1 -1 -1 - 0 0 -1 - (inc r/min-int) r/max-int -1 - - 0.0 0.0 0.0 - 0.0 0.0 1.0 - 1.0 1.0 1.0 - 5.0 1.0 5.0 - 25.0 5.0 5.0 - -1.0 1.0 -1.0 - 1.0 -1.0 -1.0 - 0.0 0.0 -1.0 - - 0.0 0.0 0 - 0.0 1.0 0 - 0.0 0.0 1 - 1.0 1.0 1 - 5.0 1.0 5 - 5.0 5.0 1 - 25.0 5.0 5 - -1.0 1.0 -1 - -1.0 -1.0 1 - 1.0 -1.0 -1 - 0.0 -1.0 0 - 0.0 0.0 -1 - - 0.0 0 0.0 - 0.0 1 0.0 - 0.0 0 1.0 - 1.0 1 1.0 - 5.0 1 5.0 - 5.0 5 1.0 - 25.0 5 5.0 - -1.0 1 -1.0 - -1.0 -1 1.0 - 1.0 -1 -1.0 - 0.0 -1 0.0 - 0.0 0 -1.0 - - 0 0 1N - 0 0N 1 - 0 0N 1N - 1 1N 1 - 1 1 1N - 1 1N 1N - 5 1 5N - 5 1N 5 - 5 1N 5N) - - ;; Zero arg - (is (= 1 (*))) - - ;; One arg - (is (= 1 (* 1))) - (is (= 2 (* 2))) - - ;; Multi arg - (is (= 362880 (* 1 2 3 4 5 6 7 8 9))) - - (is (thrown? Exception (* 1 nil))) - (is (thrown? Exception (* nil 1))) - - #?@(:cljs nil - :default - [(is (instance? clojure.lang.BigInt (* 0 1N))) - (is (instance? clojure.lang.BigInt (* 0N 1))) - (is (instance? clojure.lang.BigInt (* 0N 1N))) - (is (instance? clojure.lang.BigInt (* 1N 1))) - (is (instance? clojure.lang.BigInt (* 1 1N))) - (is (instance? clojure.lang.BigInt (* 1N 1N))) - (is (instance? clojure.lang.BigInt (* 1 5N))) - (is (instance? clojure.lang.BigInt (* 1N 5))) - (is (instance? clojure.lang.BigInt (* 1N 5N))) - - (is (thrown? Exception (* -1 r/min-int))) - (is (thrown? Exception (* r/min-int -1))) - (is (thrown? Exception (* (long (/ r/min-int 2)) 3))) - (is (thrown? Exception (* 3 (long (/ r/min-int 2)))))])) - -(deftest rationals - (are [prod x y] (= prod (* x y) (* y x)) - 1 1/2 2/1 - 1 1/2 2 - -1 1/2 -2 - -1 -1/2 2 - 1 -1/2 -2 - 1.0 1/2 2.0 - -1.0 1/2 -2.0 - -1.0 -1/2 2.0 - 1.0 -1/2 -2.0 - 1 1/2 2N - -1 1/2 -2N - -1 -1/2 2N - 1 -1/2 -2N - 1.0 1/3 3.0 - 0 1/2 0 - 0.0 1/2 0.0 - 0 1/2 0N - 1/10 1/2 1/5 - -1/10 1/2 -1/5 - -1/10 -1/2 1/5 - 1/10 -1/2 -1/5) - - (is (thrown? Exception (* 1/2 nil))) - (is (thrown? Exception (* nil 1/2)))) - -(deftest inf-nan - (testing "Multiplication with infinities" - (are [prod x y] (= prod (* x y) (* y x)) - ##Inf ##Inf 1 - ##Inf ##Inf 1N - ##Inf ##Inf 1.0 - ##Inf ##Inf 1/2 - ##Inf ##Inf 2 - ##-Inf ##Inf -1 - ##-Inf ##Inf -1N - ##-Inf ##Inf -1.0 - ##-Inf ##Inf -1/2 - ##-Inf ##-Inf 1 - ##-Inf ##-Inf 1N - ##-Inf ##-Inf 1.0 - ##-Inf ##-Inf 1/2 - ##Inf ##-Inf -1 - ##Inf ##-Inf -1N - ##Inf ##-Inf -1.0 - ##Inf ##-Inf -1/2 - ##Inf ##Inf 2 - ##Inf ##Inf ##Inf - ##-Inf ##Inf ##-Inf - ##-Inf ##-Inf ##Inf - ##Inf ##-Inf ##-Inf - ##Inf ##Inf r/max-int - ##-Inf ##Inf r/min-int - ##Inf ##Inf r/max-double - ##Inf ##Inf r/min-double)) - - (testing "Multiplication resulting in ##NaN" - (are [x y] (and (NaN? (* x y)) - (NaN? (* y x))) - ##Inf 0 ; Perhaps counter-intuitive - ##Inf 0N - ##Inf 0.0 - ##Inf 0/2 - ##NaN 1 - ##NaN 1N - ##NaN 1.0 - ##NaN 1/2))) - + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) + +(p/when-var-exists clojure.core/* + (deftest test-* + (testing "common" + (are [prod x y] (= prod (* x y) (* y x)) + 0 0 0 + 0 0 1 + 1 1 1 + 5 1 5 + 25 5 5 + -1 1 -1 + 1 -1 -1 + 0 0 -1 + (inc r/min-int) r/max-int -1 + + 0.0 0.0 0.0 + 0.0 0.0 1.0 + 1.0 1.0 1.0 + 5.0 1.0 5.0 + 25.0 5.0 5.0 + -1.0 1.0 -1.0 + 1.0 -1.0 -1.0 + 0.0 0.0 -1.0 + + 0.0 0.0 0 + 0.0 1.0 0 + 0.0 0.0 1 + 1.0 1.0 1 + 5.0 1.0 5 + 5.0 5.0 1 + 25.0 5.0 5 + -1.0 1.0 -1 + -1.0 -1.0 1 + 1.0 -1.0 -1 + 0.0 -1.0 0 + 0.0 0.0 -1 + + 0.0 0 0.0 + 0.0 1 0.0 + 0.0 0 1.0 + 1.0 1 1.0 + 5.0 1 5.0 + 5.0 5 1.0 + 25.0 5 5.0 + -1.0 1 -1.0 + -1.0 -1 1.0 + 1.0 -1 -1.0 + 0.0 -1 0.0 + 0.0 0 -1.0 + + 0 0 1N + 0 0N 1 + 0 0N 1N + 1 1N 1 + 1 1 1N + 1 1N 1N + 5 1 5N + 5 1N 5 + 5 1N 5N) + + ;; Zero arg + (is (= 1 (*))) + + ;; One arg + (is (= 1 (* 1))) + (is (= 2 (* 2))) + + ;; Multi arg + (is (= 362880 (* 1 2 3 4 5 6 7 8 9))) + + (is (thrown? Exception (* 1 nil))) + (is (thrown? Exception (* nil 1))) + + #?@(:cljs nil + :default + [(is (instance? clojure.lang.BigInt (* 0 1N))) + (is (instance? clojure.lang.BigInt (* 0N 1))) + (is (instance? clojure.lang.BigInt (* 0N 1N))) + (is (instance? clojure.lang.BigInt (* 1N 1))) + (is (instance? clojure.lang.BigInt (* 1 1N))) + (is (instance? clojure.lang.BigInt (* 1N 1N))) + (is (instance? clojure.lang.BigInt (* 1 5N))) + (is (instance? clojure.lang.BigInt (* 1N 5))) + (is (instance? clojure.lang.BigInt (* 1N 5N))) + + (is (thrown? Exception (* -1 r/min-int))) + (is (thrown? Exception (* r/min-int -1))) + (is (thrown? Exception (* (long (/ r/min-int 2)) 3))) + (is (thrown? Exception (* 3 (long (/ r/min-int 2)))))])) + + (testing "rationals" + (are [prod x y] (= prod (* x y) (* y x)) + 1 1/2 2/1 + 1 1/2 2 + -1 1/2 -2 + -1 -1/2 2 + 1 -1/2 -2 + 1.0 1/2 2.0 + -1.0 1/2 -2.0 + -1.0 -1/2 2.0 + 1.0 -1/2 -2.0 + 1 1/2 2N + -1 1/2 -2N + -1 -1/2 2N + 1 -1/2 -2N + 1.0 1/3 3.0 + 0 1/2 0 + 0.0 1/2 0.0 + 0 1/2 0N + 1/10 1/2 1/5 + -1/10 1/2 -1/5 + -1/10 -1/2 1/5 + 1/10 -1/2 -1/5) + + (is (thrown? Exception (* 1/2 nil))) + (is (thrown? Exception (* nil 1/2)))) + + (testing "inf-nan" + (testing "Multiplication with infinities" + (are [prod x y] (= prod (* x y) (* y x)) + ##Inf ##Inf 1 + ##Inf ##Inf 1N + ##Inf ##Inf 1.0 + ##Inf ##Inf 1/2 + ##Inf ##Inf 2 + ##-Inf ##Inf -1 + ##-Inf ##Inf -1N + ##-Inf ##Inf -1.0 + ##-Inf ##Inf -1/2 + ##-Inf ##-Inf 1 + ##-Inf ##-Inf 1N + ##-Inf ##-Inf 1.0 + ##-Inf ##-Inf 1/2 + ##Inf ##-Inf -1 + ##Inf ##-Inf -1N + ##Inf ##-Inf -1.0 + ##Inf ##-Inf -1/2 + ##Inf ##Inf 2 + ##Inf ##Inf ##Inf + ##-Inf ##Inf ##-Inf + ##-Inf ##-Inf ##Inf + ##Inf ##-Inf ##-Inf + ##Inf ##Inf r/max-int + ##-Inf ##Inf r/min-int + ##Inf ##Inf r/max-double + ##Inf ##Inf r/min-double)) + + (testing "Multiplication resulting in ##NaN" + (are [x y] (and (NaN? (* x y)) + (NaN? (* y x))) + ##Inf 0 ; Perhaps counter-intuitive + ##Inf 0N + ##Inf 0.0 + ##Inf 0/2 + ##NaN 1 + ##NaN 1N + ##NaN 1.0 + ##NaN 1/2))))) diff --git a/test/clojure/core_test/star_singlequote.cljc b/test/clojure/core_test/star_singlequote.cljc index d847ff22..c3f51282 100644 --- a/test/clojure/core_test/star_singlequote.cljc +++ b/test/clojure/core_test/star_singlequote.cljc @@ -1,90 +1,89 @@ (ns clojure.core-test.star-singlequote - (:require [clojure.test :as t :refer [is are]] - [clojure.core-test.number-range :as r])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -#?(:cljs nil - :default - (t/deftest common - (are [prod cand er] (= prod (*' cand er)) - 0 0 0 - 0 1 0 - 0 0 1 - 1 1 1 - 5 1 5 - 5 5 1 - 25 5 5 - -1 1 -1 - -1 -1 1 - 1 -1 -1 - 0 -1 0 - 0 0 -1 - (inc r/min-int) r/max-int -1 - (inc r/min-int) -1 r/max-int +(p/when-var-exists clojure.core/*' + (deftest test-*' + (are [prod cand er] (= prod (*' cand er)) + 0 0 0 + 0 1 0 + 0 0 1 + 1 1 1 + 5 1 5 + 5 5 1 + 25 5 5 + -1 1 -1 + -1 -1 1 + 1 -1 -1 + 0 -1 0 + 0 0 -1 + (inc r/min-int) r/max-int -1 + (inc r/min-int) -1 r/max-int - 0.0 0.0 0.0 - 0.0 1.0 0.0 - 0.0 0.0 1.0 - 1.0 1.0 1.0 - 5.0 1.0 5.0 - 5.0 5.0 1.0 - 25.0 5.0 5.0 - -1.0 1.0 -1.0 - -1.0 -1.0 1.0 - 1.0 -1.0 -1.0 - 0.0 -1.0 0.0 - 0.0 0.0 -1.0 + 0.0 0.0 0.0 + 0.0 1.0 0.0 + 0.0 0.0 1.0 + 1.0 1.0 1.0 + 5.0 1.0 5.0 + 5.0 5.0 1.0 + 25.0 5.0 5.0 + -1.0 1.0 -1.0 + -1.0 -1.0 1.0 + 1.0 -1.0 -1.0 + 0.0 -1.0 0.0 + 0.0 0.0 -1.0 - 0.0 0.0 0 - 0.0 1.0 0 - 0.0 0.0 1 - 1.0 1.0 1 - 5.0 1.0 5 - 5.0 5.0 1 - 25.0 5.0 5 - -1.0 1.0 -1 - -1.0 -1.0 1 - 1.0 -1.0 -1 - 0.0 -1.0 0 - 0.0 0.0 -1 + 0.0 0.0 0 + 0.0 1.0 0 + 0.0 0.0 1 + 1.0 1.0 1 + 5.0 1.0 5 + 5.0 5.0 1 + 25.0 5.0 5 + -1.0 1.0 -1 + -1.0 -1.0 1 + 1.0 -1.0 -1 + 0.0 -1.0 0 + 0.0 0.0 -1 - 0.0 0 0.0 - 0.0 1 0.0 - 0.0 0 1.0 - 1.0 1 1.0 - 5.0 1 5.0 - 5.0 5 1.0 - 25.0 5 5.0 - -1.0 1 -1.0 - -1.0 -1 1.0 - 1.0 -1 -1.0 - 0.0 -1 0.0 - 0.0 0 -1.0 + 0.0 0 0.0 + 0.0 1 0.0 + 0.0 0 1.0 + 1.0 1 1.0 + 5.0 1 5.0 + 5.0 5 1.0 + 25.0 5 5.0 + -1.0 1 -1.0 + -1.0 -1 1.0 + 1.0 -1 -1.0 + 0.0 -1 0.0 + 0.0 0 -1.0 - 0 0 1N - 0 0N 1 - 0 0N 1N - 1 1N 1 - 1 1 1N - 1 1N 1N - 5 1 5N - 5 1N 5 - 5 1N 5N) + 0 0 1N + 0 0N 1 + 0 0N 1N + 1 1N 1 + 1 1 1N + 1 1N 1N + 5 1 5N + 5 1N 5 + 5 1N 5N) - (is (thrown? Exception (*' 1 nil))) - (is (thrown? Exception (*' nil 1))) + (is (thrown? Exception (*' 1 nil))) + (is (thrown? Exception (*' nil 1))) - (is (instance? clojure.lang.BigInt (*' 0 1N))) - (is (instance? clojure.lang.BigInt (*' 0N 1))) - (is (instance? clojure.lang.BigInt (*' 0N 1N))) - (is (instance? clojure.lang.BigInt (*' 1N 1))) - (is (instance? clojure.lang.BigInt (*' 1 1N))) - (is (instance? clojure.lang.BigInt (*' 1N 1N))) - (is (instance? clojure.lang.BigInt (*' 1 5N))) - (is (instance? clojure.lang.BigInt (*' 1N 5))) - (is (instance? clojure.lang.BigInt (*' 1N 5N))) - - (is (instance? clojure.lang.BigInt (*' -1 r/min-int))) - (is (instance? clojure.lang.BigInt (*' r/min-int -1))) - (is (instance? clojure.lang.BigInt (*' (long (/ r/min-int 2)) 3))) - (is (instance? clojure.lang.BigInt (*' 3 (long (/ r/min-int 2))))))) + (is (instance? clojure.lang.BigInt (*' 0 1N))) + (is (instance? clojure.lang.BigInt (*' 0N 1))) + (is (instance? clojure.lang.BigInt (*' 0N 1N))) + (is (instance? clojure.lang.BigInt (*' 1N 1))) + (is (instance? clojure.lang.BigInt (*' 1 1N))) + (is (instance? clojure.lang.BigInt (*' 1N 1N))) + (is (instance? clojure.lang.BigInt (*' 1 5N))) + (is (instance? clojure.lang.BigInt (*' 1N 5))) + (is (instance? clojure.lang.BigInt (*' 1N 5N))) + (is (instance? clojure.lang.BigInt (*' -1 r/min-int))) + (is (instance? clojure.lang.BigInt (*' r/min-int -1))) + (is (instance? clojure.lang.BigInt (*' (long (/ r/min-int 2)) 3))) + (is (instance? clojure.lang.BigInt (*' 3 (long (/ r/min-int 2))))))) diff --git a/test/clojure/core_test/str.cljc b/test/clojure/core_test/str.cljc index f8e4d185..510d5210 100644 --- a/test/clojure/core_test/str.cljc +++ b/test/clojure/core_test/str.cljc @@ -1,55 +1,56 @@ (ns clojure.core-test.str (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.portability :as p])) -(deftest test-str - (are [expected x] (= expected (str x)) - "0" 0 - "1" 1 - "-1" -1 - "0.0" 0.0 - "1.0" 1.0 - "-1.0" -1.0 - "0.0" 0.00000 - "0.0" (float 0.0) - "1.0" (float 1.0) - "-1.0" (float -1.0) - "0.0" (double 0.0) - "1.0" (double 1.0) - "-1.0" (double -1.0) - "Infinity" ##Inf - "-Infinity" ##-Inf - "NaN" ##NaN - "0" 0N - "1" 1N - "-1" -1N - "0" 0/2 - "1/2" 1/2 - "-1/2" -1/2 - "0.0" 0.0M - "1.0" 1.0M - "-1.0" -1.0M - "" nil - "true" true - "false" false - "a string" "a string" - "0" "0" - "1" "1" - "-1" "-1" - "{:a :map}" {:a :map} ; keep this one item because it's unordered - "#{:a-set}" #{:a-set} ; keep this one item because it's unordered - "[:a :vector]" [:a :vector] - "(:a :list)" '(:a :list) - "0" \0 - "1" \1 - "A" \A - " " \space - ":a-keyword" :a-keyword - ":0" :0 - ":1" :1 - ":-1" :-1 - "a-sym" 'a-sym) +(p/when-var-exists clojure.core/str + (deftest test-str + (are [expected x] (= expected (str x)) + "0" 0 + "1" 1 + "-1" -1 + "0.0" 0.0 + "1.0" 1.0 + "-1.0" -1.0 + "0.0" 0.00000 + "0.0" (float 0.0) + "1.0" (float 1.0) + "-1.0" (float -1.0) + "0.0" (double 0.0) + "1.0" (double 1.0) + "-1.0" (double -1.0) + "Infinity" ##Inf + "-Infinity" ##-Inf + "NaN" ##NaN + "0" 0N + "1" 1N + "-1" -1N + "0" 0/2 + "1/2" 1/2 + "-1/2" -1/2 + "0.0" 0.0M + "1.0" 1.0M + "-1.0" -1.0M + "" nil + "true" true + "false" false + "a string" "a string" + "0" "0" + "1" "1" + "-1" "-1" + "{:a :map}" {:a :map} ; keep this one item because it's unordered + "#{:a-set}" #{:a-set} ; keep this one item because it's unordered + "[:a :vector]" [:a :vector] + "(:a :list)" '(:a :list) + "0" \0 + "1" \1 + "A" \A + " " \space + ":a-keyword" :a-keyword + ":0" :0 + ":1" :1 + ":-1" :-1 + "a-sym" 'a-sym) - ;; No arg and var arg versions - (is (= "" (str))) - (is (= "astringwithnospaces" (str "a" "string" "with" "no" "spaces")))) + ;; No arg and var arg versions + (is (= "" (str))) + (is (= "astringwithnospaces" (str "a" "string" "with" "no" "spaces"))))) diff --git a/test/clojure/core_test/string_questionmark.cljc b/test/clojure/core_test/string_questionmark.cljc index f83f24b6..2cd8bac6 100644 --- a/test/clojure/core_test/string_questionmark.cljc +++ b/test/clojure/core_test/string_questionmark.cljc @@ -1,54 +1,56 @@ (ns clojure.core-test.string-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-string? - (are [expected x] (= expected (string? x)) - false 0 - false 1 - false -1 - false r/max-int - false r/min-int - false 0.0 - false 1.0 - false -1.0 - false (float 0.0) - false (float 1.0) - false (float -1.0) - false (double 0.0) - false (double 1.0) - false (double -1.0) - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - false 0N - false 1N - false -1N - false 0/2 - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - false true - false false - true "a string" - true "0" - true "1" - true "-1" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false \A - false \space - false :a-keyword - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/string? + (deftest test-string? + (are [expected x] (= expected (string? x)) + false 0 + false 1 + false -1 + false r/max-int + false r/min-int + false 0.0 + false 1.0 + false -1.0 + false (float 0.0) + false (float 1.0) + false (float -1.0) + false (double 0.0) + false (double 1.0) + false (double -1.0) + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + false 1N + false -1N + false 0/2 + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + false true + false false + true "a string" + true "0" + true "1" + true "-1" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false \A + false \space + false :a-keyword + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/subs.cljc b/test/clojure/core_test/subs.cljc index 74ec7eab..d205140b 100644 --- a/test/clojure/core_test/subs.cljc +++ b/test/clojure/core_test/subs.cljc @@ -1,19 +1,21 @@ (ns clojure.core-test.subs - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-subs - (is (= "bcde" (subs "abcde" 1))) - (is (= "bcd" (subs "abcde" 1 4))) - (is (= "abc" (subs "abcde" 0 3))) - (is (= "" (subs "abcde" 0 0))) - (is (= "" (subs "abcde" 5))) - (is (= "" (subs "abcde" 5 5))) - (is (thrown? StringIndexOutOfBoundsException (subs "abcde" 2 1))) - (is (thrown? StringIndexOutOfBoundsException (subs "abcde" 1 6))) - (is (thrown? StringIndexOutOfBoundsException (subs "abcde" 1 200))) - (is (thrown? StringIndexOutOfBoundsException (subs "abcde" -1))) - (is (thrown? StringIndexOutOfBoundsException (subs "abcde" -1 3))) - (is (thrown? StringIndexOutOfBoundsException (subs "abcde" -1 -3))) - (is (thrown? Exception (subs nil 1 2))) - (is (thrown? Exception (subs "abcde" nil 2))) - (is (thrown? Exception (subs "abcde" 1 nil)))) +(p/when-var-exists clojure.core/subs + (deftest test-subs + (is (= "bcde" (subs "abcde" 1))) + (is (= "bcd" (subs "abcde" 1 4))) + (is (= "abc" (subs "abcde" 0 3))) + (is (= "" (subs "abcde" 0 0))) + (is (= "" (subs "abcde" 5))) + (is (= "" (subs "abcde" 5 5))) + (is (thrown? StringIndexOutOfBoundsException (subs "abcde" 2 1))) + (is (thrown? StringIndexOutOfBoundsException (subs "abcde" 1 6))) + (is (thrown? StringIndexOutOfBoundsException (subs "abcde" 1 200))) + (is (thrown? StringIndexOutOfBoundsException (subs "abcde" -1))) + (is (thrown? StringIndexOutOfBoundsException (subs "abcde" -1 3))) + (is (thrown? StringIndexOutOfBoundsException (subs "abcde" -1 -3))) + (is (thrown? Exception (subs nil 1 2))) + (is (thrown? Exception (subs "abcde" nil 2))) + (is (thrown? Exception (subs "abcde" 1 nil))))) diff --git a/test/clojure/core_test/symbol.cljc b/test/clojure/core_test/symbol.cljc index dd864c9f..9eb3deb9 100644 --- a/test/clojure/core_test/symbol.cljc +++ b/test/clojure/core_test/symbol.cljc @@ -1,88 +1,90 @@ (ns clojure.core-test.symbol - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-symbol - ;; "Symbols begin with a non-numeric character and can contain - ;; alphanumeric characters and *, +, !, -, _, ', ?, <, > and = - ;; (other characters may be allowed eventually)." - ;; (see http://clojure.org/reader for details) - ;; - ;; From https://clojuredocs.org/clojure.core/keyword - ;; keyword does not validate input strings for ns and name, and may - ;; return improper keywords with undefined behavior for non-conformant - ;; ns and name. +(p/when-var-exists clojure.core/symbol + (deftest test-symbol + ;; "Symbols begin with a non-numeric character and can contain + ;; alphanumeric characters and *, +, !, -, _, ', ?, <, > and = + ;; (other characters may be allowed eventually)." + ;; (see http://clojure.org/reader for details) + ;; + ;; From https://clojuredocs.org/clojure.core/keyword + ;; keyword does not validate input strings for ns and name, and may + ;; return improper keywords with undefined behavior for non-conformant + ;; ns and name. - (are [expected name] (= expected (symbol name)) - 'abc "abc" - 'abc 'abc - 'abc :abc - '* "*" - '* '* - '* :* - '+ "+" - '+ '+ - '+ :+ - '! "!" - '! '! - '! :! - '- "-" - '- '- - '- :- - '_ "_" - '_ '_ - '_ :_ - '? "?" - '? '? - '? :? - '< "<" - '< '< - '< :< - '> ">" - '> '> - '> :> - '= "=" - '= '= - '= := - 'abc*+!-_'?<>= "abc*+!-_'?<>=") + (are [expected name] (= expected (symbol name)) + 'abc "abc" + 'abc 'abc + 'abc :abc + '* "*" + '* '* + '* :* + '+ "+" + '+ '+ + '+ :+ + '! "!" + '! '! + '! :! + '- "-" + '- '- + '- :- + '_ "_" + '_ '_ + '_ :_ + '? "?" + '? '? + '? :? + '< "<" + '< '< + '< :< + '> ">" + '> '> + '> :> + '= "=" + '= '= + '= := + 'abc*+!-_'?<>= "abc*+!-_'?<>=") - (are [expected ns name] (= expected (symbol ns name)) - 'abc/abc "abc" "abc" - 'abc.def/abc "abc.def" "abc" + (are [expected ns name] (= expected (symbol ns name)) + 'abc/abc "abc" "abc" + 'abc.def/abc "abc.def" "abc" - '*/abc "*" "abc" - '+/abc "+" "abc" - '!/abc "!" "abc" - '-/abc "-" "abc" - '_/abc "_" "abc" - '?/abc "?" "abc" - '/abc ">" "abc" - '=/abc "=" "abc" + '*/abc "*" "abc" + '+/abc "+" "abc" + '!/abc "!" "abc" + '-/abc "-" "abc" + '_/abc "_" "abc" + '?/abc "?" "abc" + '/abc ">" "abc" + '=/abc "=" "abc" - 'abc.def/* "abc.def" "*" - 'abc.def/+ "abc.def" "+" - 'abc.def/! "abc.def" "!" - 'abc.def/- "abc.def" "-" - 'abc.def/_ "abc.def" "_" - 'abc.def/? "abc.def" "?" - 'abc.def/< "abc.def" "<" - 'abc.def/> "abc.def" ">" - 'abc.def/= "abc.def" "=" + 'abc.def/* "abc.def" "*" + 'abc.def/+ "abc.def" "+" + 'abc.def/! "abc.def" "!" + 'abc.def/- "abc.def" "-" + 'abc.def/_ "abc.def" "_" + 'abc.def/? "abc.def" "?" + 'abc.def/< "abc.def" "<" + 'abc.def/> "abc.def" ">" + 'abc.def/= "abc.def" "=" - 'abc*+!-_'?<>=/abc*+!-_'?<>= "abc*+!-_'?<>=" "abc*+!-_'?<>=") + 'abc*+!-_'?<>=/abc*+!-_'?<>= "abc*+!-_'?<>=" "abc*+!-_'?<>=") - (is (thrown? Exception (symbol nil))) ; keyword returns nil - (is (= 'abc (symbol nil "abc"))) ; But if ns is nil, it just ignores it. + (is (thrown? Exception (symbol nil))) ; keyword returns nil + (is (= 'abc (symbol nil "abc"))) ; But if ns is nil, it just ignores it. - ;; prints as 'abc/null but the null is really a nil. Since this is - ;; not readable via the standard Clojure reader, I'm not even sure - ;; how to test this case here. That's why it's commented out. - ;; Note that `keyword` throws for this case. - ;; (is (= 'abc/null (symbol "abc" nil))) + ;; prints as 'abc/null but the null is really a nil. Since this is + ;; not readable via the standard Clojure reader, I'm not even sure + ;; how to test this case here. That's why it's commented out. + ;; Note that `keyword` throws for this case. + ;; (is (= 'abc/null (symbol "abc" nil))) - ;; Two arg version requires namespace and symbol to be a string, not - ;; a symbol or keyword like the one arg version. - (is (thrown? Exception (symbol 'abc "abc"))) - (is (thrown? Exception (symbol "abc" 'abc))) - (is (thrown? Exception (symbol :abc "abc"))) - (is (thrown? Exception (symbol "abc" :abc)))) + ;; Two arg version requires namespace and symbol to be a string, not + ;; a symbol or keyword like the one arg version. + (is (thrown? Exception (symbol 'abc "abc"))) + (is (thrown? Exception (symbol "abc" 'abc))) + (is (thrown? Exception (symbol :abc "abc"))) + (is (thrown? Exception (symbol "abc" :abc))))) diff --git a/test/clojure/core_test/symbol_questionmark.cljc b/test/clojure/core_test/symbol_questionmark.cljc index 3241200e..aaca3f3d 100644 --- a/test/clojure/core_test/symbol_questionmark.cljc +++ b/test/clojure/core_test/symbol_questionmark.cljc @@ -1,18 +1,20 @@ (ns clojure.core-test.symbol-questionmark - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-symbol? - (are [expected x] (= expected (symbol? x)) - false :a-keyword - true 'a-symbol - false :a-ns/a-keyword - true 'a-ns/a-keyword - false "a string" - false 0 - false 0N - false 0.0 - false 1/2 - false 0.0M - false false - false true - false nil)) +(p/when-var-exists clojure.core/symbol? + (deftest test-symbol? + (are [expected x] (= expected (symbol? x)) + false :a-keyword + true 'a-symbol + false :a-ns/a-keyword + true 'a-ns/a-keyword + false "a string" + false 0 + false 0N + false 0.0 + false 1/2 + false 0.0M + false false + false true + false nil))) diff --git a/test/clojure/core_test/taps.cljc b/test/clojure/core_test/taps.cljc index ae7897a0..67a283a6 100644 --- a/test/clojure/core_test/taps.cljc +++ b/test/clojure/core_test/taps.cljc @@ -1,50 +1,52 @@ (ns clojure.core-test.taps - (:require [clojure.test :as t :refer [is]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -;; testsing multiple tap functions -(defn sleep [ms] - #?(:clj (Thread/sleep ms) - :cljs nil)) ;; can test in the next iteration of the event loop, but this won't show up in the testing results +(p/when-var-exists clojure.core/add-tap + ;; testsing multiple tap functions + (defn sleep [ms] + #?(:clj (Thread/sleep ms) + :cljs nil)) ;; can test in the next iteration of the event loop, but this won't show up in the testing results -;; These tests may need promises in ClojureScript + ;; These tests may need promises in ClojureScript -(t/deftest tapping - (let [counter1 (volatile! 0) - counter2 (volatile! 0) - tester1 (fn [a] (vswap! counter1 + a)) - tester2 (fn [a] (vswap! counter2 + a)) - err (fn [x] (throw (ex-info (str x) {:x x})))] - (is (nil? (remove-tap tester1))) - (is (nil? (add-tap tester1))) - (is (nil? (add-tap nil))) - (is (nil? (add-tap err))) - (tap> 2) - (is (nil? (add-tap tester2))) - (tap> 3) - (tap> 101) - (sleep 50) ;; the tap queue always races - (is (= 106 @counter1)) - (is (= 104 @counter2)))) + (deftest tapping + (let [counter1 (volatile! 0) + counter2 (volatile! 0) + tester1 (fn [a] (vswap! counter1 + a)) + tester2 (fn [a] (vswap! counter2 + a)) + err (fn [x] (throw (ex-info (str x) {:x x})))] + (is (nil? (remove-tap tester1))) + (is (nil? (add-tap tester1))) + (is (nil? (add-tap nil))) + (is (nil? (add-tap err))) + (tap> 2) + (is (nil? (add-tap tester2))) + (tap> 3) + (tap> 101) + (sleep 50) ;; the tap queue always races + (is (= 106 @counter1)) + (is (= 104 @counter2)))) -(t/deftest removals - (let [counter1 (volatile! 0) - counter2 (volatile! 0) - tester1 (fn [a] (vswap! counter1 + a)) - tester2 (fn [a] (vswap! counter2 + a)) - err (fn [x] (throw (ex-info (str x) {:x x})))] - (is (nil? (remove-tap tester1))) - (is (nil? (add-tap tester1))) - (is (nil? (add-tap tester2))) - (tap> 3) - (sleep 100) - (is (nil? (remove-tap tester1))) - (tap> 5) - (is (nil? (remove-tap tester2))) - (sleep 50) ;; if we tap now, we can still see it in the testers - (tap> 100) - (sleep 50) - (is (nil? (remove-tap nil))) - (is (nil? (remove-tap tester2))) - (is (= 3 @counter1)) - (is (= 8 @counter2)))) + (deftest removals + (let [counter1 (volatile! 0) + counter2 (volatile! 0) + tester1 (fn [a] (vswap! counter1 + a)) + tester2 (fn [a] (vswap! counter2 + a)) + err (fn [x] (throw (ex-info (str x) {:x x})))] + (is (nil? (remove-tap tester1))) + (is (nil? (add-tap tester1))) + (is (nil? (add-tap tester2))) + (tap> 3) + (sleep 100) + (is (nil? (remove-tap tester1))) + (tap> 5) + (is (nil? (remove-tap tester2))) + (sleep 50) ;; if we tap now, we can still see it in the testers + (tap> 100) + (sleep 50) + (is (nil? (remove-tap nil))) + (is (nil? (remove-tap tester2))) + (is (= 3 @counter1)) + (is (= 8 @counter2))))) diff --git a/test/clojure/core_test/true_questionmark.cljc b/test/clojure/core_test/true_questionmark.cljc index d01955d1..16c809d7 100644 --- a/test/clojure/core_test/true_questionmark.cljc +++ b/test/clojure/core_test/true_questionmark.cljc @@ -1,56 +1,58 @@ (ns clojure.core-test.true-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-true? - (are [expected x] (= expected (true? x)) - false 0 - false 1 - false -1 - false r/max-int - false r/min-int - false 0.0 - false 1.0 - false -1.0 - false (float 0.0) - false (float 1.0) - false (float -1.0) - false (double 0.0) - false (double 1.0) - false (double -1.0) - false r/max-double - false r/min-double - false ##Inf - false ##-Inf - false ##NaN - false 0N - false 1N - false -1N - false 0/2 - false 1/2 - false -1/2 - false 0.0M - false 1.0M - false -1.0M - false nil - true true - false false - false "a string" - false "0" - false "1" - false "-1" - false "true" - false "false" - false {:a :map} - false #{:a-set} - false [:a :vector] - false '(:a :list) - false \0 - false \1 - false :a-keyword - false :true - false :false - false :0 - false :1 - false :-1 - false 'a-sym)) +(p/when-var-exists clojure.core/true? + (deftest test-true? + (are [expected x] (= expected (true? x)) + false 0 + false 1 + false -1 + false r/max-int + false r/min-int + false 0.0 + false 1.0 + false -1.0 + false (float 0.0) + false (float 1.0) + false (float -1.0) + false (double 0.0) + false (double 1.0) + false (double -1.0) + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + false 1N + false -1N + false 0/2 + false 1/2 + false -1/2 + false 0.0M + false 1.0M + false -1.0M + false nil + true true + false false + false "a string" + false "0" + false "1" + false "-1" + false "true" + false "false" + false {:a :map} + false #{:a-set} + false [:a :vector] + false '(:a :list) + false \0 + false \1 + false :a-keyword + false :true + false :false + false :0 + false :1 + false :-1 + false 'a-sym))) diff --git a/test/clojure/core_test/unsigned_bit_shift_right.cljc b/test/clojure/core_test/unsigned_bit_shift_right.cljc index 1d372423..4de1b503 100644 --- a/test/clojure/core_test/unsigned_bit_shift_right.cljc +++ b/test/clojure/core_test/unsigned_bit_shift_right.cljc @@ -1,11 +1,13 @@ (ns clojure.core-test.unsigned-bit-shift-right - (:require [clojure.test :as t])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(t/deftest common - #?(:clj (t/is (thrown? NullPointerException (unsigned-bit-shift-right nil 1))) - :cljs (t/is (unsigned-bit-shift-right nil 1))) - #?(:clj (t/is (thrown? NullPointerException (unsigned-bit-shift-right 1 nil))) - :cljs (t/is (unsigned-bit-shift-right 1 nil))) +(p/when-var-exists clojure.core/unsigned-bit-shift-right + (deftest test-unsigned-bit-shift-right + #?(:clj (is (thrown? NullPointerException (unsigned-bit-shift-right nil 1))) + :cljs (is (unsigned-bit-shift-right nil 1))) + #?(:clj (is (thrown? NullPointerException (unsigned-bit-shift-right 1 nil))) + :cljs (is (unsigned-bit-shift-right 1 nil))) - (t/are [ex a b] (= ex (unsigned-bit-shift-right a b)) - 18014398509481983 -1 10)) + (are [ex a b] (= ex (unsigned-bit-shift-right a b)) + 18014398509481983 -1 10))) diff --git a/test/clojure/core_test/with_out_str.cljc b/test/clojure/core_test/with_out_str.cljc index 129345aa..b7c16f27 100644 --- a/test/clojure/core_test/with_out_str.cljc +++ b/test/clojure/core_test/with_out_str.cljc @@ -1,9 +1,11 @@ (ns clojure.core-test.with-out-str - (:require [clojure.test :as t :refer [deftest testing is are]])) + (:require [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability :as p])) -(deftest test-with-out-str - (is (= (str "some sample :text here" (println-str) - "[:a :b] {:c :d} #{:e} (:f)" (prn-str)) - (with-out-str - (println "some" "sample" :text 'here) - (prn [:a :b] {:c :d} #{:e} '(:f)))))) +(p/when-var-exists clojure.core/with-out-str + (deftest test-with-out-str + (is (= (str "some sample :text here" (println-str) + "[:a :b] {:c :d} #{:e} (:f)" (prn-str)) + (with-out-str + (println "some" "sample" :text 'here) + (prn [:a :b] {:c :d} #{:e} '(:f))))))) diff --git a/test/clojure/core_test/zero_questionmark.cljc b/test/clojure/core_test/zero_questionmark.cljc index 20cda174..10258c58 100644 --- a/test/clojure/core_test/zero_questionmark.cljc +++ b/test/clojure/core_test/zero_questionmark.cljc @@ -1,32 +1,34 @@ (ns clojure.core-test.zero-questionmark (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.number-range :as r])) + [clojure.core-test.number-range :as r] + [clojure.core-test.portability :as p])) -(deftest test-zero? - (are [expected x] (= expected (zero? x)) - true 0 - false 1 - false -1 - false r/min-int - false r/max-int - true 0.0 - false 1.0 - false -1.0 - false r/min-double - false r/max-double - false ##Inf - false ##-Inf - false ##NaN - true 0N - false 1N - false -1N - true 0/2 - false 1/2 - false -1/2 - true 0.0M - false 1.0M - false -1.0M) +(p/when-var-exists clojure.core/zero? + (deftest test-zero? + (are [expected x] (= expected (zero? x)) + true 0 + false 1 + false -1 + false r/min-int + false r/max-int + true 0.0 + false 1.0 + false -1.0 + false r/min-double + false r/max-double + false ##Inf + false ##-Inf + false ##NaN + true 0N + false 1N + false -1N + true 0/2 + false 1/2 + false -1/2 + true 0.0M + false 1.0M + false -1.0M) - (is (thrown? Exception (zero? nil))) - (is (thrown? Exception (zero? false))) - (is (thrown? Exception (zero? true)))) + (is (thrown? Exception (zero? nil))) + (is (thrown? Exception (zero? false))) + (is (thrown? Exception (zero? true)))))