-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix to make the coercion work properly with s/or #219
bugfix to make the coercion work properly with s/or #219
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This needs a test to verify that it works (and won't regress later). I didn't understand the any?
guard. Could you clarify why it is needed?
I did a bit more of investigation about this Consider these specs: (s/def ::car (st/spec (s/keys :req-un [::doors])))
(s/def ::bike (st/spec (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 #{})))) The issue happened in one of the specs in the test suite that used the Therefore you should be expecting this: (st/coerce ::new-vehicle {:rodas [1 "1" 3]} st/strip-extra-keys-transformer)
;; => {:rodas #{1 "1" 3}} But you will get (st/coerce ::new-vehicle {:rodas [1 "1" 3]} st/strip-extra-keys-transformer)
;; => {:rodas [1 "1" 3]} This happens because the spec created by I'll push some tests. |
The breaking test was
|
@ikitommi Now this is correct, I improved the mechanism to perform the validity check from coerced values and all went more smoothly now. There is no special case to handle. Solve both issues. |
Awesome, thanks! |
Simplified a bit more: f0bd074. Tests pass, does that look correct? |
Sure! Great, seems like |
Fixes #178 . The solution is a bit more convoluted than I expected because of the special case for
clojure.core/any?
forms that would introduce a bug if I stopped the reduce operation when I first get a valid data from a or spec.The example provided in the issue is now working as expected: