gen/not-empty equivalent for s/Str in schema-generators?

35 views
Skip to first unread message

Sean Grove

unread,
Jul 22, 2016, 4:17:38 PM7/22/16
to Plumbing and Graph: the Clojure utility belt
Right now I'm struggling with the validity of generated data. I have something like this:

{:uid s/Str}



as my description, but really it has to be a non-empty string, such that
(not (empty? (:uid data)))

will pass. Unfortunately, the data generated will generally *start* at the empty string.

Is there a way to easily get schema-generators to restrict the values of generated strings?

Thanks!

Best,
Sean

Jason Wolfe

unread,
Jul 22, 2016, 11:30:26 PM7/22/16
to Sean Grove, Plumbing and Graph: the Clojure utility belt
Hi Sean,

You can use `(s/constrained s/Str seq)`, which will both enforce
non-emptiness and backtrack past generation of empty strings.

If you just want to affect generation, or the constraint is more
stringent (so backtracking is slow and/or eventually fails) then you
can pass a custom generator to the generation process instead. E.g.

(def UID (s/named String 'UID))

and then you can pass a custom generator map `{UID my-uid-generator}`
into generation or completion.

Is that what you're looking for?

Cheers,
Jason
> --
> You received this message because you are subscribed to the Google Groups
> "Plumbing and Graph: the Clojure utility belt" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to prismatic-plumb...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages