Skip to content

Commit f3816b9

Browse files
committed
add :float humanizer
1 parent dcfc4ba commit f3816b9

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Malli is in well matured [alpha](README.md#alpha).
2121
* previous behavior defaulted to a `nil`-returning generator, even if the schema doesn't accept `nil`
2222
* use `:gen/return nil` property to restore this behavior
2323
* FIX: `malli.registry/{mode,type}` not respected in Babashka [#1124](https://github.com/metosin/malli/issues/1124)
24+
* FIX: `:float` missing humanizer [#1122](https://github.com/metosin/malli/issues/1122)
2425
* Updated dependencies:
2526

2627
```

src/malli/error.cljc

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
max (str "should be at most " max " character" (when (not= 1 max) "s")))))}}
106106
:int {:error/fn {:en (-pred-min-max-error-fn {:pred int?, :message "should be an integer"})}}
107107
:double {:error/fn {:en (-pred-min-max-error-fn {:pred double?, :message "should be a double"})}}
108+
:float {:error/fn {:en (-pred-min-max-error-fn {:pred float?, :message "should be a float"})}}
108109
:boolean {:error/message {:en "should be a boolean"}}
109110
:keyword {:error/message {:en "should be a keyword"}}
110111
:symbol {:error/message {:en "should be a symbol"}}

test/malli/error_test.cljc

+23-22
Original file line numberDiff line numberDiff line change
@@ -372,28 +372,29 @@
372372
(me/humanize)))))
373373

374374
(deftest double-test
375-
(is (= {:a ["should be a double"]
376-
:b ["should be at least 1"]
377-
:c ["should be at most 4"]
378-
:d [["should be at least 1"]
379-
["should be at most 4"]]
380-
:e ["should be a double"]
381-
:f ["should be 4"]}
382-
(-> [:map
383-
[:a :double]
384-
[:b [:double {:min 1}]]
385-
[:c [:double {:max 4}]]
386-
[:d [:vector [:double {:min 1, :max 4}]]]
387-
[:e [:double {:min 1, :max 4}]]
388-
[:f [:double {:min 4, :max 4}]]]
389-
(m/explain
390-
{:a "123"
391-
:b 0.0
392-
:c 5.0
393-
:d [0.0 5.0]
394-
:e "123"
395-
:f 5.0})
396-
(me/humanize)))))
375+
(doseq [t [:double :float]]
376+
(is (= {:a [(str "should be a " (name t))]
377+
:b ["should be at least 1"]
378+
:c ["should be at most 4"]
379+
:d [["should be at least 1"]
380+
["should be at most 4"]]
381+
:e [(str "should be a " (name t))]
382+
:f ["should be 4"]}
383+
(-> [:map
384+
[:a t]
385+
[:b [t {:min 1}]]
386+
[:c [t {:max 4}]]
387+
[:d [:vector [t {:min 1, :max 4}]]]
388+
[:e [t {:min 1, :max 4}]]
389+
[:f [t {:min 4, :max 4}]]]
390+
(m/explain
391+
{:a "123"
392+
:b 0.0
393+
:c 5.0
394+
:d [0.0 5.0]
395+
:e "123"
396+
:f 5.0})
397+
(me/humanize))))))
397398

398399
(deftest any-test
399400
(testing "success"

0 commit comments

Comments
 (0)