clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
arnaud_bos 2020-04-27T02:03:10.276800Z

There's an example in spec-alpha2's wiki to illustrate select from a literal schema with unqualified keys:

(gen/sample (s/gen (s/select {:a int? :b keyword?} [:a])) 5)
;;=> ({:b :C, :a -1}
;;    {:b :f_/s!, :a -1}
;;    {:b :J8.M+/+88, :a -1}
;;    {:a -2}
;;    {:b :IEcw.l?/X, :a -1})
But at the REPL this is what I get:
(gen/sample (s/gen (s/select {:a int? :b keyword?} [:a])) 5)
Error printing return value (ExceptionInfo) at clojure.test.check.generators/fn (generators.cljc:435).
Couldn't satisfy such-that predicate after 100 tries.
I'm on 8498f9cb352135579b6d3a0a5d15c40e5c2647ce , which seems to be the latest commit on master. Sorry if it's already been reported before. I don't really know where to look for stuff like this.

alexmiller 2020-04-27T02:11:53.277100Z

yeah, there's a bug in this area

👌 1
dspiteself 2020-04-27T14:28:16.279200Z

I am sure you have already seen this, but unqualified keys are not being looked at for closed specs in spec-alpha2

8498f9cb352135579b6d3a0a5d15c40e5c2647ce
(s/register
  :blah/name2
  (s/resolve-spec 'clojure.core/string?))
(s/register
  :blah/Object2
  (s/resolve-spec
    `(s/schema {:name :blah/name2})))
(s/explain :blah/Object2 {:name "hi"} )
;-> Success!
(s/explain :blah/Object2 {:name "hi"} {:closed #{:blah/Object2}})
;-> {:name "hi"} - failed: (subset? (set (keys %)) #{}) spec: :blah/Object2
https://github.com/clojure/spec-alpha2/blob/master/src/main/clojure/clojure/alpha/spec/impl.clj#L452

dspiteself 2020-04-27T14:32:16.280500Z

Creating Specs Programmatically is so pleasant. I have really been enjoying spec-alpha2.

alexmiller 2020-04-27T14:42:48.281100Z

I'm sure there are any number of bugs in the newer stuff right now, it's not done

dspiteself 2020-04-27T14:50:37.282500Z

yep I was just checking if it would be valuable to report it. Thanks for the awesome work.