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
robertfw 2020-02-28T00:41:41.066200Z

I'm trying to figure out how the overrides map for (s/gen) works, namely for overriding a generator that's down the tree a bit. That is, I have a top level spec ::data which has a key ::things which is a collection of ::thing, which has a key ::properties . I'm generating the top level - ::data - and wanting to override both ::things so I get only 1 thing, and ::properties so I get an empty list. using (s/gen ::data {::things #(s/gen (s/coll-of ::thing :min-count 1 :max-count 1))}), I'm able to force ::things to only have 1 ::thing, but I haven't figured out the incantation needed to have ::properties be empty.

robertfw 2020-02-28T00:50:35.067800Z

The docstring talks about providing a vector of keyword paths, but I haven't been able to find any more detail on what those paths should look like. I've been trying various combinations

robertfw 2020-02-28T01:29:13.070600Z

I suspect the issue is in using (s/coll-of) - for now I'm using an spec.gen/fmap call to remove any extra data I don't want, but would prefer to be able to just generate only the data needed

seancorfield 2020-02-28T01:32:23.071200Z

Your s/gen override for ::things could have a third argument which is the override for ::properties

seancorfield 2020-02-28T01:32:34.071500Z

A bit like this

(s/exercise ::things 10 {::things #(s/gen (s/coll-of ::thing :min-count 1 :max-count 1) {::properties (fn [] (s/gen (s/coll-of string? :min-count 0 :max-count 0)))})})

robertfw 2020-02-28T01:33:01.072Z

gotcha. that makes sense

seancorfield 2020-02-28T01:33:37.072700Z

I would have expected to be able to use [::properties] as a key in the top-level overrides but that doesn't seem to work.

seancorfield 2020-02-28T01:33:51.073100Z

I can't figure it out from the code 😕

robertfw 2020-02-28T01:34:16.073900Z

Yeah I spent some time walking through some spec guts but couldn't unravel it

seancorfield 2020-02-28T01:35:09.074500Z

s/keys and several others build a vector of keys to index into the overrides but I got lost trying to trace through multiple layers

2020-02-28T02:54:14.075300Z

I think it's because the nested s/gen creates a different context that doesn't know about the overrides in the top level s/exercise

alexmiller 2020-02-28T03:01:03.075900Z

^^ this, there's actually a bug around this iirc