Skip to content

Commit 024edd1

Browse files
authored
Test pop! (#796)
This closes #397.
1 parent 7fb85bb commit 024edd1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(ns clojure.core-test.pop-bang
2+
(:require [clojure.test :refer [are deftest is testing]]
3+
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
4+
5+
(when-var-exists pop!
6+
(deftest test-pop!
7+
8+
(testing "nominal cases"
9+
(are [expected vec] (= expected (persistent! (pop! (transient vec))))
10+
[] [nil]
11+
[] [1]
12+
[1 2] [1 2 3]
13+
[:c :b] [:c :b :a]))
14+
15+
(testing "cannot pop! empty vector"
16+
(is (thrown? #?(:cljs js/Error :default Exception) (pop! (transient [])))))
17+
18+
(testing "cannot pop! after call to persistent!"
19+
(let [t (transient [0 1]), _ (persistent! t)]
20+
(is (thrown? #?(:cljs js/Error :cljr Exception :default Error) (pop! t)))))
21+
22+
(testing "bad shapes"
23+
(are [arg] (thrown? #?(:cljs js/Error :default Exception) (pop! arg))
24+
(transient {:a 0})
25+
(transient #{0})
26+
[0]
27+
'(0)
28+
#{0}
29+
(range 3)
30+
true
31+
false
32+
"s"
33+
3.14
34+
42
35+
nil))))

0 commit comments

Comments
 (0)