Last active
May 17, 2017 19:18
-
-
Save bhb/6cfcb3b38757442aec4ba5db46148699 to your computer and use it in GitHub Desktop.
Recursive spec with clojure.spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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} |
(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
I got it working using
(s/def ::tag (s/cat :type #{:div} :attrs map? :children (s/coll-of ::tag)))