mirror of
https://github.com/penpot/penpot.git
synced 2025-06-23 21:26:58 +02:00
✨ Add better defaults for several number schema generators
This commit is contained in:
parent
8f774a3611
commit
d08d2f49ac
2 changed files with 16 additions and 8 deletions
|
@ -702,7 +702,10 @@
|
||||||
(fn [v]
|
(fn [v]
|
||||||
(and (pred v)
|
(and (pred v)
|
||||||
(>= max v)))
|
(>= max v)))
|
||||||
pred)]
|
pred)
|
||||||
|
|
||||||
|
gen (or (get props :gen/gen)
|
||||||
|
(sg/small-int :max max :min min))]
|
||||||
|
|
||||||
{:pred pred
|
{:pred pred
|
||||||
:type-properties
|
:type-properties
|
||||||
|
@ -710,7 +713,7 @@
|
||||||
:description "int"
|
:description "int"
|
||||||
:error/message "expected to be int/long"
|
:error/message "expected to be int/long"
|
||||||
:error/code "errors.invalid-integer"
|
:error/code "errors.invalid-integer"
|
||||||
:gen/gen (sg/small-int :max max :min min)
|
:gen/gen gen
|
||||||
:decode/string parse-long
|
:decode/string parse-long
|
||||||
:decode/json parse-long
|
:decode/json parse-long
|
||||||
::oapi/type "integer"
|
::oapi/type "integer"
|
||||||
|
@ -768,10 +771,11 @@
|
||||||
(>= max v)))
|
(>= max v)))
|
||||||
pred)
|
pred)
|
||||||
|
|
||||||
gen (sg/one-of
|
gen (or (get props :gen/gen)
|
||||||
(sg/small-int :max max :min min)
|
(sg/one-of
|
||||||
(->> (sg/small-double :max max :min min)
|
(sg/small-int :max max :min min)
|
||||||
(sg/fmap #(mth/precision % 2))))]
|
(->> (sg/small-double :max max :min min)
|
||||||
|
(sg/fmap #(mth/precision % 2)))))]
|
||||||
|
|
||||||
{:pred pred
|
{:pred pred
|
||||||
:type-properties
|
:type-properties
|
||||||
|
@ -786,7 +790,9 @@
|
||||||
|
|
||||||
(register! ::safe-int [::int {:max max-safe-int :min min-safe-int}])
|
(register! ::safe-int [::int {:max max-safe-int :min min-safe-int}])
|
||||||
(register! ::safe-double [::double {:max max-safe-int :min min-safe-int}])
|
(register! ::safe-double [::double {:max max-safe-int :min min-safe-int}])
|
||||||
(register! ::safe-number [::number {:max max-safe-int :min min-safe-int}])
|
(register! ::safe-number [::number {:gen/gen (sg/small-double)
|
||||||
|
:max max-safe-int
|
||||||
|
:min min-safe-int}])
|
||||||
|
|
||||||
(defn parse-boolean
|
(defn parse-boolean
|
||||||
[v]
|
[v]
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.schema.registry :as sr]
|
[app.common.schema.registry :as sr]
|
||||||
[app.common.uri :as u]
|
[app.common.uri :as u]
|
||||||
|
[app.common.math :as mth]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[clojure.core :as c]
|
[clojure.core :as c]
|
||||||
[clojure.test.check.generators :as tg]
|
[clojure.test.check.generators :as tg]
|
||||||
|
@ -40,7 +41,8 @@
|
||||||
|
|
||||||
(defn small-double
|
(defn small-double
|
||||||
[& {:keys [min max] :or {min -100 max 100}}]
|
[& {:keys [min max] :or {min -100 max 100}}]
|
||||||
(tg/double* {:min min, :max max, :infinite? false, :NaN? false}))
|
(->> (tg/double* {:min min, :max max, :infinite? false, :NaN? false})
|
||||||
|
(tg/fmap #(mth/precision % 2))))
|
||||||
|
|
||||||
(defn small-int
|
(defn small-int
|
||||||
[& {:keys [min max] :or {min -100 max 100}}]
|
[& {:keys [min max] :or {min -100 max 100}}]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue