From 61c9422ef6b1f1f240caac8c2d067ca5917ba14a Mon Sep 17 00:00:00 2001 From: Jona Ekenberg Date: Sat, 23 May 2020 19:49:40 +0200 Subject: [PATCH] added syntax for custom generators --- src/ghostwheel/core.cljc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ghostwheel/core.cljc b/src/ghostwheel/core.cljc index d387633..193eedd 100644 --- a/src/ghostwheel/core.cljc +++ b/src/ghostwheel/core.cljc @@ -237,12 +237,15 @@ (s/def ::such-that-op #{:st '|}) (s/def ::ret-op #{:ret '=>}) (s/def ::gen-op #{:gen '<-}) +(s/def ::args-gen-op #{:args-gen '<<}) (s/def ::gspec (s/and vector? (s/cat :args (s/? (s/cat :args (s/+ ::spec-elem) :args-such-that (s/? (s/cat :op ::such-that-op :preds (s/+ ::pred-fn))))) + :args-gen (s/? (s/cat :op ::args-gen-op + :args-gen-fn any?)) :ret-op ::ret-op :ret ::spec-elem :fn-such-that (s/? (s/cat :op ::such-that-op @@ -546,6 +549,7 @@ retspec :ret fn-such-that :fn-such-that {:keys [gen-fn] :as gen} :gen} + {:keys [args-gen-fn] :as args-gen} :args-gen} conformed-gspec] (if (and anon-fspec? argspec-def @@ -633,7 +637,10 @@ final-fspec (concat (when anon-fspec? [`s/fspec]) - [:args processed-args] + (if args-gen-fn + [:args `(s/with-gen ~processed-args + ~args-gen-fn)] + [:args processed-args]) [:ret (extract-spec retspec)] (when fn-spec [:fn fn-spec]) (when gen-fn [:gen gen-fn]))]