Fork me on GitHub
#clojure-spec
<
2019-08-29
>
joefromct20:08:55

is there a way to make a recursive spec to generate the output from clojure.data.xml ?

joefromct20:08:07

not sure what i’m doing wrong there

Alex Miller (Clojure team)20:08:42

you might try limiting the collection sizes

Alex Miller (Clojure team)20:08:00

(s/def ::attrs (s/map-of keyword? string? :gen-max 3))

Alex Miller (Clojure team)20:08:18

(s/def ::content (s/coll-of ::a-content :kind vector? :gen-max 3))

Alex Miller (Clojure team)20:08:02

oh, it's probably that the unqualified keys are foiling the recursion limiter

Alex Miller (Clojure team)20:08:37

try it with :req and see if that works

joefromct20:08:45

hmm.. no luck with req and gen-max 3

(s/def ::tag       keyword?)
(s/def ::attrs (s/map-of keyword? string? :gen-max 3))
(s/def ::a-content (s/keys :req [::tag ::attrs ::content] ))
(s/def ::content (s/coll-of ::a-content :kind vector? :gen-max 3))

(->> ::content
     s/gen
     gen/generate
     (binding [s/*recursion-limit* 1]))

;;=> Execution error (StackOverflowError) at clojure.test.check.generators/tuple
;;(generators.cljc:534).

Alex Miller (Clojure team)20:08:48

We have some open tickets about SO on recursive gen. I have not dug into any of them recently

joefromct20:08:51

ok sounds good, i’ll keep an eye out.

joefromct20:08:11

i appreciate how you always try to respond when i’m sure your busy with strange loop very soon.

joefromct20:08:29

i hope i don’t miss it this year because i’m stuck in a tube in the museum. j/k