Skip to content

Commit 0b69456

Browse files
authored
Merge pull request #1142 from frenchy64/float-explainer
add :float humanizer
2 parents 13984e4 + f3816b9 commit 0b69456

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
@@ -22,6 +22,7 @@ Malli is in well matured [alpha](README.md#alpha).
2222
* use `:gen/return nil` property to restore this behavior
2323
* Support decoding map keys into keywords for `[:map` schemas in `json-transformer` [#1135](https://github.com/metosin/malli/issues/1135)
2424
* FIX: `malli.registry/{mode,type}` not respected in Babashka [#1124](https://github.com/metosin/malli/issues/1124)
25+
* FIX: `:float` missing humanizer [#1122](https://github.com/metosin/malli/issues/1122)
2526
* Updated dependencies:
2627

2728
```

src/malli/error.cljc

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
negated "should be a string")))}}
136136
:int {:error/fn {:en (-pred-min-max-error-fn {:pred int?, :message "should be an integer"})}}
137137
:double {:error/fn {:en (-pred-min-max-error-fn {:pred double?, :message "should be a double"})}}
138+
:float {:error/fn {:en (-pred-min-max-error-fn {:pred float?, :message "should be a float"})}}
138139
:boolean {:error/message {:en "should be a boolean"}}
139140
:keyword {:error/message {:en "should be a keyword"}}
140141
:symbol {:error/message {:en "should be a symbol"}}

test/malli/error_test.cljc

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

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

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

0 commit comments

Comments
 (0)