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

(when-var-exists conj
(deftest test-conj
Copy link
Member

Choose a reason for hiding this comment

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

I think we can have a test for adding to the front of an infinite seq. For example (conj (range) -1)) is valid.

(testing "common"
(is (= [] (conj)))
(is (= nil (conj nil)))
(is (= '(nil) (conj nil nil)))
(is (= {} (conj {})))
(is (= #{} (conj #{})))
(is (= '() (conj '())))
(is (= '(3) (conj nil 3)))
(is (= '([1 2]) (conj nil [1 2])))
(is (= [1 2 3 4] (conj [1 2 3] 4)))
(is (= '(4 1 2 3) (conj '(1 2 3) 4)))
(is (= '(\f \e \d \a \b \c) (conj '(\a \b \c) \d \e \f)))
(is (= [[1 2] [3 4] [5 6]] (conj [[1 2] [3 4]] [5 6])))
(is (= {:a 0 :b 1} (conj {:a 0} [:b 1])))
(is (= {:a 0 :b 1} (conj {:a 0} {:b 1})))
Copy link
Member

Choose a reason for hiding this comment

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

Existing map keys can also be updated. (conj {:a 0} {:a 1}), for example.

(is (= #{1 #{2}} (conj #{1} #{2})))
(is (= {:a 1} (conj {:a 0} {:a 1})))
(is (= {:a 2} (conj {:a 0} {:a 1} {:a 2})))
(is (= ["a" "b" "c" ["d" "e" "f"]] (conj ["a" "b" "c"] ["d" "e" "f"])))

#?@(:cljs [(is (thrown? js/Error (conj \a \b)))
(is (thrown? js/Error (conj 1 2)))
(is (thrown? js/Error (conj :a :b)))
(is (thrown? js/Error (conj {:a 0} '(:b 1))))]

:default [(is (thrown? Exception (conj "a" "b")))
Copy link
Member

Choose a reason for hiding this comment

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

What about this one for CLJS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't include one because in cljs a character is a string, so the test (is (thrown? js/Error (conj \a \b))) basically covers strings as well. Another test with strings seemed a bit redundant, but I can include it if you want

(is (thrown? Exception (conj \a \b)))
(is (thrown? Exception (conj 1 2)))
(is (thrown? Exception (conj :a :b)))
(is (thrown? Exception (conj {:a 0} '(:b 1))))]))

(when-var-exists clojure.core/first
(testing "first"
(is (= -1 (first (conj (range) -1))))))))