Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
:url "https://github.com/jank-lang/clojure-test-suite"
:license {:name "MPL 2.0"
:url "https://www.mozilla.org/en-US/MPL/2.0/"}
:clr {:main-cmd ["Clojure.Main"]
:compile-cmd ["Clojure.Compile"]}
:dependencies [[org.clojure/clojure "1.12.0"]
[org.clojure/clojurescript "1.12.42"]]
:plugins [[com.jakemccrary/lein-test-refresh "0.25.0"]])
:plugins [[com.jakemccrary/lein-test-refresh "0.25.0"]
[lein-clr "0.2.2"]])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added these changes to make cljr development easier for myself

104 changes: 87 additions & 17 deletions test/clojure/core_test/num.cljc
Original file line number Diff line number Diff line change
@@ -1,26 +1,96 @@
(ns clojure.core-test.num
(:require [clojure.test :as t :refer [deftest is]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
(:require [clojure.test :as t :refer [are deftest is testing]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])
(:import #?(:cljr [Assigner AssignObject])))

(defn f [])

#?(:clj
(do
(definterface IChecker
(isLong [^long l])
(isLong [^Object l])

(isDouble [^double d])
(isDouble [^Object d]))

(deftype Checker []
IChecker
(isLong [this ^long l] true)
(isLong [this ^Object l] false)
(isDouble [this ^double d] true)
(isDouble [this ^Object d] false))))

(when-var-exists num
(deftest test-num
(testing "positive cases"
#?@(:cljs []
:clj
;; The compiler should pass `x` as a primitive to `num`.
[(let [x 1.0]
(is (instance? java.lang.Double (num x))))
(let [x 1]
(is (instance? java.lang.Long (num x))))
[(testing "longs"
(let [l (long 1)
L (num l)
checker (Checker.)]
(is (.isLong checker l))
(is (false? (.isLong checker L)))))
(testing "doubles"
(let [d (double 1.0)
D (num d)
checker (Checker.)]
(is (.isDouble checker d))
(is (false? (.isDouble checker D)))))
;; `BigInt` and `BigDecimal` are always boxed and `num` just returns them as-is.
(is (instance? clojure.lang.BigInt (num 1N)))
(is (instance? java.math.BigDecimal (num 1.0M)))]
:cljr
;; The compiler should pass `x` as a primitive to `num`.
[(let [x 1.0]
(is (instance? System.Double (num x))))
(let [x 1]
(is (instance? System.Int64 (num x))))
;; `BigInt` and `BigDecimal` are always boxed and `num` just returns them as-is.
(is (instance? clojure.lang.BigInt (num 1N)))
(is (instance? clojure.lang.BigDecimal (num 1.0M)))]
:default (is false "TODO test num"))))
;; By default assume that other platforms are no-ops for numeric inputs
:default (are [n] (and (= n (num n))
(= (type n) (type (num n))))
0
0.1
1/2
1N
1.0M
(short 1)
(byte 1)
(int 1)
(long 1)
(float 1.0)
(double 1.0)
##NaN
##Inf))
(testing "exceptions thrown"
;; [[num]] is a true no-op in `cljr`, equivalent to [[identity]]
#?@(:cljs
nil

:cljr
(are [x] (and (= x (num x))
(= (type x) (type (num x))))
(fn [])
f
{}
#{}
[]
'()
nil
\1
\a
""
"1"
#""
'a)

:default
(are [x] (thrown? Exception (num x))
(fn [])
f
{}
#{}
[]
'()
nil
\1
\a
""
"1"
#""
'a))))))
Loading