Skip to content
Open
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
37 changes: 37 additions & 0 deletions test/clojure/core_test/vec.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(ns clojure.core-test.vec
(:require [clojure.test :refer [deftest testing is are]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))

(when-var-exists vec
(deftest test-vec

(testing "vec coll"
(are [expected coll] (= expected (vec coll))
[] nil
[] '()
[] []
[] #{}
[] {}
[] ""
[nil nil nil] '(nil nil nil)
[1 2 3] '(1 2 3)
[1 2 3] [1 2 3]
[1 2 3] (sorted-set 1 2 3)
[1 2 3] (range 1 4)
[[:a 1] [:b 2]] {:a 1 :b 2}
[\a \b \c] "abc"))

#?(:cljr "cljr does not alias array"
:default (testing "array aliasing"
(let [arr (to-array [1 2 3]), v (vec arr)]
(is (= [1 2 3] v))
(aset arr 0 -1)
(is (= [-1 2 3] v)))))
Comment on lines +28 to +29
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small nitpick, even though it's not required, it might be clearer that this mutation and the assertion are related if they were in a do block or logically grouped in some other way like doto). Not a big thing just weird to see mutating code in Clojure without a ! suffix, but I won't block on this


(testing "bad shape"
(are [arg] (thrown? #?(:cljs js/Error :default Exception) (vec arg))
42
3.14
true
:a
(transient [])))))