Skip to content

Commit

Permalink
Merge pull request #245 from wandersoncferreira/bugfix/defensive-impl
Browse files Browse the repository at this point in the history
more defensive impl for type-priority in parse-form merge
  • Loading branch information
ikitommi authored Nov 7, 2020
2 parents 3c813bc + 4462b12 commit 65bb923
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/spec_tools/parse.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@
::items specs}))

(defmethod parse-form 'clojure.spec.alpha/merge [_ form options]
(let [type-priority #((:type %) {:map 0
:multi-spec 1} 0)]
(let [type-priority #(if (= (:type %) :multi-spec) 1 0)]
(apply impl/deep-merge (->> (rest form)
(map #(parse-spec % options))
(sort-by type-priority)))))
Expand Down
14 changes: 14 additions & 0 deletions test/cljc/spec_tools/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,20 @@
(is (st/spec? (st/merge ::qix ::qux)))
(is (st/spec? (st/merge qix ::qux))))))

(s/def ::a242 int?)
(s/def ::b242 int?)
(s/def ::c242 int?)

(deftest issue-242
(testing "parse-form should continue to work with [:or [:map]] specs"
(let [desired-spec (st/spec (s/merge (s/or :one (s/keys :req-un [::a242])
:two (s/keys :req-un [::b242]))
(s/keys :req-un [::c242])))]
(is (s/valid? desired-spec {:a242 1 :c242 2}))
(is (not (s/valid? desired-spec {:c242 2})))
(is (s/valid? desired-spec {:b242 2 :c242 3}))
(is (not (s/valid? desired-spec {:a242 1}))))))

(s/def ::rec-pattern (s/coll-of (s/or :atr qualified-keyword?
:ref (s/map-of qualified-keyword?
(s/or :rec-pattern ::rec-pattern)))))
Expand Down

0 comments on commit 65bb923

Please sign in to comment.