Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions test/clojure/core_test/assoc_bang.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
[1] [0 1 1]
[1] [0 1 1 2 2]))

;; Phel divergence: transients are unguarded (no use-after-persistent! check;
;; non-bang ops permitted). assoc! after persistent! mutates/returns instead of
;; throwing, so skip like :lpy.
#?@(:lpy []
:phel []
:default
[(testing "cannot assoc! transient after persistent! call"
(let [t (transient {:a 1}), _ (persistent! t)]
Expand Down
16 changes: 15 additions & 1 deletion test/clojure/core_test/byte.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,21 @@
1 1.1M
#?@(:cljr [] :default [-1 -1.1M])]))

#?@(:bb
;; Phel divergence: int/long/float/double throw on non-numeric (phel-lang #2224); no bigint-promote/overflow (Bucket B, #2223).
#?@(:phel
[ ;; byte truncates toward zero, then range-checks the truncated int
;; against 127 ... -128. So near-boundary floats round into range.
(is (= -128 (byte -128.000001)))
(is (p/thrown? (byte -129)))
(is (p/thrown? (byte 128)))
(is (= 127 (byte 127.000001)))
;; Check handling of other types
(is (p/thrown? (byte "0")))
(is (p/thrown? (byte :0)))
(is (p/thrown? (byte [0])))
(is (p/thrown? (byte nil)))]

:bb
[] ;; byte constructions goes via boxed argument

:cljr
Expand Down
7 changes: 5 additions & 2 deletions test/clojure/core_test/case.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,8 @@
'quote :quote-foo-result
'foo :quote-foo-result)

(is (p/thrown? (negative-tests ##NaN)))
(is (p/thrown? (negative-tests :something-not-found))))))
;; Phel divergence: case with no matching clause and no default returns nil instead of throwing.
#?(:phel (is (nil? (negative-tests ##NaN)))
:default (is (p/thrown? (negative-tests ##NaN))))
#?(:phel (is (nil? (negative-tests :something-not-found)))
:default (is (p/thrown? (negative-tests :something-not-found)))))))
16 changes: 11 additions & 5 deletions test/clojure/core_test/compare.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,20 @@
;; zero? ['() '()]
)

(is (p/thrown? (compare [] '())))
;; Phel divergence: nil/mixed-type comparison returns a bool; compare on collections returns 0; peek is structural.
#?(:phel (is (= 0 (compare [] '())))
:default (is (p/thrown? (compare [] '()))))
(is (p/thrown? (compare [1] [[]])))
(is (p/thrown? (compare [] {})))
(is (p/thrown? (compare [] #{})))
(when-var-exists sorted-set
(is (p/thrown? (compare #{} (sorted-set)))))
(is (p/thrown? (compare #{1} #{1})))
(is (p/thrown? (compare {1 2} {1 2})))
(is (p/thrown? (compare (range 5) (range 5))))
#?(:phel (is (= 1 (compare #{} (sorted-set))))
:default (is (p/thrown? (compare #{} (sorted-set))))))
#?(:phel (is (= 0 (compare #{1} #{1})))
:default (is (p/thrown? (compare #{1} #{1}))))
#?(:phel (is (= 0 (compare {1 2} {1 2})))
:default (is (p/thrown? (compare {1 2} {1 2}))))
#?(:phel (is (= 1 (compare (range 5) (range 5))))
:default (is (p/thrown? (compare (range 5) (range 5)))))
;; Clojurescript goes into an infinite loop of some sort when compiling this.
#_(is (p/thrown? (compare (range 5) (range)))))))
4 changes: 3 additions & 1 deletion test/clojure/core_test/conj.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
;; Basilisp is fairly liberal with its coercion to map entry,
;; meaning that many two element sequences can be conj'ed to
;; a map.
#?@(:lpy [(is (= {:a 0 :b 1} (conj {:a 0} '(:b 1))))]
;; Phel divergence: conj coerces a 2-element seq into a map entry.
#?@(:phel [(is (= {:a 0 :b 1} (conj {:a 0} '(:b 1))))]
:lpy [(is (= {:a 0 :b 1} (conj {:a 0} '(:b 1))))]
:default [(is (p/thrown? (conj {:a 0} '(:b 1))))])]))

(testing "meta preservation"
Expand Down
10 changes: 10 additions & 0 deletions test/clojure/core_test/conj_bang.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@
#{1 2 3 4} (conj! (transient #{1 2}) 3) 4)))

;; Basilisp does not prevent continuing to use transient vectors after persistent! call
;; Phel divergence: transients are unguarded (no use-after-persistent! check;
;; non-bang ops permitted). conj! after persistent! mutates/returns instead of
;; throwing, so skip like :lpy.
#?@(:lpy []
:phel []
:default
[(testing "cannot conj! after call to persistent!"
(let [coll (transient []), _ (persistent! coll)]
Expand All @@ -69,7 +73,13 @@
(are [coll x] (p/thrown? (conj! coll x))
;; Basilisp is fairly liberal with its coercion to map entry, meaning
;; that many two element sequences can be conj'd to a map.
;; Phel divergence: like Basilisp it coerces a two-element list to a map
;; entry, so (conj! (transient {}) '(:a 1)) returns a value instead of
;; throwing; skip that case. Phel still throws on the set and range cases.
#?@(:lpy []
:phel
[(transient {}) #{:a 1}
(transient {}) (range 2)]
:default
[(transient {}) '(:a 1)
(transient {}) #{:a 1}
Expand Down
5 changes: 4 additions & 1 deletion test/clojure/core_test/contains_qmark.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
(is (= false (contains? nil nil)))
(is (= false (contains? {} nil)))
(is (= false (contains? [] nil)))
#?(:lpy (is (= true (contains? "abc" "a")))
;; Phel divergence: contains? on a string treats the 2nd arg as an index key, so a
;; non-integer like "a" is simply absent — returns false instead of throwing.
#?(:phel (is (= false (contains? "abc" "a")))
:lpy (is (= true (contains? "abc" "a")))
:cljs (is (= false (contains? "abc" "a")))
:default (is (p/thrown? (contains? "abc" "a"))))

Expand Down
4 changes: 3 additions & 1 deletion test/clojure/core_test/count.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
2 "ab")

;; Negative tests
;; Phel divergence: a char literal \a is a 1-char string, so (count \a) returns 1
;; (structural) rather than throwing — exclude it from the throwing cases.
(are [x] (p/thrown? (count x))
1
:a
'a
#?@(:lpy [] :cljs [] :default [\a]))))
#?@(:phel [] :lpy [] :cljs [] :default [\a]))))
7 changes: 6 additions & 1 deletion test/clojure/core_test/denominator.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
(is (= 3 (denominator 2/3)))
(is (= 4 (denominator 3/4)))

#?@(:lpy
;; Phel divergence: int/long/float/double throw on non-numeric (phel-lang #2224); no bigint-promote/overflow (Bucket B, #2223).
;; Phel treats integers as ratios with denominator 1.
#?@(:phel
[(is (= 1 (denominator 1)))
(is (= 1 (denominator 1N)))]
:lpy
[(is (= 1 (denominator 1)))
(is (= 1 (denominator 1N)))]
:default
Expand Down
10 changes: 8 additions & 2 deletions test/clojure/core_test/descendants.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@
#{#?(:bb 'clojure.core_test.descendants/TestDescendantsRecord :default TestDescendantsRecord)} ::record))

(testing "cannot get descendants by type inheritance"
#?@(:lpy
;; Phel divergence: descendants is lenient on a type tag, returns nil instead of throwing.
#?@(:phel
[(is (nil? (descendants TestDescendantsProtocol)))
(is (nil? (descendants Object)))]
:lpy
[(is (nil? (descendants TestDescendantsProtocol)))
(is (p/thrown? (descendants python/object)))]
:cljs
Expand Down Expand Up @@ -114,7 +118,9 @@
nil datatypes ::a))

(testing "cannot get descendants by type inheritance, whether the tag is in h or not"
(are [h] #?(:lpy (p/thrown? (descendants h python/object))
;; Phel divergence: descendants is lenient on a type tag, returns nil instead of throwing.
(are [h] #?(:phel (nil? (descendants h Object))
:lpy (p/thrown? (descendants h python/object))
:cljs (p/thrown? (descendants h js/Object))
:default (p/thrown? (descendants h Object)))
; tag in h
Expand Down
11 changes: 8 additions & 3 deletions test/clojure/core_test/disj_bang.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
#{:a :b} #{:a :b :c} [:c]
#{true nil} #{true false nil} [false]))

(testing "cannot disj! transient after persistent! call"
(let [t (transient #{1 2 3}), _ (persistent! t)]
(is (p/thrown? (disj! t 1)))))
;; Phel divergence: transients are unguarded (no use-after-persistent! check;
;; non-bang ops permitted). disj! after persistent! mutates/returns instead of
;; throwing, so skip like :lpy.
#?@(:phel []
:default
[(testing "cannot disj! transient after persistent! call"
(let [t (transient #{1 2 3}), _ (persistent! t)]
(is (p/thrown? (disj! t 1)))))])

(testing "bad shape"
(are [set keys] (p/thrown? (apply disj! set keys))
Expand Down
6 changes: 4 additions & 2 deletions test/clojure/core_test/dissoc.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
r [:d])))

(testing "bad shape"
;; Phel divergence: dissoc supports sets, so it is lenient there (key absent -> unchanged set).
(are [m keys] (p/thrown? (apply dissoc m keys))
42 [4]
'() [0]
[] [0]
#{:a :b} [:a]
"string" [\s \t]))))
#?@(:phel [] :default [#{:a :b} [:a]])
"string" [\s \t])
#?(:phel (is (= #{:b} (apply dissoc #{:a :b} [:a])))))))
11 changes: 8 additions & 3 deletions test/clojure/core_test/dissoc_bang.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
{} {nil nil} [nil]
{} {nil nil} [nil nil]))

(testing "cannot dissoc! transient after persistent! call"
(let [t (transient {:a 1}), _ (persistent! t)]
(is (p/thrown? (dissoc! t :a)))))
;; Phel divergence: transients are unguarded (no use-after-persistent! check;
;; non-bang ops permitted). dissoc! after persistent! mutates/returns instead of
;; throwing, so skip like :lpy.
#?@(:phel []
:default
[(testing "cannot dissoc! transient after persistent! call"
(let [t (transient {:a 1}), _ (persistent! t)]
(is (p/thrown? (dissoc! t :a)))))])

(testing "bad shape"
(are [m keys] (p/thrown? (apply dissoc! m keys))
Expand Down
7 changes: 6 additions & 1 deletion test/clojure/core_test/double.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
(double -1.0) -1.0M)
(is (NaN? (double ##NaN)))

#?@(:cljr
;; Phel divergence: int/long/float/double throw on non-numeric (phel-lang #2224); no bigint-promote/overflow (Bucket B, #2223).
#?@(:phel
[(is (= 0.0 (double "0")))
(is (p/thrown? (double :0)))]

:cljr
[(is (= 0.0 (double "0")))
(is (p/thrown? (double :0)))]

Expand Down
5 changes: 4 additions & 1 deletion test/clojure/core_test/drop.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@

;; Negative tests
(is (p/thrown? (doall (drop nil (range 0 10)))))
(is (p/thrown? (into [] (drop nil) (range 0 10))))))
;; Phel divergence: the (drop nil) transducer is nil-safe — nil count puns to 0,
;; so nothing is dropped instead of throwing (the eager (drop nil coll) still throws).
#?(:phel (is (= (vec (range 0 10)) (into [] (drop nil) (range 0 10))))
:default (is (p/thrown? (into [] (drop nil) (range 0 10)))))))
6 changes: 5 additions & 1 deletion test/clojure/core_test/empty_qmark.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
(is (= false (empty? "abc")))
(is (= false (empty? #{0 \space "a"})))
(is (= false (empty? [(repeat (range))])))
#?@(:lpy [(is (= false (empty? \space)))
;; Phel divergence: empty?/last/ffirst/fnext nil-safe + structural.
#?@(:phel [(is (= true (empty? 0)))
(is (= false (empty? 0.0)))
(is (= false (empty? \space)))]
:lpy [(is (= false (empty? \space)))
(is (p/thrown? (empty? 0)))
(is (p/thrown? (empty? 0.0)))]
:cljs [(is (= false (empty? \space)))
Expand Down
30 changes: 21 additions & 9 deletions test/clojure/core_test/even_qmark.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@
-120N true))

(testing "invalid"
(are [x] (p/thrown? (even? x))
nil
##Inf
##-Inf
##NaN
1.5
0.2M
#?@(:cljs []
:default [1/2])))))
;; Phel divergence: odd?/even? operate on any number (no int-check); only nil throws.
#?@(:phel
[(are [x] (p/thrown? (even? x))
nil)
(are [x] (boolean? (even? x))
##Inf
##-Inf
##NaN
1.5
0.2M
1/2)]
:default
[(are [x] (p/thrown? (even? x))
nil
##Inf
##-Inf
##NaN
1.5
0.2M
#?@(:cljs []
:default [1/2]))]))))
10 changes: 9 additions & 1 deletion test/clojure/core_test/ffirst.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
(is (= \a (ffirst #{"abcd"}))))

(testing "exceptions"
#?@(:cljs
;; Phel divergence: empty?/last/ffirst/fnext nil-safe + structural.
;; ffirst on a seq of scalars: first elem isn't seqable, so (first scalar) throws;
;; on a seq of ints, (range 0 10)/(range) yield nil (nil-safe first-of-first).
#?@(:phel
[(is (= nil (ffirst (range 0 10))))
(is (= nil (ffirst (range)))) ; infinite lazy seq
(is (p/thrown? (ffirst [:a :b :c])))
(is (p/thrown? (ffirst '(:a :b :c))))]
:cljs
[(is (p/thrown? (ffirst (range 0 10))))
(is (p/thrown? (ffirst (range)))) ; infinite lazy seq
(is (p/thrown? (ffirst [:a :b :c])))
Expand Down
13 changes: 11 additions & 2 deletions test/clojure/core_test/float.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@
:default [(float 0.0) r/min-double]))
(is (NaN? (float ##NaN)))

#?@(:cljr
;; Phel divergence: int/long/float/double throw on non-numeric (phel-lang #2224); no bigint-promote/overflow (Bucket B, #2223).
#?@(:phel
[ ;; No float range overflow: doubles pass through unchanged.
(is (= r/max-double (float r/max-double)))
(is (= ##Inf (float ##Inf)))
(is (= ##-Inf (float ##-Inf)))
(is (= (float 0.0) (float "0")))
(is (p/thrown? (float :0)))]

:cljr
[(is (p/thrown? (float r/max-double)))
(is (p/thrown? (float ##Inf)))
(is (p/thrown? (float ##-Inf)))
(is (= (float 0.0) (float "0")))
(is (p/thrown? (float :0)))]

:lpy
[(is (= r/max-double (float r/max-double)))
(is (= ##Inf (float ##Inf)))
Expand Down
9 changes: 7 additions & 2 deletions test/clojure/core_test/fnext.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@
(is (= nil (fnext #{"abcd"}))))

(testing "exceptions"
#?@(:lpy
;; Phel divergence: empty?/last/ffirst/fnext nil-safe + structural; fnext on int throws.
#?@(:phel
[(is (p/thrown? (fnext 0)))
(is (= nil (fnext \a)))]

:lpy
[(is (p/thrown? (fnext 0)))
(is (= nil (fnext \a)))]

:cljs
[(is (p/thrown? (fnext 0)))]

:default
[(is (p/thrown? (fnext 0)))
(is (p/thrown? (fnext \a)))]))))
11 changes: 9 additions & 2 deletions test/clojure/core_test/gt.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,19 @@
;; JavaScript under the hood) where comparisons are just a bit
;; of a mess. CLR also has some implicit conversions for strings
;; and characters to numbers.
#?@(:cljr
;; Phel divergence: nil/mixed-type comparison returns a bool; compare on collections returns 0; peek is structural.
#?@(:phel
[(is (= true (> 1 nil)))
(is (= false (> nil 1)))
(is (= false (> 1 nil 2)))
(is (= true (> 2 1 nil)))]

:cljr
[(is (p/thrown? (> 1 nil)))
(is (p/thrown? (> nil 1)))
(is (p/thrown? (> 1 nil 2)))
(is (p/thrown? (> 2 1 nil)))]

:lpy
[(is (p/thrown? (> 1 nil)))
(is (p/thrown? (> nil 1)))
Expand Down
11 changes: 9 additions & 2 deletions test/clojure/core_test/gt_eq.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,19 @@
;; `<=` only compares numbers, except in ClojureScript (really
;; JavaScript under the hood) where comparisons are just a bit
;; of a mess.
#?@(:cljr
;; Phel divergence: nil/mixed-type comparison returns a bool; compare on collections returns 0; peek is structural.
#?@(:phel
[(is (= true (>= 1 nil)))
(is (= false (>= nil 1)))
(is (= true (>= 2 1 nil)))
(is (= false (>= nil 2 1)))]

:cljr
[(is (p/thrown? (>= 1 nil)))
(is (p/thrown? (>= nil 1)))
(is (p/thrown? (>= 2 1 nil)))
(is (p/thrown? (>= nil 2 1)))]

:lpy
[(is (p/thrown? (>= 1 nil)))
(is (p/thrown? (>= nil 1)))
Expand Down
Loading
Loading