Skip to content

Commit 06264b3

Browse files
author
dnolen
committed
support gen overrides by name in addition to path
same as Clojure b0c94544
1 parent 5da67c1 commit 06264b3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main/cljs/cljs/spec.cljs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,22 @@
224224
(defn- gensub
225225
[spec overrides path rmap form]
226226
;;(prn {:spec spec :over overrides :path path :form form})
227-
(let [spec (specize spec)]
227+
(let [spec (c/or (get overrides spec) spec)
228+
spec (specize spec)]
228229
(if-let [g (c/or (get overrides path) (gen* spec overrides path rmap))]
229230
(gen/such-that #(valid? spec %) g 100)
230231
(throw (js/Error. (str "Unable to construct gen at: " path " for: " (abbrev form)))))))
231232

232233
(defn gen
233234
"Given a spec, returns the generator for it, or throws if none can
234235
be constructed. Optionally an overrides map can be provided which
235-
should map paths (vectors of keywords) to generators. These will be
236-
used instead of the generators at those paths. Note that parent
237-
generator (in the spec or overrides map) will supersede those of any
238-
subtrees. A generator for a regex op must always return a
239-
sequential collection (i.e. a generator for s/? should return either
240-
an empty sequence/vector or a sequence/vector with one item in it)"
236+
should map spec names or paths (vectors of keywords) to
237+
generators. These will be used instead of the generators at those
238+
names/paths. Note that parent generator (in the spec or overrides
239+
map) will supersede those of any subtrees. A generator for a regex
240+
op must always return a sequential collection (i.e. a generator for
241+
s/? should return either an empty sequence/vector or a
242+
sequence/vector with one item in it)"
241243
([spec] (gen spec nil))
242244
([spec overrides] (gensub spec overrides [] {::recursion-limit *recursion-limit*} spec)))
243245

0 commit comments

Comments
 (0)