Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions deps-clr.edn
Original file line number Diff line number Diff line change
@@ -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.*"]}}}}
51 changes: 32 additions & 19 deletions test/clojure/core_test/byte.cljc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,19 +11,20 @@
;; 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.
Expand All @@ -34,14 +36,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
Expand All @@ -53,15 +55,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)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing is weird

;; 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)))])))
7 changes: 5 additions & 2 deletions test/clojure/core_test/double.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
33 changes: 23 additions & 10 deletions test/clojure/core_test/int.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)))])))
12 changes: 8 additions & 4 deletions test/clojure/core_test/shuffle.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
(is (vector? actual))
(is (= (count x) (count actual))))))
(testing "negative cases"
(is (thrown? #?(:cljs :default, :default Exception) (shuffle 1)))
(is (thrown? Exception (shuffle 1)))
#?@(:cljs
[(is (= [] (shuffle nil)))
(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 {})))]))))
15 changes: 13 additions & 2 deletions test/clojure/core_test/str.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
24 changes: 20 additions & 4 deletions test/clojure/core_test/with_out_str.cljc
Original file line number Diff line number Diff line change
@@ -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)))))))
9 changes: 5 additions & 4 deletions test/clojure/string_test/blank_qmark.cljc
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
(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?
(is (true? (str/blank? "")))
(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 ""))))
Expand Down
4 changes: 4 additions & 0 deletions test/clojure/string_test/capitalize.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
28 changes: 23 additions & 5 deletions test/clojure/string_test/ends_with_qmark.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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? :default (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֎" "֎")))
Expand Down
3 changes: 3 additions & 0 deletions test/clojure/string_test/lower_case.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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 :cljs (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))))))
43 changes: 28 additions & 15 deletions test/clojure/string_test/starts_with_qmark.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,44 @@
(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? :default (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" "֎")))
(is (true? (str/starts-with? "a-test" "a")))
(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")))])))
Loading