-
Couldn't load subscription status.
- Fork 24
test conj #768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test conj #768
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| (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}))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing map keys can also be updated. |
||
| (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"))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about this one for CLJS? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? 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)))))))) | ||
There was a problem hiding this comment.
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.