When using regular expression operators (s/alt
s/cat
etc ) to describe sequences, s/with-gen
doesn't work as I would have expected. It completely ignores the generator passed to the definition. Eg:
(require '[clojure.alpha.spec :as s])
(require '[clojure.alpha.spec.gen :as gen])
(s/def ::some-spec
(s/with-gen string? (constantly (gen/return "olar"))))
(gen/sample (s/gen ::some-spec))
;;=> ("olar" "olar" "olar" "olar" "olar" "olar" "olar" "olar" "olar" "olar")
The above generator works as I would expected, now if we try to create a similar one for s/alt we get unexpected results:
(s/def ::some-other-spec
(s/with-gen
(s/alt :greetings #{:olar :oizito :oi :hello :hey :yo :hallo}
:farewell #{:bye :bye-bye :hasta-la-vista :tchussy :tchau-kakao})
(constantly (gen/return [:tchau-kakao]))))
(gen/sample (s/gen ::some-other-spec))
;;=> => ([:olar] [:hasta-la-vista] [:hallo] [:hallo] [:tchussy] [:oi] [:bye-bye] [:tchussy] [:tchau-kakao] [:yo])
Is this a bug or is it expected somehow?