Skip to content

Commit

Permalink
Merge pull request #1142 from frenchy64/float-explainer
Browse files Browse the repository at this point in the history
add :float humanizer
  • Loading branch information
ikitommi authored Dec 8, 2024
2 parents 13984e4 + f3816b9 commit 0b69456
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Malli is in well matured [alpha](README.md#alpha).
* use `:gen/return nil` property to restore this behavior
* Support decoding map keys into keywords for `[:map` schemas in `json-transformer` [#1135](https://github.com/metosin/malli/issues/1135)
* FIX: `malli.registry/{mode,type}` not respected in Babashka [#1124](https://github.com/metosin/malli/issues/1124)
* FIX: `:float` missing humanizer [#1122](https://github.com/metosin/malli/issues/1122)
* Updated dependencies:

```
Expand Down
1 change: 1 addition & 0 deletions src/malli/error.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
negated "should be a string")))}}
:int {:error/fn {:en (-pred-min-max-error-fn {:pred int?, :message "should be an integer"})}}
:double {:error/fn {:en (-pred-min-max-error-fn {:pred double?, :message "should be a double"})}}
:float {:error/fn {:en (-pred-min-max-error-fn {:pred float?, :message "should be a float"})}}
:boolean {:error/message {:en "should be a boolean"}}
:keyword {:error/message {:en "should be a keyword"}}
:symbol {:error/message {:en "should be a symbol"}}
Expand Down
45 changes: 23 additions & 22 deletions test/malli/error_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -373,28 +373,29 @@
(me/humanize)))))

(deftest double-test
(is (= {:a ["should be a double"]
:b ["should be at least 1"]
:c ["should be at most 4"]
:d [["should be at least 1"]
["should be at most 4"]]
:e ["should be a double"]
:f ["should be 4"]}
(-> [:map
[:a :double]
[:b [:double {:min 1}]]
[:c [:double {:max 4}]]
[:d [:vector [:double {:min 1, :max 4}]]]
[:e [:double {:min 1, :max 4}]]
[:f [:double {:min 4, :max 4}]]]
(m/explain
{:a "123"
:b 0.0
:c 5.0
:d [0.0 5.0]
:e "123"
:f 5.0})
(me/humanize)))))
(doseq [t [:double :float]]
(is (= {:a [(str "should be a " (name t))]
:b ["should be at least 1"]
:c ["should be at most 4"]
:d [["should be at least 1"]
["should be at most 4"]]
:e [(str "should be a " (name t))]
:f ["should be 4"]}
(-> [:map
[:a t]
[:b [t {:min 1}]]
[:c [t {:max 4}]]
[:d [:vector [t {:min 1, :max 4}]]]
[:e [t {:min 1, :max 4}]]
[:f [t {:min 4, :max 4}]]]
(m/explain
{:a "123"
:b 0.0
:c 5.0
:d [0.0 5.0]
:e "123"
:f 5.0})
(me/humanize))))))

(deftest any-test
(testing "success"
Expand Down

0 comments on commit 0b69456

Please sign in to comment.