Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Recursive spec with clojure.spec
;; on 1.9.0-master-SNAPSHOT
;; bb6d305ffd24d1ce0286d3bf6903b6c68e2c95fd
(require '[clojure.spec :as s])
(s/def ::tag (s/cat :type #{:div}
:attrs map?
:children (s/spec (s/* ::tag))))
(s/explain ::tag [:div {} [[:div {} []]]])
;; In: [2 0] val: [:div {} []] fails spec: _ at: [:children :type] predicate: #{:div}

This comment has been minimized.

Copy link

flipmokid commented Sep 14, 2016

I got it working using

(s/def ::tag (s/cat :type #{:div} :attrs map? :children (s/coll-of ::tag)))


This comment has been minimized.

Copy link

gphilipp commented May 17, 2017

(s/exercise ::tag 2) throws a CompilerException java.lang.StackOverflowError. How can you generate sample data ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.