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
8 changes: 7 additions & 1 deletion test/clojure/core_test/assoc_bang.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns clojure.core-test.assoc-bang
(:require [clojure.test :refer [deftest testing are]]
(:require [clojure.test :refer [are deftest is testing]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))

(when-var-exists assoc!
Expand Down Expand Up @@ -49,6 +49,12 @@
[1] [0 1 1]
[1] [0 1 1 2 2]))

(testing "cannot assoc! transient after persistent! call"
(let [t (transient {:a 1}), _ (persistent! t)]
(is (thrown? #?(:cljs js/Error :cljr Exception :default Error) (assoc! t :b 2))))
(let [t (transient [1]), _ (persistent! t)]
(is (thrown? #?(:cljs js/Error :cljr Exception :default Error) (assoc! t 0 2)))))

(testing "bad shape"
(are [coll] (thrown? #?(:cljs js/Error :default Exception) (assoc! coll 1 3))
nil
Expand Down
8 changes: 7 additions & 1 deletion test/clojure/core_test/disj_bang.cljc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(ns clojure.core-test.disj-bang
(:require [clojure.test :refer [deftest testing are]]
(:require [clojure.test :refer [are deftest is testing]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))

(when-var-exists disj!
(deftest test-disj!

(testing "nominal cases"
(are [expected set keys] (= expected (persistent! (apply disj! (transient set) keys)))
#{} #{} [nil]
Expand All @@ -15,6 +16,11 @@
#{[3 3]} #{[1 1] 2 [3 3]} [[1 1] 2]
#{: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 (thrown? #?(:cljs js/Error :cljr Exception :default Error) (disj! t 1)))))

(testing "bad shape"
(are [set keys] (thrown? #?(:cljs js/Error :default Exception) (apply disj! set keys))
nil [nil]
Expand Down
7 changes: 5 additions & 2 deletions test/clojure/core_test/dissoc_bang.cljc
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(ns clojure.core-test.dissoc-bang
(:require [clojure.test :refer [deftest testing are]]
(:require [clojure.test :refer [are deftest is testing]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))

(when-var-exists dissoc!

(deftest test-dissoc!

(testing "non-nil"
Expand All @@ -21,6 +20,10 @@
{} {nil nil} [nil]
{} {nil nil} [nil nil]))

(testing "cannot dissoc! transient after persistent! call"
(let [t (transient {:a 1}), _ (persistent! t)]
(is (thrown? #?(:cljs js/Error :cljr Exception :default Error) (dissoc! t :a)))))

(testing "bad shape"
(are [m keys] (thrown? #?(:cljs js/Error :default Exception) (apply dissoc! m keys))
{:a 1} [:a]
Expand Down
38 changes: 38 additions & 0 deletions test/clojure/core_test/persistent_bang.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(ns clojure.core-test.persistent-bang
(:require [clojure.test :refer [are deftest is testing]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))

(when-var-exists persistent!
(deftest test-persistent!

(testing "map"
(are [expected coll] (= expected (persistent! coll))
{} (transient {})
{nil nil} (transient {nil nil})
{:a 1 :b 2} (transient {:a 1 :b 2})))

(testing "vector"
(are [expected coll] (= expected (persistent! coll))
[] (transient [])
[nil] (transient [nil])
[1 2 3] (transient [1 2 3])))

(testing "set"
(are [expected coll] (= expected (persistent! coll))
#{} (transient #{})
#{nil} (transient #{nil})
#{:a :b :c} (transient #{:a :b :c})))

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'll want a test for calling persistent! multiple times on a transient, since that will throw. We don't need to do it for every possible shape, but we do want to capture that behavior, since it's documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, added case for this behavior.

(testing "calling persistent! a second time throws"
(let [coll (transient {}), _ (persistent! coll)]
(is (thrown? #?(:cljs js/Error :cljr Exception :default Error) (persistent! coll)))))

(testing "bad shape"
(are [coll] (thrown? #?(:cljs js/Error :default Exception) (persistent! coll))
nil
{:a 1 :b 2}
[1 2 3]
'(1 2 3)
#{1 2 3}
true
false))))