diff --git a/test/clojure/core_test/keyword.cljc b/test/clojure/core_test/keyword.cljc index c77c9b10..b6146ed3 100644 --- a/test/clojure/core_test/keyword.cljc +++ b/test/clojure/core_test/keyword.cljc @@ -3,86 +3,98 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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. + (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? #?(:cljs :default :default 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"))) ; If ns is nil, we just ignore it. + ;; But if name is nil, then maybe we throw or maybe we don't + #?(:cljs nil ; CLJS creates a keyword that isn't + ; readable (symbol part is null string: ":abc/") + :default + (is (thrown? Exception (keyword "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? #?(:cljs :default :default Exception) (keyword 'abc "abc"))) - (is (thrown? #?(:cljs :default :default Exception) (keyword "abc" 'abc))) - (is (thrown? #?(:cljs :default :default Exception) (keyword :abc "abc"))) - (is (thrown? #?(:cljs :default :default Exception) (keyword "abc" :abc))))) + #?@(:cljs + ;; IMO, CLJS gets this right + [(is (= :abc/abc (keyword 'abc "abc"))) + (is (= :abc/abc (keyword "abc" 'abc))) + (is (= :abc/abc (keyword :abc "abc"))) + (is (= :abc/abc (keyword "abc" :abc)))] + :default + ;; In Clojure JVM, 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/long.cljc b/test/clojure/core_test/long.cljc index 1897729d..b0fcdf54 100644 --- a/test/clojure/core_test/long.cljc +++ b/test/clojure/core_test/long.cljc @@ -3,45 +3,53 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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 [] + (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)))]) + (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 - #?@(:cljs [] - :default - [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 + #?@(:cljs [] + :default + [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? #?(:cljs :default :clj Exception) (long -9223372036854775809))) - (is (thrown? #?(:cljs :default :clj Exception) (long 9223372036854775808))) + #?@(:cljs [] ; In CLJS all numbers are really doubles + :default + ;; `long` throws outside the range of 9223372036854775807 ... -9223372036854775808 + [(is (thrown? #?(:cljs :default :clj Exception) (long -9223372036854775809))) + (is (thrown? #?(:cljs :default :clj Exception) (long 9223372036854775808)))]) - ;; Check handling of other types - (is (thrown? #?(:cljs :default :clj Exception) (long "0"))) - (is (thrown? #?(:cljs :default :clj Exception) (long :0))) - (is (thrown? #?(:cljs :default :clj Exception) (long [0]))) - (is (thrown? #?(:cljs :default :clj Exception) (long nil))))) + ;; Check handling of other types + #?@(:cljs + [(is (= 0 (long "0"))) ; JavaScript peeking through? + (is (NaN? (long :0))) + (is (NaN? (long [0]))) + (is (= 0 (long nil)))] ; Hm. Interesting. + :default + [(is (thrown? Exception (long "0"))) + (is (thrown? Exception (long :0))) + (is (thrown? Exception (long [0]))) + (is (thrown? Exception (long nil)))]))) diff --git a/test/clojure/core_test/max.cljc b/test/clojure/core_test/max.cljc index 1f07d914..05f56493 100644 --- a/test/clojure/core_test/max.cljc +++ b/test/clojure/core_test/max.cljc @@ -30,12 +30,23 @@ (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))) + #?@(:cljs + [(is (= 1 (max ##NaN 1))) ; Bug? + (is (NaN? (max 1 ##NaN))) ; Works as in JVM + (is (NaN? (max 1 2 3 4 ##NaN))) + (is (= ##Inf (max ##-Inf ##NaN ##Inf))) ; Bug? + (is (NaN? (max ##NaN))) - (is (thrown? #?(:cljs :default :clj Exception) (max "x" "y"))) - (is (thrown? #?(:cljs :default :clj Exception) (max nil 1))) - (is (thrown? #?(:cljs :default :clj Exception) (max 1 nil))))) + (is (= "y" (max "x" "y"))) ; In CLJS "x" and "y" are characters + (is (= 1 (max nil 1))) + (is (= 1 (max 1 nil)))] + :default + [(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)))]))) diff --git a/test/clojure/core_test/min.cljc b/test/clojure/core_test/min.cljc index 736a23ad..b9e9b30e 100644 --- a/test/clojure/core_test/min.cljc +++ b/test/clojure/core_test/min.cljc @@ -30,12 +30,23 @@ (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))) + #?@(:cljs + [(is (= 1 (min ##NaN 1))) ; Bug? + (is (NaN? (min 1 ##NaN))) + (is (NaN? (min 1 2 3 4 ##NaN))) + (is (= ##Inf (min ##-Inf ##NaN ##Inf))) ; Bug? + (is (NaN? (min ##NaN))) - (is (thrown? #?(:cljs :default :clj Exception) (min "x" "y"))) - (is (thrown? #?(:cljs :default :clj Exception) (min nil 1))) - (is (thrown? #?(:cljs :default :clj Exception) (min 1 nil))))) + (is (= "x" (min "x" "y"))) + (is (nil? (min nil 1))) ; nil acts like zero + (is (nil? (min 1 nil)))] + :default + [(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? #?(:cljs :default :clj Exception) (min "x" "y"))) + (is (thrown? #?(:cljs :default :clj Exception) (min nil 1))) + (is (thrown? #?(:cljs :default :clj Exception) (min 1 nil)))]))) diff --git a/test/clojure/core_test/minus.cljc b/test/clojure/core_test/minus.cljc index 76443f7f..5465e32f 100644 --- a/test/clojure/core_test/minus.cljc +++ b/test/clojure/core_test/minus.cljc @@ -4,200 +4,216 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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 - #?(:cljs nil - :default (is (thrown? #?(:cljs :default :default 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? #?(:cljs :default :clj Exception) (- nil 1))) - (is (thrown? #?(:cljs :default :clj Exception) (- 1 nil))) - (is (thrown? #?(:cljs :default :clj Exception) (- nil 1N))) - (is (thrown? #?(:cljs :default :clj Exception) (- 1N nil))) - (is (thrown? #?(:cljs :default :clj Exception) (- nil 1.0))) - (is (thrown? #?(:cljs :default :clj Exception) (- 1.0 nil))) - (is (thrown? #?(:cljs :default :clj Exception) (- nil 1.0M))) - (is (thrown? #?(:cljs :default :clj Exception) (- 1.0M nil))) - + (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 + #?(:cljs nil + :default (is (thrown? #?(:cljs :default :default Exception) (-)))) + + ;; Single arg + (is (= -3 (- 3))) + (is (= 3 (- -3))) + + ;; Multi-arg + (is (= -45 (- 0 1 2 3 4 5 6 7 8 9))) + + + #?@(:cljs + [(is (= -1 (- nil 1))) + (is (= 1 (- 1 nil))) + (is (= -1 (- nil 1N))) + (is (= 1 (- 1N nil))) + (is (= -1 (- nil 1.0))) + (is (= 1 (- 1.0 nil))) + (is (= -1 (- nil 1.0M))) + (is (= 1 (- 1.0M nil))) + ;; Add these back in later + #_(is (- r/min-int 1)) + #_(is (- r/max-int -1))] + :default + [(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))) + (is (thrown? Exception (- r/min-int 1))) + (is (thrown? Exception (- r/max-int -1)))])) + + + #?(:cljs nil ; CLJS doesn't support ratios + :default + (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))) + + (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 ##Inf + ##-Inf 1N ##Inf + ##Inf 1.0 ##-Inf + ##-Inf 1.0 ##Inf + #?@(:cljs [] + :default + [##Inf 1/2 ##-Inf + ##-Inf 1/2 ##Inf]) + + ##-Inf ##-Inf 1 + ##-Inf ##-Inf 1N + ##-Inf ##-Inf 1.0 + ##Inf ##Inf 1 + ##Inf ##Inf 1N + ##Inf ##Inf 1.0 + #?@(:cljs [] + :default + [##-Inf ##-Inf 1/2 + ##Inf ##Inf 1/2])) + + (are [x y] (and (NaN? (- x y)) + (NaN? (- y x))) + ##-Inf ##-Inf + 1 ##NaN + 1N ##NaN #?@(:cljs [] :default - [(is (thrown? #?(:cljs :default :clj Exception) (- r/min-int 1))) - (is (thrown? #?(:cljs :default :clj Exception) (- r/max-int -1)))])) - - - #?(:cljs [] - :default - (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? #?(:cljs :default :clj Exception) (- nil 1/2))) - (is (thrown? #?(:cljs :default :clj Exception) (- 1/2 nil))) - - (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 ##Inf - ##-Inf 1N ##Inf - ##Inf 1.0 ##-Inf - ##-Inf 1.0 ##Inf - #?@(:cljs [] - :default - [##Inf 1/2 ##-Inf - ##-Inf 1/2 ##Inf]) - - ##-Inf ##-Inf 1 - ##-Inf ##-Inf 1N - ##-Inf ##-Inf 1.0 - ##Inf ##Inf 1 - ##Inf ##Inf 1N - ##Inf ##Inf 1.0 - #?@(:cljs [] - :default - [##-Inf ##-Inf 1/2 - ##Inf ##Inf 1/2])) - - (are [x y] (and (NaN? (- x y)) - (NaN? (- y x))) - ##-Inf ##-Inf - 1 ##NaN - 1N ##NaN - #?@(:cljs [] - :default - [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? #?(:cljs :default :clj Exception) (- ##NaN nil))) - (is (thrown? #?(:cljs :default :clj Exception) (- ##Inf nil)))))) + [1.0 ##NaN + 1/2 ##NaN]) + ##Inf ##NaN + ##-Inf ##NaN + ##NaN ##NaN) + + ;; Single arg + (is (= ##-Inf (- ##Inf))) + (is (= ##Inf (- ##-Inf))) + (is (NaN? (- ##NaN))) + + #?@(:cljs + ;; CLJS treats nil as zero in arithemetic operations + [(is (NaN? (- ##NaN nil))) + (is (= ##Inf (- ##Inf nil)))] + :default + [(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 b16054e6..77202cda 100644 --- a/test/clojure/core_test/mod.cljc +++ b/test/clojure/core_test/mod.cljc @@ -4,85 +4,114 @@ [clojure.core-test.portability :as 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 + (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 + ;; Note that CLJS reads big integers as doubles with the + ;; fractional part equal to zero (just like CLJS ints). The + ;; big-int? function is conditionalized for CLJS. + 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 + ;; CLJS can read big decimals at the reader, but just converts + ;; them to doubles. + #?@(:cljs + [double? 1.0M 10 3.0M + double? 2.0M -10 3.0M + double? -1.0M -10 -3.0M + double? -2.0M 10 -3.0M + double? 1.0M 10.0M 3 + double? 2.0M -10.0M 3 + double? -1.0M -10.0M -3 + double? -2.0M 10.0M -3 + double? 1.0M 10.0M 3.0M + double? 2.0M -10.0M 3.0M + double? -1.0M -10.0M -3.0M + double? -2.0M 10.0M -3.0M] + :default + [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 - #?@(:cljs [] - :default [p/big-int? 0N 3 1/2 - p/big-int? 0N 3 -1/2 - p/big-int? -1N 3 -4/3 - p/big-int? 0N -3 1/2 - p/big-int? 1N -3 4/3 - p/big-int? 0N -3 -1/2 - ratio? 1/3 3 4/3 - ratio? 7/2 37/2 15 - ratio? -23/2 37/2 -15 - ratio? 23/2 -37/2 15 - ratio? -1/3 -3 -4/3 - ratio? -7/2 -37/2 -15])) + #?@(:cljs [] + :default [p/big-int? 0N 3 1/2 + p/big-int? 0N 3 -1/2 + p/big-int? -1N 3 -4/3 + p/big-int? 0N -3 1/2 + p/big-int? 1N -3 4/3 + p/big-int? 0N -3 -1/2 + ratio? 1/3 3 4/3 + ratio? 7/2 37/2 15 + ratio? -23/2 37/2 -15 + ratio? 23/2 -37/2 15 + ratio? -1/3 -3 -4/3 + ratio? -7/2 -37/2 -15])) - (is (thrown? #?(:cljs :default :default Exception) (mod 10 0))) - (is (thrown? #?(:cljs :default :default Exception) (mod ##Inf 1))) ; surprising since (/ ##Inf 1) = ##Inf - (is (NaN? (mod 1 ##Inf))) - (is (thrown? #?(:cljs :default :default Exception) (mod ##-Inf 1))) ; surprising since (/ ##-Inf 1) = ##-Inf - (is (NaN? (mod 1 ##-Inf))) - (is (thrown? #?(:cljs :default :default Exception) (mod ##NaN 1))) - (is (thrown? #?(:cljs :default :default Exception) (mod 1 ##NaN))) - (is (thrown? #?(:cljs :default :default Exception) (mod ##NaN 1))))) + #?@(:cljs + [(is (NaN? (mod 10 0))) + (is (NaN? (mod ##Inf 1))) + (is (NaN? (mod 1 ##Inf))) + (is (NaN? (mod ##-Inf 1))) + (is (NaN? (mod 1 ##-Inf))) + (is (NaN? (mod ##NaN 1))) + (is (NaN? (mod 1 ##NaN))) + (is (NaN? (mod ##NaN 1)))] + :default + [(is (thrown? Exception (mod 10 0))) + (is (thrown? Exception (mod ##Inf 1))) + (is (NaN? (mod 1 ##Inf))) + (is (thrown? Exception (mod ##-Inf 1))) + (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/nan_qmark.cljc b/test/clojure/core_test/nan_qmark.cljc index 8a8c5800..884ee2e9 100644 --- a/test/clojure/core_test/nan_qmark.cljc +++ b/test/clojure/core_test/nan_qmark.cljc @@ -4,8 +4,12 @@ (when-var-exists clojure.core/NaN? (deftest test-NaN? - (is (thrown? #?(:cljs :default :default Exception) (NaN? nil))) - (is (thrown? #?(:cljs :default :default Exception) (NaN? "##NaN"))) + #?@(:cljs + [(is (not (NaN? nil))) + (is (NaN? "##NaN"))] ; Surprising + :default + [(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 diff --git a/test/clojure/core_test/neg_int_qmark.cljc b/test/clojure/core_test/neg_int_qmark.cljc index bfa82634..4fb3e16f 100644 --- a/test/clojure/core_test/neg_int_qmark.cljc +++ b/test/clojure/core_test/neg_int_qmark.cljc @@ -13,7 +13,8 @@ true r/min-int false 0.0 false 1.0 - false -1.0 + #?@(:cljs [true -1.0] + :default [false -1.0]) false r/max-double false r/min-double false ##Inf @@ -21,7 +22,8 @@ false ##NaN false 0N false 1N - false -1N + #?@(:cljs [true -1N] + :default [false -1N]) #?@(:cljs [] :default [false 0/2 @@ -29,7 +31,8 @@ false -1/2]) false 0.0M false 1.0M - false -1.0M + #?@(:cljs [true -1.0M] + :default [false -1.0M]) false nil false true false false diff --git a/test/clojure/core_test/neg_qmark.cljc b/test/clojure/core_test/neg_qmark.cljc index ceac415f..c2de790c 100644 --- a/test/clojure/core_test/neg_qmark.cljc +++ b/test/clojure/core_test/neg_qmark.cljc @@ -4,33 +4,38 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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 - #?@(:cljs [] - :default - [false 0/2 - false 1/2 - true -1/2]) - false 0.0M - false 1.0M - true -1.0M) + (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 + #?@(:cljs [] + :default + [false 0/2 + false 1/2 + true -1/2]) + false 0.0M + false 1.0M + true -1.0M) - (is (thrown? #?(:cljs :default :clj Exception) (neg? nil))) - (is (thrown? #?(:cljs :default :clj Exception) (neg? false))) - (is (thrown? #?(:cljs :default :clj Exception) (neg? true))))) + #?@(:cljs + [(is (not (neg? nil))) + (is (not (neg? false))) ; Prints warning + (is (not (neg? true)))] ; Prints warning + :default + [(is (thrown? Exception (neg? nil))) + (is (thrown? Exception (neg? false))) + (is (thrown? Exception (neg? true)))]))) diff --git a/test/clojure/core_test/partial.cljc b/test/clojure/core_test/partial.cljc index 117aecd4..d046b59c 100644 --- a/test/clojure/core_test/partial.cljc +++ b/test/clojure/core_test/partial.cljc @@ -9,9 +9,10 @@ (deftest test-partial (let [simple-use (partial inc 2)] (is (= 3 (simple-use)))) - (let [lazily-evaluated (partial inc 2 3)] - #?(:clj (is (thrown? #?(:cljs :default :default Exception) (lazily-evaluated))) - :cljs (is (thrown? js/Error (lazily-evaluated))))) + (let [lazily-evaluated (partial inc 1 17)] + ;; CLJS ignores extra parameters given to apply. E.g., (apply inc 1 17) => 2 + #?(:cljs (is (= 2 (lazily-evaluated))) + :default (is (thrown? #?(:cljs :default :default Exception) (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)))) diff --git a/test/clojure/core_test/plus.cljc b/test/clojure/core_test/plus.cljc index 491adcb5..a21bdbaa 100644 --- a/test/clojure/core_test/plus.cljc +++ b/test/clojure/core_test/plus.cljc @@ -72,17 +72,23 @@ ;; Multi arg (is (= 45 (+ 0 1 2 3 4 5 6 7 8 9))) - (is (thrown? #?(:cljs :default :clj Exception) (+ 1 nil))) - (is (thrown? #?(:cljs :default :clj Exception) (+ nil 1))) - (is (thrown? #?(:cljs :default :clj Exception) (+ 1N nil))) - (is (thrown? #?(:cljs :default :clj Exception) (+ nil 1N))) - (is (thrown? #?(:cljs :default :clj Exception) (+ 1.0 nil))) - (is (thrown? #?(:cljs :default :clj Exception) (+ nil 1.0))) - - #?@(:cljs [] + + #?@(:cljs + [(is (= 1 (+ 1 nil))) + (is (= 1 (+ nil 1))) + (is (= 1 (+ 1N nil))) + (is (= 1 (+ nil 1N))) + (is (= 1 (+ 1.0 nil))) + (is (= 1 (+ nil 1.0)))] :default - [(is (thrown? #?(:cljs :default :default Exception) (+ r/max-int 1))) - (is (thrown? #?(:cljs :default :default Exception) (+ r/min-int -1))) + [(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))) + (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))) @@ -98,46 +104,46 @@ (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) + 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? #?(:cljs :default :default Exception) (+ 1/2 nil))) (is (thrown? #?(:cljs :default :default Exception) (+ nil 1/2))) #?@(:cljs nil :default - [(is (+ r/max-int 1/2)) ; test that these don't throw + [(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))) @@ -181,5 +187,9 @@ ##-Inf ##NaN ##NaN ##NaN) - (is (thrown? #?(:cljs :default :clj Exception) (+ ##NaN nil))) - (is (thrown? #?(:cljs :default :clj Exception) (+ ##Inf nil)))))) + #?@(:cljs + [(is (NaN? (+ ##NaN nil))) + (is (= ##Inf (+ ##Inf nil)))] + :default + [(is (thrown? Exception (+ ##NaN nil))) + (is (thrown? Exception (+ ##Inf nil)))])))) diff --git a/test/clojure/core_test/portability.cljc b/test/clojure/core_test/portability.cljc index 3ad46485..957aa38e 100644 --- a/test/clojure/core_test/portability.cljc +++ b/test/clojure/core_test/portability.cljc @@ -11,5 +11,9 @@ (println "SKIP -" '~var-sym)))) (defn big-int? [n] - (and (integer? n) - (not (int? n)))) + ;; In CLJS, all numbers are really doubles and integer? and int? + ;; return true if the fractional part of the double is zero + #?(:cljs (integer? n) + :default + (and (integer? n) + (not (int? n))))) diff --git a/test/clojure/core_test/pos_int_qmark.cljc b/test/clojure/core_test/pos_int_qmark.cljc index 467bc1a7..9615e0fe 100644 --- a/test/clojure/core_test/pos_int_qmark.cljc +++ b/test/clojure/core_test/pos_int_qmark.cljc @@ -4,47 +4,50 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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 - #?@(:cljs [] - :default - [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))) + (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 + #?@(:cljs [true 1.0] + :default [false 1.0]) + false -1.0 + false r/max-double + false r/min-double + false ##Inf + false ##-Inf + false ##NaN + false 0N + #?@(:cljs [true 1.0] + :default [false 1N]) + false -1N + #?@(:cljs [] + :default + [false 0/2 + false 1/2 + false -1/2]) + false 0.0M + #?@(:cljs [true 1.0M] + :default [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_qmark.cljc b/test/clojure/core_test/pos_qmark.cljc index a4b7e195..757ef398 100644 --- a/test/clojure/core_test/pos_qmark.cljc +++ b/test/clojure/core_test/pos_qmark.cljc @@ -4,33 +4,38 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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 - #?@(:cljs [] - :default - [false 0/2 - true 1/2 - false -1/2]) - false 0.0M - true 1.0M - false -1.0M) + (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 + #?@(:cljs [] + :default + [false 0/2 + true 1/2 + false -1/2]) + false 0.0M + true 1.0M + false -1.0M) - (is (thrown? #?(:cljs :default :clj Exception) (pos? nil))) - (is (thrown? #?(:cljs :default :clj Exception) (pos? false))) - (is (thrown? #?(:cljs :default :clj Exception) (pos? true))))) + #?@(:cljs + [(is (not (pos? nil))) + (is (not (pos? false))) ; Prints warning + (is (pos? true))] ; Prints warning + :default + [(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 2ea7ea71..9beeb1d7 100644 --- a/test/clojure/core_test/pr_str.cljc +++ b/test/clojure/core_test/pr_str.cljc @@ -5,5 +5,8 @@ (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}" + ;; Slight differences in the way that CLJS handles characters and + ;; numbers with no fractional part. + (is (= #?(:cljs "nil \"a\" \"string\" \"A\" \" \" 1 17 [:a :b] {:c :d} #{:e}" + :default "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 0c7364d8..999e120b 100644 --- a/test/clojure/core_test/print_str.cljc +++ b/test/clojure/core_test/print_str.cljc @@ -5,5 +5,6 @@ (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}" + (is (= #?(:cljs "nil a string A 1 17 [:a :b] {:c :d} #{:e}" + :default "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 063111e6..3196afb8 100644 --- a/test/clojure/core_test/println_str.cljc +++ b/test/clojure/core_test/println_str.cljc @@ -11,5 +11,6 @@ ;; 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) + (is (= #?(:cljs (str "nil a string A 1 17 [:a :b] {:c :d} #{:e}" nl) + :default (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 2f9eb96b..31769931 100644 --- a/test/clojure/core_test/prn_str.cljc +++ b/test/clojure/core_test/prn_str.cljc @@ -11,5 +11,6 @@ ;; 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) + (is (= #?(:cljs (str "nil \"a\" \"string\" \"A\" \" \" 1 17 [:a :b] {:c :d} #{:e}" nl) + :default (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/quot.cljc b/test/clojure/core_test/quot.cljc index 8f1e92ed..5d6bb2e7 100644 --- a/test/clojure/core_test/quot.cljc +++ b/test/clojure/core_test/quot.cljc @@ -3,85 +3,107 @@ [clojure.core-test.portability :as p #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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 + (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 + #?@(:cljs + [double? 3.0M 10 3.0M + double? -3.0M -10 3.0M + double? 3.0M -10 -3.0M + double? -3.0M 10 -3.0M + double? 3.0M 10.0M 3 + double? -3.0M -10.0M 3 + double? 3.0M -10.0M -3 + double? -3.0M 10.0M -3 + double? 3.0M 10.0M 3.0M + double? -3.0M -10.0M 3.0M + double? 3.0M -10.0M -3.0M + double? -3.0M 10.0M -3.0M] + :default + [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 - #?@(:cljs [] - :default [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 + #?@(:cljs [] + :default [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) + double? 0.0 1 ##Inf + double? 0.0 1 ##-Inf) - (is (thrown? #?(:cljs :default :default Exception) (quot 10 0))) - (is (thrown? #?(:cljs :default :default Exception) (quot ##Inf 1))) ; surprising since (/ ##Inf 1) = ##Inf - (is (thrown? #?(:cljs :default :default Exception) (quot ##-Inf 1))) ; surprising since (/ ##-Inf 1) = ##-Inf - (is (thrown? #?(:cljs :default :default Exception) (quot ##NaN 1))) - (is (thrown? #?(:cljs :default :default Exception) (quot 1 ##NaN))) - (is (thrown? #?(:cljs :default :default Exception) (quot ##NaN 1))))) + #?@(:cljs + [(is (NaN? (quot 10 0))) + (is (NaN? (quot ##Inf 1))) + (is (NaN? (quot ##-Inf 1))) + (is (NaN? (quot ##NaN 1))) + (is (NaN? (quot 1 ##NaN))) + (is (NaN? (quot ##NaN 1)))] + :default + [(is (thrown? #?(:cljs :default :default Exception) (quot 10 0))) + (is (thrown? #?(:cljs :default :default Exception) (quot ##Inf 1))) + (is (thrown? #?(:cljs :default :default Exception) (quot ##-Inf 1))) + (is (thrown? #?(:cljs :default :default Exception) (quot ##NaN 1))) + (is (thrown? #?(:cljs :default :default Exception) (quot 1 ##NaN))) + (is (thrown? #?(:cljs :default :default Exception) (quot ##NaN 1)))]))) diff --git a/test/clojure/core_test/rand.cljc b/test/clojure/core_test/rand.cljc index 85617e99..b3370807 100644 --- a/test/clojure/core_test/rand.cljc +++ b/test/clojure/core_test/rand.cljc @@ -11,11 +11,11 @@ (let [x (repeatedly length rand)] (is (every? double? x)) (is (every? pos? x)) - (is (> (count (set x)) 1)))) + (is (> (count (set x)) 1)))) ; shouldn't be constant (testing "one-arg case" (let [limit 0.01 ; Choose something < 1 to constrain it further x (repeatedly length #(rand limit))] (is (every? double? x)) (is (every? pos? x)) - (is (> (count (set x)) 1)) + (is (> (count (set x)) 1)) ; shouldn't be constant (is (every? #(< % limit) x))))))) diff --git a/test/clojure/core_test/rand_int.cljc b/test/clojure/core_test/rand_int.cljc index 57f0bb1d..c2a9b4df 100644 --- a/test/clojure/core_test/rand_int.cljc +++ b/test/clojure/core_test/rand_int.cljc @@ -7,9 +7,9 @@ ;; Generally, we test that the numbers returned pass `int?` and ;; that they are not constant. (let [length 100 - limit Integer/MAX_VALUE ; Note Long/MAX_VALUE overflows + limit 2000000000 ; 2 billion x (repeatedly length #(rand-int limit))] (is (every? int? x)) (is (every? pos? x)) - (is (> (count (set x)) 1)) + (is (> (count (set x)) 1)) ; Shouldn't be constant (is (every? #(< % limit) x))))) diff --git a/test/clojure/core_test/rem.cljc b/test/clojure/core_test/rem.cljc index be815d9a..15a6c126 100644 --- a/test/clojure/core_test/rem.cljc +++ b/test/clojure/core_test/rem.cljc @@ -38,18 +38,32 @@ 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 + #?@(:cljs + [double? 1.0M 10 3.0M + double? -1.0M -10 3.0M + double? -1.0M -10 -3.0M + double? 1.0M 10 -3.0M + double? 1.0M 10.0M 3 + double? -1.0M -10.0M 3 + double? -1.0M -10.0M -3 + double? 1.0M 10.0M -3 + double? 1.0M 10.0M 3.0M + double? -1.0M -10.0M 3.0M + double? -1.0M -10.0M -3.0M + double? 1.0M 10.0M -3.0M] + :default + [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 @@ -76,11 +90,21 @@ ratio? -1/3 -3 -4/3 ratio? -7/2 -37/2 -15])) - (is (thrown? #?(:cljs :default :clj Exception) (rem 10 0))) - (is (thrown? #?(:cljs :default :clj Exception) (rem ##Inf 1))) ; surprising since (/ ##Inf 1) = ##Inf - (is (NaN? (rem 1 ##Inf))) - (is (thrown? #?(:cljs :default :clj Exception) (rem ##-Inf 1))) ; surprising since (/ ##-Inf 1) = ##-Inf - (is (NaN? (rem 1 ##-Inf))) - (is (thrown? #?(:cljs :default :clj Exception) (rem ##NaN 1))) - (is (thrown? #?(:cljs :default :clj Exception) (rem 1 ##NaN))) - (is (thrown? #?(:cljs :default :clj Exception) (rem ##NaN 1))))) + #?@(:cljs + [(is (NaN? (rem 10 0))) + (is (NaN? (rem ##Inf 1))) + (is (NaN? (rem 1 ##Inf))) + (is (NaN? (rem ##-Inf 1))) + (is (NaN? (rem 1 ##-Inf))) + (is (NaN? (rem ##NaN 1))) + (is (NaN? (rem 1 ##NaN))) + (is (NaN? (rem ##NaN 1)))] + :default + [(is (thrown? #?(:cljs :default :clj Exception) (rem 10 0))) + (is (thrown? #?(:cljs :default :clj Exception) (rem ##Inf 1))) + (is (NaN? (rem 1 ##Inf))) + (is (thrown? #?(:cljs :default :clj Exception) (rem ##-Inf 1))) + (is (NaN? (rem 1 ##-Inf))) + (is (thrown? #?(:cljs :default :clj Exception) (rem ##NaN 1))) + (is (thrown? #?(:cljs :default :clj Exception) (rem 1 ##NaN))) + (is (thrown? #?(:cljs :default :clj Exception) (rem ##NaN 1)))]))) diff --git a/test/clojure/core_test/seq.cljc b/test/clojure/core_test/seq.cljc index 3a89e319..c2c75d9f 100644 --- a/test/clojure/core_test/seq.cljc +++ b/test/clojure/core_test/seq.cljc @@ -13,7 +13,8 @@ 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)) + #?@(:cljs [(int-array 3) '(nil nil nil)] + :default [(int-array 3) '(0 0 0)])) (testing "sets and maps" (let [input #{440M 55000M 80000} input-hash (into (hash-set) input) diff --git a/test/clojure/core_test/short.cljc b/test/clojure/core_test/short.cljc index 098fbe08..9fae9aee 100644 --- a/test/clojure/core_test/short.cljc +++ b/test/clojure/core_test/short.cljc @@ -3,47 +3,67 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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 [] - :default - [(is (instance? java.lang.Short (short 0)))]) + (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 [] + :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 - #?@(:cljs [] - :default - [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 + #?@(:cljs ; short is a dummy cast in CLJS + [1.1 1.1 + -1.1 -1.1 + 1.9 1.9] + :default + [1 1.1 + -1 -1.1 + 1 1.9]) + #?@(:cljs [] + :default + [1 3/2 + -1 -3/2 + 0 1/10 + 0 -1/10]) + #?@(:cljs + [1.1 1.1M + -1.1 -1.1M] + :default + [1 1.1M + -1 -1.1M])) - ;; `short` throws outside the range of 32767 ... -32768. - (is (thrown? #?(:cljs :default :clj Exception) (short -32768.000001))) - (is (thrown? #?(:cljs :default :clj Exception) (short -32769))) - (is (thrown? #?(:cljs :default :clj Exception) (short 32768))) - (is (thrown? #?(:cljs :default :clj Exception) (short 32767.000001))) + #?@(:cljs + [;; CLJS short is just a dummy cast + (is (= -32768.1 (short -32768.1))) + (is (= -32769 (short -32769))) + (is (= 32768 (short 32768))) + (is (= 32767.1 (short 32767.1))) + (is (= "0" (short "0"))) + (is (= :0 (short :0))) + (is (= [0] (short [0]))) + (is (= nil (short nil)))] + :default + [;; `short` throws outside the range of 32767 ... -32768. + (is (thrown? Exception (short -32768.000001))) + (is (thrown? Exception (short -32769))) + (is (thrown? Exception (short 32768))) + (is (thrown? Exception (short 32767.000001))) - ;; Check handling of other types - (is (thrown? #?(:cljs :default :clj Exception) (short "0"))) - (is (thrown? #?(:cljs :default :clj Exception) (short :0))) - (is (thrown? #?(:cljs :default :clj Exception) (short [0]))) - (is (thrown? #?(:cljs :default :clj Exception) (short nil))))) + ;; Check handling of other types + (is (thrown? Exception (short "0"))) + (is (thrown? Exception (short :0))) + (is (thrown? Exception (short [0]))) + (is (thrown? Exception (short nil)))]))) diff --git a/test/clojure/core_test/slash.cljc b/test/clojure/core_test/slash.cljc index 4882b64e..81d843ec 100644 --- a/test/clojure/core_test/slash.cljc +++ b/test/clojure/core_test/slash.cljc @@ -125,24 +125,29 @@ #?(:cljs (is (= 50 (/ 100 1 2))) :default (is (= 1/362880 (/ 1 2 3 4 5 6 7 8 9)))) - (is (thrown? #?(:cljs :default :clj Exception) (/ 1 0))) - (is (thrown? #?(:cljs :default :clj Exception) (/ nil 1))) - (is (thrown? #?(:cljs :default :clj Exception) (/ 1 nil)))) + #?@(:cljs + [(is (= ##Inf (/ 1 0))) + (is (= 0 (/ nil 1))) + (is (= ##Inf (/ 1 nil)))] + :default + [(is (thrown? Exception (/ 1 0))) + (is (thrown? Exception (/ nil 1))) + (is (thrown? Exception (/ 1 nil)))])) #?(:cljs nil :default (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) + 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))) diff --git a/test/clojure/core_test/star.cljc b/test/clojure/core_test/star.cljc index e1000054..7d9a9b31 100644 --- a/test/clojure/core_test/star.cljc +++ b/test/clojure/core_test/star.cljc @@ -15,7 +15,6 @@ -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 @@ -72,8 +71,12 @@ ;; Multi arg (is (= 362880 (* 1 2 3 4 5 6 7 8 9))) - (is (thrown? #?(:cljs :default :clj Exception) (* 1 nil))) - (is (thrown? #?(:cljs :default :clj Exception) (* nil 1))) + #?@(:cljs + [(is (= 0 (* 1 nil))) + (is (= 0 (* nil 1)))] + :default + [(is (thrown? Exception (* 1 nil))) + (is (thrown? Exception (* nil 1)))]) #?@(:cljs [] :default @@ -87,36 +90,36 @@ (is (instance? clojure.lang.BigInt (* 1N 5))) (is (instance? clojure.lang.BigInt (* 1N 5N))) - (is (thrown? #?(:cljs :default :default Exception) (* -1 r/min-int))) - (is (thrown? #?(:cljs :default :default Exception) (* r/min-int -1))) - (is (thrown? #?(:cljs :default :default Exception) (* (long (/ r/min-int 2)) 3))) - (is (thrown? #?(:cljs :default :default Exception) (* 3 (long (/ r/min-int 2)))))])) + (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)))))])) #?(:cljs nil :default (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) + 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? #?(:cljs :default :default Exception) (* 1/2 nil))) (is (thrown? #?(:cljs :default :default Exception) (* nil 1/2))))) diff --git a/test/clojure/core_test/str.cljc b/test/clojure/core_test/str.cljc index e986c708..d7b13630 100644 --- a/test/clojure/core_test/str.cljc +++ b/test/clojure/core_test/str.cljc @@ -3,56 +3,72 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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 - #?@(:cljs [] - :default - ["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) + (deftest test-str + (are [expected x] (= expected (str x)) + "0" 0 + "1" 1 + "-1" -1 + #?@(:cljs + ["0" 0.0 + "1" 1.0 + "-1" -1.0 + "0" 0.00000 + "0" (float 0.0) + "1" (float 1.0) + "-1" (float -1.0) + "0" (double 0.0) + "1" (double 1.0) + "-1" (double -1.0)] + :default + ["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 + #?@(:cljs + ["0" 0.0M + "1" 1.0M + "-1" -1.0M] + :default + ["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_qmark.cljc b/test/clojure/core_test/string_qmark.cljc index 2c6dc7d4..bce9b91e 100644 --- a/test/clojure/core_test/string_qmark.cljc +++ b/test/clojure/core_test/string_qmark.cljc @@ -4,55 +4,61 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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 - #?@(:cljs [] - :default - [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))) + (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 + #?@(:cljs [] + :default + [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) + #?@(:cljs + [true \0 + true \1 + true \A + true \space] + :default + [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 f0ccec84..927ef567 100644 --- a/test/clojure/core_test/subs.cljc +++ b/test/clojure/core_test/subs.cljc @@ -3,19 +3,30 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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? #?(:cljs :default :clj Exception) (subs "abcde" 2 1))) - (is (thrown? #?(:cljs :default :clj Exception) (subs "abcde" 1 6))) - (is (thrown? #?(:cljs :default :clj Exception) (subs "abcde" 1 200))) - (is (thrown? #?(:cljs :default :clj Exception) (subs "abcde" -1))) - (is (thrown? #?(:cljs :default :clj Exception) (subs "abcde" -1 3))) - (is (thrown? #?(:cljs :default :clj Exception) (subs "abcde" -1 -3))) - (is (thrown? #?(:cljs :default :clj Exception) (subs nil 1 2))) - (is (thrown? #?(:cljs :default :clj Exception) (subs "abcde" nil 2))) - (is (thrown? #?(:cljs :default :clj Exception) (subs "abcde" 1 nil))))) + (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))) + #?@(:cljs + [(is (= "b" (subs "abcde" 2 1))) + (is (= "bcde" (subs "abcde" 1 6))) + (is (= "bcde" (subs "abcde" 1 200))) + (is (= "abcde" (subs "abcde" -1))) + (is (= "abc" (subs "abcde" -1 3))) + (is (= "" (subs "abcde" -1 -3))) + (is (thrown? :default (subs nil 1 2))) + (is (= "ab" (subs "abcde" nil 2))) + (is (= "a" (subs "abcde" 1 nil)))] + :default + [(is (thrown? Exception (subs "abcde" 2 1))) + (is (thrown? Exception (subs "abcde" 1 6))) + (is (thrown? Exception (subs "abcde" 1 200))) + (is (thrown? Exception (subs "abcde" -1))) + (is (thrown? Exception (subs "abcde" -1 3))) + (is (thrown? Exception (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 22662369..d80e234c 100644 --- a/test/clojure/core_test/symbol.cljc +++ b/test/clojure/core_test/symbol.cljc @@ -3,88 +3,94 @@ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (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. + (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? #?(:cljs :default :clj Exception) (symbol nil))) ; keyword returns nil - (is (= 'abc (symbol nil "abc"))) ; But if ns is nil, it just ignores it. + (is (thrown? #?(:cljs :default :clj 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? #?(:cljs :default :clj Exception) (symbol 'abc "abc"))) - (is (thrown? #?(:cljs :default :clj Exception) (symbol "abc" 'abc))) - (is (thrown? #?(:cljs :default :clj Exception) (symbol :abc "abc"))) - (is (thrown? #?(:cljs :default :clj 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. + #?@(:cljs + [(is (= 'abc/abc (symbol 'abc "abc"))) + (is (= 'abc/abc (symbol "abc" 'abc))) + ;; (is (= :abc/abc (symbol :abc "abc"))) results in unreadable value + (is (= 'abc/:abc (symbol "abc" :abc)))] + :default + [(is (thrown? Exception (symbol 'abc "abc"))) + (is (thrown? Exception (symbol "abc" 'abc))) + (is (thrown? Exception (symbol :abc "abc"))) + (is (thrown? Exception (symbol "abc" :abc)))])))