Skip to content

Commit a54a567

Browse files
dmillerE-A-Griffin
andauthored
Additional edits for ClojureCLR tests (#107)
* Additional edits for ClojureCLR tests * Fix formatting * Cleanup with-out-str * Cleanup blank_qmark * Cleanup byte * Cleanup 2 * Fix whitespace * Fix cljs shuffle * Fix clj --------- Co-authored-by: Emma Griffin <emma.audrey.g@gmail.com>
1 parent b908bb1 commit a54a567

15 files changed

+183
-70
lines changed

deps-clr.edn

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{:deps {}
2+
:aliases
3+
{:test
4+
{:extra-paths ["test"]
5+
:extra-deps {io.github.dmiller/test-runner {:git/sha "c055ea13d19c6a9b9632aa2370fcc2215c8043c3"}}
6+
:exec-fn cognitect.test-runner.api/test
7+
:exec-args {:dirs ["test"]
8+
:patterns [".*test.*"]}}}}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/clojure/core_test/byte.cljc

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns clojure.core-test.byte
2-
(:require [clojure.test :as t :refer [deftest testing is are]]
3-
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
2+
(:require [clojure.test :as t :refer [deftest is are]]
3+
[clojure.core-test.portability
4+
#?(:cljs :refer-macros :default :refer) [when-var-exists]]))
45

56
(when-var-exists clojure.core/byte
67
(deftest test-byte
@@ -10,19 +11,21 @@
1011
;; test whether it's a fixed-length integer of some sort.
1112
(is (int? (byte 0)))
1213
#?(:clj (is (instance? java.lang.Byte (byte 0)))
13-
:cljr (is (instance? System.Byte (byte 0))))
14+
:cljr (is (instance? System.Byte (byte 0))))
1415

1516
;; Check conversions and rounding from other numeric types
17+
;; In ClojureCLR, Byte is unsigned, so we have to wipe all tests
18+
;; of negative values
1619
(are [expected x] (= expected (byte x))
17-
-128 -128
20+
#?@(:cljr [] :default [-128 -128])
1821
0 0
1922
127 127
2023
1 1N
2124
0 0N
22-
-1 -1N
25+
#?@(:cljr [] :default [-1 -1N])
2326
1 1.0M
2427
0 0.0M
25-
-1 -1.0M
28+
#?@(:cljr [] :default [-1 -1.0M])
2629
;; Clojurescript `byte` is a "dummy cast" which doesn't do
2730
;; anything (no-op). Thus, there is no conversion, no truncation
2831
;; of decimal values, etc.
@@ -34,14 +37,14 @@
3437
-1.1 -1.1M]
3538
:default
3639
[1 1.1
37-
-1 -1.1
40+
#?@(:cljr [] :default [-1 -1.1])
3841
1 1.9
3942
1 3/2
40-
-1 -3/2
43+
#?@(:cljr [] :default [-1 -3/2])
4144
0 1/10
42-
0 -1/10
45+
#?@(:cljr [] :default [0 -1/10])
4346
1 1.1M
44-
-1 -1.1M]))
47+
#?@(:cljr [] :default [-1 -1.1M])]))
4548

4649
#?@(:cljs
4750
[ ;; ClojureScript `byte` just returns its argument
@@ -53,15 +56,26 @@
5356
(is (= :0 (byte :0)))
5457
(is (= [0] (byte [0])))
5558
(is (= nil (byte nil)))]
56-
:bb [] ;; byte constructions goes via boxed argument
59+
:cljr
60+
[ ;; `byte` throws outside the range of 127 ... -128.
61+
(is (thrown? Exception (byte -128.000001)))
62+
(is (thrown? Exception (byte -129)))
63+
(is (= 128 (byte 128)))
64+
(is (= 127(byte 127.000001)))
65+
;; Check handling of other types
66+
(is (= 0 (byte "0")))
67+
(is (thrown? Exception (byte :0)))
68+
(is (thrown? Exception (byte [0])))
69+
(is (thrown? Exception (byte nil)))]
70+
:bb [] ;; byte constructions goes via boxed argument
5771
:default
5872
[ ;; `byte` throws outside the range of 127 ... -128.
59-
(is (thrown? #?(:clj Exception :cljr Exception) (byte -128.000001)))
60-
(is (thrown? #?(:clj Exception :cljr Exception) (byte -129)))
61-
(is (thrown? #?(:clj Exception :cljr Exception) (byte 128)))
62-
(is (thrown? #?(:clj Exception :cljr Exception) (byte 127.000001)))
73+
(is (thrown? Exception (byte -128.000001)))
74+
(is (thrown? Exception (byte -129)))
75+
(is (thrown? Exception (byte 128)))
76+
(is (thrown? Exception (byte 127.000001)))
6377
;; Check handling of other types
64-
(is (thrown? #?(:clj Exception :cljr Exception) (byte "0")))
65-
(is (thrown? #?(:clj Exception :cljr Exception) (byte :0)))
66-
(is (thrown? #?(:clj Exception :cljr Exception) (byte [0])))
67-
(is (thrown? #?(:clj Exception :cljr Exception) (byte nil)))])))
78+
(is (thrown? Exception (byte "0")))
79+
(is (thrown? Exception (byte :0)))
80+
(is (thrown? Exception (byte [0])))
81+
(is (thrown? Exception (byte nil)))])))

test/clojure/core_test/double.cljc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
;; In cljs, `double` is just returns the argument unchanged (dummy fn)
2424
[(is (= "0" (double "0")))
2525
(is (= :0 (double :0)))]
26+
:cljr
27+
[(is (= 0.0 (double "0")))
28+
(is (thrown? Exception (double :0)))]
2629
:default
27-
[(is (thrown? #?(:clj Exception :cljr Exception) (double "0")))
28-
(is (thrown? #?(:clj Exception :cljr Exception) (double :0)))])
30+
[(is (thrown? Exception (double "0")))
31+
(is (thrown? Exception (double :0)))])
2932

3033
#?@(:clj
3134
[(is (instance? java.lang.Double (double 0)))

test/clojure/core_test/int.cljc

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
;; predicate for it. Here, we just test whether it's a fixed-length
1212
;; integer of some sort.
1313
(is (int? (int 0)))
14-
#?(:clj (is (instance? java.lang.Integer (int 0))))
14+
#?(:clj (is (instance? java.lang.Integer (int 0)))
15+
:cljr (is (instance? System.Int32 (int 0))))
1516

1617
;; Check conversions and rounding from other numeric types
1718
(are [expected x] (= expected (int x))
@@ -40,16 +41,28 @@
4041
0 -1/10]))
4142

4243
#?@(:cljs []
43-
:bb []
44+
:bb []
45+
:cljr
46+
[ ;; `int` throws outside the range of 32767 ... -32768.
47+
(is (thrown? Exception (int -2147483648.000001)))
48+
(is (thrown? Exception (int -2147483649)))
49+
(is (thrown? Exception (int 2147483648)))
50+
(is (thrown? Exception (int 2147483647.000001)))
51+
52+
;; Check handling of other types
53+
(is (= 0 (int "0")))
54+
(is (thrown? Exception (int :0)))
55+
(is (thrown? Exception (int [0])))
56+
(is (thrown? Exception (int nil)))]
4457
:default
4558
[ ;; `int` throws outside the range of 32767 ... -32768.
46-
(is (thrown? #?(:clj Exception :cljr Exception) (int -2147483648.000001)))
47-
(is (thrown? #?(:clj Exception :cljr Exception) (int -2147483649)))
48-
(is (thrown? #?(:clj Exception :cljr Exception) (int 2147483648)))
49-
(is (thrown? #?(:clj Exception :cljr Exception) (int 2147483647.000001)))
59+
(is (thrown? Exception (int -2147483648.000001)))
60+
(is (thrown? Exception (int -2147483649)))
61+
(is (thrown? Exception (int 2147483648)))
62+
(is (thrown? Exception (int 2147483647.000001)))
5063

5164
;; Check handling of other types
52-
(is (thrown? #?(:clj Exception :cljr Exception) (int "0")))
53-
(is (thrown? #?(:clj Exception :cljr Exception) (int :0)))
54-
(is (thrown? #?(:clj Exception :cljr Exception) (int [0])))
55-
(is (thrown? #?(:clj Exception :cljr Exception) (int nil)))])))
65+
(is (thrown? Exception (int "0")))
66+
(is (thrown? Exception (int :0)))
67+
(is (thrown? Exception (int [0])))
68+
(is (thrown? Exception (int nil)))])))

test/clojure/core_test/shuffle.cljc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323
(is (vector? actual))
2424
(is (= (count x) (count actual))))))
2525
(testing "negative cases"
26-
(is (thrown? #?(:cljs :default, :default Exception) (shuffle 1)))
26+
#?(:cljs (is (thrown? js/Error (shuffle 1)))
27+
:default (is (thrown? Exception (shuffle 1))))
2728
#?@(:cljs
2829
[(is (= [] (shuffle nil)))
29-
(is [] (shuffle {}))]
30+
(is (= [] (shuffle {})))]
31+
:cljr
32+
[(is (thrown? Exception (shuffle nil)))
33+
(is (thrown? Exception (shuffle "abc")))
34+
(is (= [] (shuffle {})))]
3035
:default
31-
[(is (thrown? #?(:cljs :default, :default Exception) (shuffle nil)))
32-
(is (thrown? #?(:cljs :default, :default Exception) (shuffle "abc")))
33-
(is (thrown? #?(:cljs :default, :default Exception) (shuffle {})))]))))
36+
[(is (thrown? Exception (shuffle nil)))
37+
(is (thrown? Exception (shuffle "abc")))
38+
(is (thrown? Exception (shuffle {})))]))))

test/clojure/core_test/str.cljc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
"0" (double 0.0)
2020
"1" (double 1.0)
2121
"-1" (double -1.0)]
22+
:cljr
23+
["0" 0.0
24+
"1" 1.0
25+
"-1" -1.0
26+
"0" 0.00000
27+
"0" (float 0.0)
28+
"1" (float 1.0)
29+
"-1" (float -1.0)
30+
"0" (double 0.0)
31+
"1" (double 1.0)
32+
"-1" (double -1.0)]
2233
:default
2334
["0.0" 0.0
2435
"1.0" 1.0
@@ -49,8 +60,8 @@
4960
"-1.0" -1.0M])
5061

5162
"" nil
52-
"true" true
53-
"false" false
63+
#?(:cljr "True" :default "true") true
64+
#?(:cljr "False" :default "false") false
5465
"a string" "a string"
5566
"0" "0"
5667
"1" "1"
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
(ns clojure.core-test.with-out-str
2-
(:require [clojure.test :as t :refer [deftest testing is are]]
3-
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
2+
(:require [clojure.test :as t :refer [deftest is]]
3+
[clojure.core-test.portability
4+
#?(:cljs :refer-macros :default :refer) [when-var-exists]]))
5+
6+
;; This is part of clojure.test-helpers, but I couldn't figure out how to
7+
;; :require or :use that library.
8+
;; Copied here for now
9+
(defn platform-newlines [s]
10+
#?(:clj
11+
(let [nl (System/getProperty "line.separator")]
12+
(.replace s "\n" nl))
13+
:cljr
14+
(let [nl Environment/NewLine] ;;; (System/getProperty "line.separator")]
15+
(.Replace ^String s "\n" nl)) ;;; .replace, add type hint
16+
:default
17+
s))
18+
419

520
(when-var-exists clojure.core/with-out-str
621
(deftest test-with-out-str
7-
(is (= (str "some sample :text here" \newline
8-
"[:a :b] {:c :d} #{:e} (:f)" \newline)
22+
(is (= (platform-newlines
23+
(str "some sample :text here" \newline
24+
"[:a :b] {:c :d} #{:e} (:f)" \newline))
925
(with-out-str
1026
(println "some" "sample" :text 'here)
1127
(prn [:a :b] {:c :d} #{:e} '(:f)))))))

test/clojure/core_test/with_precision.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(ns clojure.core-test.with-precision
22
(:require [clojure.test :as t :refer [deftest testing is are]]
3-
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
3+
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
44

5-
(when-var-exists clojure.core/with-precision
5+
(when-var-exists with-precision
66
(deftest test-with-precision
77
;; tests copied from https://clojuredocs.org/clojure.core/with-precision
88
(is (= 2M (with-precision 1 :rounding UP (* 1.1M 1M))))

test/clojure/string_test/blank_qmark.cljc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
(ns clojure.string-test.blank-qmark
22
(:require [clojure.string :as str]
3-
[clojure.test :as t :refer [deftest testing is are]]
4-
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
3+
[clojure.test :as t :refer [deftest testing is]]
4+
[clojure.core-test.portability
5+
#?(:cljs :refer-macros :default :refer) [when-var-exists]]))
56

67
(when-var-exists str/blank?
78
(deftest test-blank?
89
(is (true? (str/blank? "")))
910
(is (true? (str/blank? nil)))
1011
(is (false? (str/blank? "֎")))
1112
(testing "U+2007"
12-
(is (#?(:cljs true? :cljr true :default false?) (str/blank? "")))
13-
(is (#?(:cljs true? :cljr true :default false?) (str/blank? "\u2007"))))
13+
(is (#?(:cljs true? :cljr true? :default false?) (str/blank? "")))
14+
(is (#?(:cljs true? :cljr true? :default false?) (str/blank? "\u2007"))))
1415
(is (true? (str/blank? " ")))
1516
(is (true? (str/blank? " \t ")))
1617
#?(:cljs (do (is (true? (str/blank? (symbol ""))))

0 commit comments

Comments
 (0)