File tree 3 files changed +30
-17
lines changed
3 files changed +30
-17
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino
14
14
15
15
Malli is in well matured [ alpha] ( README.md#alpha ) .
16
16
17
+ ## NEXT
18
+
19
+ * ** BREAKING** : ` :gen/fmap ` property requires its schema to create a generator.
20
+ * previous behavior defaulted to a ` nil ` -returning generator, even if the schema doesn't accept ` nil `
21
+ * use ` :gen/return nil ` property to restore this behavior
22
+
17
23
## 0.16.4 (2024-08-30)
18
24
19
25
* Distribute ` :merge ` over ` :multi ` [ #1086 ] ( https://github.com/metosin/malli/pull/1086 ) , see [ documentation] ( README.md#distributive-schemas )
Original file line number Diff line number Diff line change 552
552
(defn- -create-from-schema [props options]
553
553
(some-> (:gen/schema props) (generator options)))
554
554
555
- (defn- -create-from-fmap [props schema options]
555
+ (defn- -create-from-fmap [gen props schema options]
556
556
(when-some [fmap (:gen/fmap props)]
557
557
(gen/fmap (m/eval fmap (or options (m/options schema)))
558
- (or (-create-from-return props)
559
- (-create-from-elements props)
560
- (-create-from-schema props options)
561
- (-create-from-gen props schema options)
562
- nil-gen))))
558
+ gen)))
563
559
564
560
(defn- -create [schema options]
565
561
(let [props (-merge (m/type-properties schema)
566
- (m/properties schema))]
567
- (or (-create-from-fmap props schema options)
568
- (-create-from-return props)
569
- (-create-from-elements props)
570
- (-create-from-schema props options)
571
- (-create-from-gen props schema options)
572
- (m/-fail! ::no-generator {:options options
573
- :schema schema}))))
562
+ (m/properties schema))
563
+ gen (or (-create-from-return props)
564
+ (-create-from-elements props)
565
+ (-create-from-schema props options)
566
+ (-create-from-gen props schema options)
567
+ (m/-fail! ::no-generator {:options options
568
+ :schema schema}))]
569
+ (or (-create-from-fmap gen props schema options)
570
+ gen)))
574
571
575
572
; ;
576
573
; ; public api
Original file line number Diff line number Diff line change 241
241
242
242
(testing " generator override"
243
243
(testing " without generator"
244
- (let [schema [:fn {:gen/fmap '(fn [_] (rand-int 10 ))}
244
+ (let [schema [:fn {:gen/elements [5 ]
245
+ :gen/fmap '(fn [i] (rand-int i))}
245
246
'(fn [x] (<= 0 x 10 ))]
246
247
generator (mg/generator schema)]
247
248
(dotimes [_ 100 ]
248
- (m/validate schema (mg/generate generator)))))
249
+ (let [v (mg/generate generator)]
250
+ (is (m/validate schema v))
251
+ (is (<= 0 v 5 ))))))
249
252
(testing " with generator"
250
253
(is (re-matches #"kikka_\d +" (mg/generate [:and {:gen/fmap '(partial str " kikka_" )} pos-int?])))))
251
254
999
1002
1000
1003
(defn alphanumeric-char? [c]
1001
1004
{:pre [(char? c)]}
1002
- (let [i (int c)]
1005
+ (let [int (fn [c]
1006
+ #?(:clj (int c)
1007
+ :cljs (.charCodeAt c 0 )))
1008
+ i (int c)]
1003
1009
(or (<= (int \a) i (int \z))
1004
1010
(<= (int \A) i (int \Z))
1005
1011
(<= (int \0 ) i (int \9 )))))
1006
1012
1013
+ (deftest alphanumeric-char?-test
1014
+ (is (alphanumeric-char? \a))
1015
+ (is (not (alphanumeric-char? \-))))
1016
+
1007
1017
(defn alphanumeric-string? [s]
1008
1018
{:pre [(string? s)]}
1009
1019
(every? alphanumeric-char? s))
You can’t perform that action at this time.
0 commit comments