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

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

(testing "nominal cases"
(are [expected vec] (= expected (persistent! (pop! (transient vec))))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a test for the count of the transient vector before coercing it to a persistent vector?

Copy link
Member

Choose a reason for hiding this comment

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

This is a gray area, since it could be considered testing count or testing transients in general, rather than pop!. The most important thing is that the value we get out of pop!, when turned persistent, is what we expect.

[] [nil]
[] [1]
[1 2] [1 2 3]
[:c :b] [:c :b :a]))

(testing "cannot pop! empty vector"
(is (thrown? #?(:cljs js/Error :default Exception) (pop! (transient [])))))

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

(testing "bad shapes"
(are [arg] (thrown? #?(:cljs js/Error :default Exception) (pop! arg))
(transient {:a 0})
(transient #{0})
[0]
'(0)
#{0}
(range 3)
true
false
"s"
3.14
42
nil))))