diff --git a/deps-clr.edn b/deps-clr.edn new file mode 100644 index 0000000..d8bcb98 --- /dev/null +++ b/deps-clr.edn @@ -0,0 +1,8 @@ +{:deps {} + :aliases + {:test + {:extra-paths ["test"] + :extra-deps {io.github.dmiller/test-runner {:git/sha "c055ea13d19c6a9b9632aa2370fcc2215c8043c3"}} + :exec-fn cognitect.test-runner.api/test + :exec-args {:dirs ["test"] + :patterns [".*test.*"]}}}} diff --git a/package-lock.json b/package-lock.json index 4559627..2a47cbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "clojure.core-test", + "name": "io.github.jank-lang/clojure-test-suite", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "clojure.core-test", + "name": "io.github.jank-lang/clojure-test-suite", "version": "1.0.0", "license": "MPL 2.0", "devDependencies": { diff --git a/test/clojure/core_test/byte.cljc b/test/clojure/core_test/byte.cljc index 4987998..d788df1 100644 --- a/test/clojure/core_test/byte.cljc +++ b/test/clojure/core_test/byte.cljc @@ -1,6 +1,7 @@ (ns clojure.core-test.byte - (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + (:require [clojure.test :as t :refer [deftest is are]] + [clojure.core-test.portability + #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (when-var-exists clojure.core/byte (deftest test-byte @@ -10,19 +11,21 @@ ;; test whether it's a fixed-length integer of some sort. (is (int? (byte 0))) #?(:clj (is (instance? java.lang.Byte (byte 0))) - :cljr (is (instance? System.Byte (byte 0)))) + :cljr (is (instance? System.Byte (byte 0)))) ;; Check conversions and rounding from other numeric types + ;; In ClojureCLR, Byte is unsigned, so we have to wipe all tests + ;; of negative values (are [expected x] (= expected (byte x)) - -128 -128 + #?@(:cljr [] :default [-128 -128]) 0 0 127 127 1 1N 0 0N - -1 -1N + #?@(:cljr [] :default [-1 -1N]) 1 1.0M 0 0.0M - -1 -1.0M + #?@(:cljr [] :default [-1 -1.0M]) ;; Clojurescript `byte` is a "dummy cast" which doesn't do ;; anything (no-op). Thus, there is no conversion, no truncation ;; of decimal values, etc. @@ -34,14 +37,14 @@ -1.1 -1.1M] :default [1 1.1 - -1 -1.1 + #?@(:cljr [] :default [-1 -1.1]) 1 1.9 1 3/2 - -1 -3/2 + #?@(:cljr [] :default [-1 -3/2]) 0 1/10 - 0 -1/10 + #?@(:cljr [] :default [0 -1/10]) 1 1.1M - -1 -1.1M])) + #?@(:cljr [] :default [-1 -1.1M])])) #?@(:cljs [ ;; ClojureScript `byte` just returns its argument @@ -53,15 +56,26 @@ (is (= :0 (byte :0))) (is (= [0] (byte [0]))) (is (= nil (byte nil)))] - :bb [] ;; byte constructions goes via boxed argument + :cljr + [ ;; `byte` throws outside the range of 127 ... -128. + (is (thrown? Exception (byte -128.000001))) + (is (thrown? Exception (byte -129))) + (is (= 128 (byte 128))) + (is (= 127(byte 127.000001))) + ;; Check handling of other types + (is (= 0 (byte "0"))) + (is (thrown? Exception (byte :0))) + (is (thrown? Exception (byte [0]))) + (is (thrown? Exception (byte nil)))] + :bb [] ;; byte constructions goes via boxed argument :default [ ;; `byte` throws outside the range of 127 ... -128. - (is (thrown? #?(:clj Exception :cljr Exception) (byte -128.000001))) - (is (thrown? #?(:clj Exception :cljr Exception) (byte -129))) - (is (thrown? #?(:clj Exception :cljr Exception) (byte 128))) - (is (thrown? #?(:clj Exception :cljr Exception) (byte 127.000001))) + (is (thrown? Exception (byte -128.000001))) + (is (thrown? Exception (byte -129))) + (is (thrown? Exception (byte 128))) + (is (thrown? Exception (byte 127.000001))) ;; Check handling of other types - (is (thrown? #?(:clj Exception :cljr Exception) (byte "0"))) - (is (thrown? #?(:clj Exception :cljr Exception) (byte :0))) - (is (thrown? #?(:clj Exception :cljr Exception) (byte [0]))) - (is (thrown? #?(:clj Exception :cljr Exception) (byte nil)))]))) + (is (thrown? Exception (byte "0"))) + (is (thrown? Exception (byte :0))) + (is (thrown? Exception (byte [0]))) + (is (thrown? Exception (byte nil)))]))) diff --git a/test/clojure/core_test/double.cljc b/test/clojure/core_test/double.cljc index e554032..65f51f0 100644 --- a/test/clojure/core_test/double.cljc +++ b/test/clojure/core_test/double.cljc @@ -23,9 +23,12 @@ ;; In cljs, `double` is just returns the argument unchanged (dummy fn) [(is (= "0" (double "0"))) (is (= :0 (double :0)))] + :cljr + [(is (= 0.0 (double "0"))) + (is (thrown? Exception (double :0)))] :default - [(is (thrown? #?(:clj Exception :cljr Exception) (double "0"))) - (is (thrown? #?(:clj Exception :cljr Exception) (double :0)))]) + [(is (thrown? Exception (double "0"))) + (is (thrown? Exception (double :0)))]) #?@(:clj [(is (instance? java.lang.Double (double 0))) diff --git a/test/clojure/core_test/int.cljc b/test/clojure/core_test/int.cljc index cc1e8c9..d8928e9 100644 --- a/test/clojure/core_test/int.cljc +++ b/test/clojure/core_test/int.cljc @@ -11,7 +11,8 @@ ;; predicate for it. Here, we just test whether it's a fixed-length ;; integer of some sort. (is (int? (int 0))) - #?(:clj (is (instance? java.lang.Integer (int 0)))) + #?(:clj (is (instance? java.lang.Integer (int 0))) + :cljr (is (instance? System.Int32 (int 0)))) ;; Check conversions and rounding from other numeric types (are [expected x] (= expected (int x)) @@ -40,16 +41,28 @@ 0 -1/10])) #?@(:cljs [] - :bb [] + :bb [] + :cljr + [ ;; `int` throws outside the range of 32767 ... -32768. + (is (thrown? Exception (int -2147483648.000001))) + (is (thrown? Exception (int -2147483649))) + (is (thrown? Exception (int 2147483648))) + (is (thrown? Exception (int 2147483647.000001))) + + ;; Check handling of other types + (is (= 0 (int "0"))) + (is (thrown? Exception (int :0))) + (is (thrown? Exception (int [0]))) + (is (thrown? Exception (int nil)))] :default [ ;; `int` throws outside the range of 32767 ... -32768. - (is (thrown? #?(:clj Exception :cljr Exception) (int -2147483648.000001))) - (is (thrown? #?(:clj Exception :cljr Exception) (int -2147483649))) - (is (thrown? #?(:clj Exception :cljr Exception) (int 2147483648))) - (is (thrown? #?(:clj Exception :cljr Exception) (int 2147483647.000001))) + (is (thrown? Exception (int -2147483648.000001))) + (is (thrown? Exception (int -2147483649))) + (is (thrown? Exception (int 2147483648))) + (is (thrown? Exception (int 2147483647.000001))) ;; Check handling of other types - (is (thrown? #?(:clj Exception :cljr Exception) (int "0"))) - (is (thrown? #?(:clj Exception :cljr Exception) (int :0))) - (is (thrown? #?(:clj Exception :cljr Exception) (int [0]))) - (is (thrown? #?(:clj Exception :cljr Exception) (int nil)))]))) + (is (thrown? Exception (int "0"))) + (is (thrown? Exception (int :0))) + (is (thrown? Exception (int [0]))) + (is (thrown? Exception (int nil)))]))) diff --git a/test/clojure/core_test/shuffle.cljc b/test/clojure/core_test/shuffle.cljc index c266698..6a9b424 100644 --- a/test/clojure/core_test/shuffle.cljc +++ b/test/clojure/core_test/shuffle.cljc @@ -23,11 +23,16 @@ (is (vector? actual)) (is (= (count x) (count actual)))))) (testing "negative cases" - (is (thrown? #?(:cljs :default, :default Exception) (shuffle 1))) + #?(:cljs (is (thrown? js/Error (shuffle 1))) + :default (is (thrown? Exception (shuffle 1)))) #?@(:cljs [(is (= [] (shuffle nil))) - (is [] (shuffle {}))] + (is (= [] (shuffle {})))] + :cljr + [(is (thrown? Exception (shuffle nil))) + (is (thrown? Exception (shuffle "abc"))) + (is (= [] (shuffle {})))] :default - [(is (thrown? #?(:cljs :default, :default Exception) (shuffle nil))) - (is (thrown? #?(:cljs :default, :default Exception) (shuffle "abc"))) - (is (thrown? #?(:cljs :default, :default Exception) (shuffle {})))])))) + [(is (thrown? Exception (shuffle nil))) + (is (thrown? Exception (shuffle "abc"))) + (is (thrown? Exception (shuffle {})))])))) diff --git a/test/clojure/core_test/str.cljc b/test/clojure/core_test/str.cljc index d7b1363..87179a6 100644 --- a/test/clojure/core_test/str.cljc +++ b/test/clojure/core_test/str.cljc @@ -19,6 +19,17 @@ "0" (double 0.0) "1" (double 1.0) "-1" (double -1.0)] + :cljr + ["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 @@ -49,8 +60,8 @@ "-1.0" -1.0M]) "" nil - "true" true - "false" false + #?(:cljr "True" :default "true") true + #?(:cljr "False" :default "false") false "a string" "a string" "0" "0" "1" "1" diff --git a/test/clojure/core_test/with_out_str.cljc b/test/clojure/core_test/with_out_str.cljc index 3d9bc5c..801a02b 100644 --- a/test/clojure/core_test/with_out_str.cljc +++ b/test/clojure/core_test/with_out_str.cljc @@ -1,11 +1,27 @@ (ns clojure.core-test.with-out-str - (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + (:require [clojure.test :as t :refer [deftest is]] + [clojure.core-test.portability + #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +;; This is part of clojure.test-helpers, but I couldn't figure out how to +;; :require or :use that library. +;; Copied here for now +(defn platform-newlines [s] + #?(:clj + (let [nl (System/getProperty "line.separator")] + (.replace s "\n" nl)) + :cljr + (let [nl Environment/NewLine] ;;; (System/getProperty "line.separator")] + (.Replace ^String s "\n" nl)) ;;; .replace, add type hint + :default + s)) + (when-var-exists clojure.core/with-out-str (deftest test-with-out-str - (is (= (str "some sample :text here" \newline - "[:a :b] {:c :d} #{:e} (:f)" \newline) + (is (= (platform-newlines + (str "some sample :text here" \newline + "[:a :b] {:c :d} #{:e} (:f)" \newline)) (with-out-str (println "some" "sample" :text 'here) (prn [:a :b] {:c :d} #{:e} '(:f))))))) diff --git a/test/clojure/core_test/with_precision.cljc b/test/clojure/core_test/with_precision.cljc index a2a288e..5061c08 100644 --- a/test/clojure/core_test/with_precision.cljc +++ b/test/clojure/core_test/with_precision.cljc @@ -1,8 +1,8 @@ (ns clojure.core-test.with-precision (:require [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) -(when-var-exists clojure.core/with-precision +(when-var-exists with-precision (deftest test-with-precision ;; tests copied from https://clojuredocs.org/clojure.core/with-precision (is (= 2M (with-precision 1 :rounding UP (* 1.1M 1M)))) diff --git a/test/clojure/string_test/blank_qmark.cljc b/test/clojure/string_test/blank_qmark.cljc index 085320f..fbf9444 100644 --- a/test/clojure/string_test/blank_qmark.cljc +++ b/test/clojure/string_test/blank_qmark.cljc @@ -1,7 +1,8 @@ (ns clojure.string-test.blank-qmark (:require [clojure.string :as str] - [clojure.test :as t :refer [deftest testing is are]] - [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + [clojure.test :as t :refer [deftest testing is]] + [clojure.core-test.portability + #?(:cljs :refer-macros :default :refer) [when-var-exists]])) (when-var-exists str/blank? (deftest test-blank? @@ -9,8 +10,8 @@ (is (true? (str/blank? nil))) (is (false? (str/blank? "֎"))) (testing "U+2007" - (is (#?(:cljs true? :cljr true :default false?) (str/blank? " "))) - (is (#?(:cljs true? :cljr true :default false?) (str/blank? "\u2007")))) + (is (#?(:cljs true? :cljr true? :default false?) (str/blank? " "))) + (is (#?(:cljs true? :cljr true? :default false?) (str/blank? "\u2007")))) (is (true? (str/blank? " "))) (is (true? (str/blank? " \t "))) #?(:cljs (do (is (true? (str/blank? (symbol "")))) diff --git a/test/clojure/string_test/capitalize.cljc b/test/clojure/string_test/capitalize.cljc index b5496e1..0332c60 100644 --- a/test/clojure/string_test/capitalize.cljc +++ b/test/clojure/string_test/capitalize.cljc @@ -11,6 +11,10 @@ (is (thrown? :default (str/capitalize 'a/a))) (is (thrown? :default (str/capitalize :a))) (is (thrown? :default (str/capitalize :a/a)))) + :cljr (do (is (thrown? Exception (str/capitalize 1))) + (is (thrown? Exception (str/capitalize 'Asdf))) + (is (thrown? Exception (str/capitalize 'asDf/aSdf))) + (is (thrown? Exception (str/capitalize :asDf/aSdf)))) :default (do (is (= "1" (str/capitalize 1))) (is (= "Asdf" (str/capitalize 'Asdf))) (is (= "Asdf/asdf" (str/capitalize 'asDf/aSdf))) diff --git a/test/clojure/string_test/ends_with_qmark.cljc b/test/clojure/string_test/ends_with_qmark.cljc index fdb1a65..b62422b 100644 --- a/test/clojure/string_test/ends_with_qmark.cljc +++ b/test/clojure/string_test/ends_with_qmark.cljc @@ -7,16 +7,34 @@ (deftest test-ends-with? (is (true? (str/ends-with? "" ""))) (is (thrown? #?(:cljs :default :clj Exception :cljr Exception) (str/ends-with? "" nil))) - (is (thrown? #?(:cljs :default :clj Exception :cljr Exception) (str/ends-with? nil ""))) + + #?(:cljs (is (thrown? :default (str/ends-with? nil ""))) + :cljr (is (true? (str/ends-with? nil ""))) + :default (is (thrown? Exception (str/ends-with? nil "")))) + #?(:cljs (do (is (false? (str/ends-with? "ab" :b))) (is (false? (str/ends-with? "ab" :a)))) :default (is (thrown? #?(:clj Exception :cljr Exception) (str/ends-with? "ab" :b)))) + #?(:cljs (is (false? (str/ends-with? "ab" 'b))) :default (is (thrown? #?(:clj Exception :cljr Exception) (str/ends-with? "ab" 'b)))) - (is (#?(:cljs false? :default true?) (str/ends-with? 'ab "b"))) - (is (false? (str/ends-with? 'ab "a"))) - (is (#?(:cljs false? :default true?) (str/ends-with? :ab "b"))) - (is (false? (str/ends-with? :ab "a"))) + + #?@(:cljs + [(is (false? (str/ends-with? 'ab "b"))) + (is (false? (str/ends-with? 'ab "a"))) + (is (false? (str/ends-with? :ab "b"))) + (is (false? (str/ends-with? :ab "a")))] + :cljr + [(is (thrown? Exception (str/ends-with? 'ab "b"))) + (is (thrown? Exception (str/ends-with? 'ab "a"))) + (is (thrown? Exception (str/ends-with? :ab "b"))) + (is (thrown? Exception (str/ends-with? :ab "b")))] + :default + [(is (true? (str/ends-with? 'ab "b"))) + (is (false? (str/ends-with? 'ab "a"))) + (is (true? (str/ends-with? :ab "b"))) + (is (false? (str/ends-with? :ab "a")))]) + (is (false? (str/ends-with? "" "a"))) (is (true? (str/ends-with? "a-test" ""))) (is (true? (str/ends-with? "a-test֎" "֎"))) diff --git a/test/clojure/string_test/lower_case.cljc b/test/clojure/string_test/lower_case.cljc index 99421f1..db30f60 100644 --- a/test/clojure/string_test/lower_case.cljc +++ b/test/clojure/string_test/lower_case.cljc @@ -14,8 +14,11 @@ (is (= "asdf" (str/lower-case "ASDF"))) (is (= "ASDF" s) "original string mutated")) #?(:cljs (is (thrown? :default (str/lower-case :ASDF))) + :cljr (is (thrown? Exception (str/lower-case :ASDF))) :default (is (= ":asdf" (str/lower-case :ASDF)))) #?(:cljs (is (thrown? :default (str/lower-case :ASDF/ASDF))) + :cljr (is (thrown? Exception (str/lower-case :ASDF/ASDF))) :default (is (= ":asdf/asdf" (str/lower-case :ASDF/ASDF)))) #?(:cljs (is (thrown? :default (str/lower-case 'ASDF))) + :cljr (is (thrown? Exception (str/lower-case 'ASDF))) :default (is (= "asdf" (str/lower-case 'ASDF)))))) diff --git a/test/clojure/string_test/starts_with_qmark.cljc b/test/clojure/string_test/starts_with_qmark.cljc index 5563b6e..907d685 100644 --- a/test/clojure/string_test/starts_with_qmark.cljc +++ b/test/clojure/string_test/starts_with_qmark.cljc @@ -8,13 +8,18 @@ (is (true? (str/starts-with? "" ""))) #?(:cljs (is (false? (str/starts-with? "" nil))) :default (is (thrown? #?(:clj Exception :cljr Exception) (str/starts-with? "" nil)))) - (is (thrown? #?(:cljs :default :clj Exception :cljr Exception) (str/starts-with? nil ""))) + + #?(:cljs (is (thrown? :default (str/starts-with? nil ""))) + :cljr (is (true? (str/starts-with? nil ""))) + :default (is (thrown? Exception (str/starts-with? nil "")))) + #?(:cljs (do (is (false? (str/starts-with? "ab" :a))) (is (true? (str/starts-with? ":ab" :a))) (is (false? (str/starts-with? "ab" :b)))) :default (is (thrown? #?(:clj Exception :cljr Exception) (str/starts-with? "ab" :a)))) #?(:cljs (is (true? (str/starts-with? "ab" 'a))) :default (is (thrown? #?(:clj Exception :cljr Exception) (str/starts-with? "a" 'a)))) + (is (false? (str/starts-with? "" "a"))) (is (true? (str/starts-with? "a-test" ""))) (is (true? (str/starts-with? "֎a-test" "֎"))) @@ -22,17 +27,25 @@ (is (true? (str/starts-with? "a-test" "a-test"))) (is (false? (str/starts-with? "a-test" "-"))) (is (false? (str/starts-with? "a-test" "t"))) - #?(:cljs (is (thrown? :default (str/starts-with? 'ab ":a"))) - :default (do (is (false? (str/starts-with? 'ab "b"))) - (is (true? (str/starts-with? 'ab "a"))))) - #?(:cljs (is (thrown? :default (str/starts-with? :ab ":a"))) - :default (do (is (false? (str/starts-with? :ab "b"))) - (is (false? (str/starts-with? :ab "a"))) - (is (true? (str/starts-with? :ab ":a"))))) - #?(:cljs (is (thrown? :default (str/starts-with? 'a/b ":a"))) - :default (do (is (false? (str/starts-with? 'a/b "b"))) - (is (true? (str/starts-with? 'a/b "a"))))) - #?(:cljs (is (thrown? :default (str/starts-with? :a/b ":a"))) - :default (do (is (false? (str/starts-with? :a/b "b"))) - (is (false? (str/starts-with? :a/b "a"))) - (is (true? (str/starts-with? :a/b ":a"))))))) + + #?@(:cljs + [(is (thrown? :default (str/starts-with? 'ab ":a"))) + (is (thrown? :default (str/starts-with? :ab ":a"))) + (is (thrown? :default (str/starts-with? 'a/b ":a"))) + (is (thrown? :default (str/starts-with? :a/b ":a")))] + :cljr + [(is (thrown? Exception (str/starts-with? 'ab ":a"))) + (is (thrown? Exception (str/starts-with? :ab ":a"))) + (is (thrown? Exception (str/starts-with? 'a/b ":a"))) + (is (thrown? Exception (str/starts-with? :a/b ":a")))] + :default + [(is (false? (str/starts-with? 'ab "b"))) + (is (true? (str/starts-with? 'ab "a"))) + (is (false? (str/starts-with? :ab "b"))) + (is (false? (str/starts-with? :ab "a"))) + (is (true? (str/starts-with? :ab ":a"))) + (is (false? (str/starts-with? 'a/b "b"))) + (is (true? (str/starts-with? 'a/b "a"))) + (is (false? (str/starts-with? :a/b "b"))) + (is (false? (str/starts-with? :a/b "a"))) + (is (true? (str/starts-with? :a/b ":a")))]))) diff --git a/test/clojure/string_test/upper_case.cljc b/test/clojure/string_test/upper_case.cljc index 8bad599..16c6ab2 100644 --- a/test/clojure/string_test/upper_case.cljc +++ b/test/clojure/string_test/upper_case.cljc @@ -14,10 +14,14 @@ (is (= "ASDF" (str/upper-case "asdf"))) (is (= "asdf" s) "original string mutated")) #?(:cljs (is (thrown? :default (str/upper-case :asdf))) + :cljr (is (thrown? Exception (str/upper-case :asdf))) :default (is (= ":ASDF" (str/upper-case :asdf)))) #?(:cljs (is (thrown? :default (str/upper-case :asdf/asdf))) + :cljr (is (thrown? Exception (str/upper-case :asdf/asdf))) :default (is (= ":ASDF/ASDF" (str/upper-case :asdf/asdf)))) #?(:cljs (is (thrown? :default (str/upper-case 'asdf))) + :cljr (is (thrown? Exception (str/upper-case 'asdf))) :default (is (= "ASDF" (str/upper-case 'asdf)))) #?(:cljs (is (thrown? :default (str/upper-case 'asdf/asdf))) + :cljr (is (thrown? Exception (str/upper-case 'asdf/asdf))) :default (is (= "ASDF/ASDF" (str/upper-case 'asdf/asdf))))))