From bae2e70081d94a19613bfe336420663eac2e67f3 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sun, 1 Dec 2024 22:34:55 -0600 Subject: [PATCH] Close #1121: don't generate nil if :seqable is non-empty --- src/malli/generator.cljc | 8 ++++++-- test/malli/generator_test.cljc | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/malli/generator.cljc b/src/malli/generator.cljc index 140ad94c5..abdc1bf0f 100644 --- a/src/malli/generator.cljc +++ b/src/malli/generator.cljc @@ -145,9 +145,13 @@ (gen/one-of gs))) (defn- -seqable-gen [schema options] - (let [el (-> schema m/children first)] + (let [{:keys [min]} (-min-max schema options) + el (-> schema m/children first)] (gen-one-of - (-> [nil-gen] + (-> [] + (cond-> + (or (nil? min) (zero? min)) + (conj nil-gen)) (into (map #(-coll-gen schema % options)) [identity vec eduction #(into-array #?(:clj Object) %)]) (conj (-coll-distinct-gen schema set options)) diff --git a/test/malli/generator_test.cljc b/test/malli/generator_test.cljc index 73e6fe078..e8c7d90f4 100644 --- a/test/malli/generator_test.cljc +++ b/test/malli/generator_test.cljc @@ -1137,3 +1137,9 @@ [{} :map]]] (is (every? #{{:type nil} {:type {}}} (mg/sample schema))) (is (every? (m/validator schema) (mg/sample schema)))))) + +(deftest seqable-generates-non-empty-with-positive-min-test + (is (seq (mg/generate [:seqable {:min 4 :max 4} :int] {:seed 0}))) + (doseq [_ (range 100) + v (mg/sample [:seqable {:min 1} :any])] + (is (seq v))))