Skip to content

Commit

Permalink
testing st/coerce with s/or specs
Browse files Browse the repository at this point in the history
  • Loading branch information
wandersoncferreira committed Mar 28, 2020
1 parent e925901 commit 49904b4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/cljc/spec_tools/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,23 @@
(st/decode spec "114.0" st/string-transformer)
(st/conform spec "114.0" st/string-transformer)
(st/coerce spec "114.0" st/string-transformer))))))

(s/def ::car (s/keys :req-un [::doors]))
(s/def ::bike (s/keys :req-un [::wheels]))
(s/def ::tires (s/coll-of (s/and int?) :into #{}))
(s/def ::vehicle (s/or :car ::car
:bike ::bike))
(s/def ::new-vehicle (s/map-of
keyword?
(s/or :vehicle ::vehicle
:tires (s/coll-of (s/and int?) :into #{}))))

(deftest issue-179
(testing "st/coerce can work properly with s/or specs"
(let [chevy {:doors 4}]
(is (= (st/coerce ::car chevy st/strip-extra-keys-transformer)
{:doors 4}))
(is (= (st/coerce ::vehicle chevy st/strip-extra-keys-transformer)
{:doors 4}))
(is (= (st/coerce ::new-vehicle {:rodas [1 "1" 3]} st/strip-extra-keys-transformer)
{:rodas #{1 "1" 3}})))))

0 comments on commit 49904b4

Please sign in to comment.