File tree 2 files changed +39
-3
lines changed
test/clojure/test_clojure
2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 4040
4040
(dissoc bes (key entry))
4041
4041
((key entry) bes)))
4042
4042
(dissoc b :as :or )
4043
- {:keys #(keyword (str %)), :strs str, :syms #(list `quote %)})]
4043
+ {:keys #(if (keyword? %) % (keyword (str %))),
4044
+ :strs str, :syms #(list `quote %)})]
4044
4045
(if (seq bes)
4045
4046
(let [bb (key (first bes))
4046
4047
bk (val (first bes))
4051
4052
(next bes)))
4052
4053
ret))))]
4053
4054
(cond
4054
- (symbol? b) (-> bvec (conj b) (conj v))
4055
+ (symbol? b) (-> bvec (conj (if (namespace b) (symbol (name b)) b)) (conj v))
4056
+ (keyword? b) (-> bvec (conj (symbol (name b))) (conj v))
4055
4057
(vector? b) (pvec bvec b v)
4056
4058
(map? b) (pmap bvec b v)
4057
4059
:else (throw (new Exception (str " Unsupported binding form: " b))))))
4058
4060
process-entry (fn [bvec b] (pb bvec (first b) (second b)))]
4059
4061
(if (every? symbol? (map first bents))
4060
4062
bindings
4061
- (reduce1 process-entry [] bents))))
4063
+ (if-let [kwbs (seq (filter #(keyword? (first %)) bents))]
4064
+ (throw (new Exception (str " Unsupported binding key: " (ffirst kwbs))))
4065
+ (reduce1 process-entry [] bents)))))
4062
4066
4063
4067
(defmacro let
4064
4068
" binding => binding-form init-expr
Original file line number Diff line number Diff line change 31
31
(deftest empty-list-with-:as-destructuring
32
32
(let [{:as x} '()]
33
33
(is (= {} x))))
34
+
35
+ (deftest keywords-in-destructuring
36
+ (let [{:keys [:a :b ]} {:a 1 :b 2 }]
37
+ (is (= 1 a))
38
+ (is (= 2 b))))
39
+
40
+ (deftest namespaced-keywords-in-destructuring
41
+ (let [{:keys [:a/b :c/d ]} {:a/b 1 :c/d 2 }]
42
+ (is (= 1 b))
43
+ (is (= 2 d))))
44
+
45
+ (deftest namespaced-keys-in-destructuring
46
+ (let [{:keys [a/b c/d]} {:a/b 1 :c/d 2 }]
47
+ (is (= 1 b))
48
+ (is (= 2 d))))
49
+
50
+ (deftest namespaced-syms-in-destructuring
51
+ (let [{:syms [a/b c/d]} {'a/b 1 'c/d 2 }]
52
+ (is (= 1 b))
53
+ (is (= 2 d))))
54
+
55
+ (deftest keywords-not-allowed-in-let-bindings
56
+ (is (thrown-with-msg? Exception #"Unsupported binding key: :a"
57
+ (eval '(let [:a 1 ] a))))
58
+ (is (thrown-with-msg? Exception #"Unsupported binding key: :a/b"
59
+ (eval '(let [:a/b 1 ] b)))))
60
+
61
+ (require '[clojure.string :as s])
62
+ (deftest resolve-keyword-ns-alias-in-destructuring
63
+ (let [{:keys [::s/x ::s/y ]} {:clojure.string/x 1 :clojure.string/y 2 }]
64
+ (is (= x 1 ))
65
+ (is (= y 2 ))))
You can’t perform that action at this time.
0 commit comments