forked from jank-lang/clojure-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdissoc_bang.cljc
More file actions
42 lines (37 loc) · 1.67 KB
/
Copy pathdissoc_bang.cljc
File metadata and controls
42 lines (37 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(ns clojure.core-test.dissoc-bang
(:require [clojure.test :refer [are deftest is testing]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists] :as p]))
(when-var-exists dissoc!
(deftest test-dissoc!
(testing "non-nil"
(are [expected m keys] (= expected (persistent! (apply dissoc! (transient m) keys)))
{} {} [:a]
{} {:a 1} [:a]
{} {:a 1} [:a :a]
{} {:a 1 :b 2} [:a :b]
{:b 2} {:a 1 :b 2} [:a]
{:b 2} {:a 1 :b 2} [:a :c]))
(testing "nil"
(are [expected m keys] (= expected (persistent! (apply dissoc! (transient m) keys)))
{} {} [nil]
{} {nil nil} [nil]
{} {nil nil} [nil nil]))
;; Phel divergence: transients are unguarded (no use-after-persistent! check;
;; non-bang ops permitted). dissoc! after persistent! mutates/returns instead of
;; throwing, so skip like :lpy.
#?@(:phel []
:default
[(testing "cannot dissoc! transient after persistent! call"
(let [t (transient {:a 1}), _ (persistent! t)]
(is (p/thrown? (dissoc! t :a)))))])
(testing "bad shape"
(are [m keys] (p/thrown? (apply dissoc! m keys))
{:a 1} [:a]
[0] [0]
(transient [0]) [0]
'(0) [0]
#{:a :b} [:a]
(transient #{:a :b}) [:a]
42 [4]
:k [:k]
"string" [\s \t]))))