Skip to content

Commit

Permalink
Merge pull request #877 from metosin/874
Browse files Browse the repository at this point in the history
fix #874
  • Loading branch information
ikitommi authored Mar 18, 2023
2 parents 8bdd7f5 + eb30b2d commit 0395d5c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 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).
* `m/explicit-keys` to get a vector of explicit keys from entry schemas (no `::m/default`
* `mt/strip-extra-keys-transformer` works with `:map-of` schemas
* Simplify content-dependent schema creation with `m/-simple-schema` and `m/-collection-schema` via new 3-arity `:compile` function of type `children properties options -> props`. Old 2-arity top-level callback function is `m/deprecated!` and support for it will be removed in future versions. [#866](https://github.com/metosin/malli/pull/866)
* FIX Repeated calls to `malli.util/assoc-`in referencing non-existing maps fail [#874](https://github.com/metosin/malli/issues/874)

## 0.10.2 (2023-03-05)

Expand Down
3 changes: 1 addition & 2 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@
;; update
(-simple-entry-parser keyset (assoc children i c) (assoc forms i f))
;; assoc
(let [size (inc (count keyset))]
(-simple-entry-parser (assoc keyset k size) (conj children c) (conj forms f))))))))
(-simple-entry-parser (assoc keyset k {:order (count keyset)}) (conj children c) (conj forms f)))))))

(defn -set-entries
([schema ?key value]
Expand Down
44 changes: 27 additions & 17 deletions test/malli/util_test.cljc
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
(ns malli.util-test
(:require [clojure.test :refer [are deftest is testing]]
#?(:bb [cheshire.core :as json]
#?(:bb [cheshire.core :as json]
:clj [jsonista.core :as json])
[malli.core :as m]
[malli.impl.util :as miu]
[malli.registry :as mr]
[malli.util :as mu]))

#?(:clj (defn from-json [s]
#?(:bb (json/parse-string s)
#?(:bb (json/parse-string s)
:clj (json/read-value s))))

#?(:clj (defn to-json [x]
#?(:bb (json/generate-string x)
#?(:bb (json/generate-string x)
:clj (json/write-value-as-string x))))

(defn form= [& ?schemas]
Expand Down Expand Up @@ -535,13 +535,13 @@
:c "a string"}))))))

(deftest transform-entries-test
(let [registry (mr/composite-registry {:a/x int?} (m/default-schemas))
options {:registry registry}
(let [registry (mr/composite-registry {:a/x int?} (m/default-schemas))
options {:registry registry}
key->key-transform #(map (fn [[k m _]] [k m k]) %)

schema [:map [:a/x {:m true} int?]]
schema [:map [:a/x {:m true} int?]]
schema-with-options (m/schema schema options)
result-schema (m/schema [:map [:a/x {:m true} :a/x]] options)]
result-schema (m/schema [:map [:a/x {:m true} :a/x]] options)]

(testing "manual options are preserved in output type from the transform"
(is (mu/equals
Expand Down Expand Up @@ -1013,27 +1013,27 @@
ff (conj f -f)
tt (conj t -t)]
(testing "every pred behaves like and: one false => result is false"
(is (true? ((miu/-every-pred [-t]) nil)))
(is (true? ((miu/-every-pred [-t]) nil)))
(is (false? ((miu/-every-pred [-f]) nil)))
(is (true? ((miu/-every-pred t) nil)))
(is (true? ((miu/-every-pred t) nil)))
(is (false? ((miu/-every-pred f) nil)))
(is (false? ((miu/-every-pred t+f) nil)))
(is (false? ((miu/-every-pred f+t) nil)))
(is (false? ((miu/-every-pred tf) nil)))
(is (false? ((miu/-every-pred ft) nil)))
(is (false? ((miu/-every-pred ff) nil)))
(is (true? ((miu/-every-pred tt) nil))))
(is (true? ((miu/-every-pred tt) nil))))
(testing "some pred behaves like or: one true => result is true"
(is (true? ((miu/-some-pred [-t]) nil)))
(is (true? ((miu/-some-pred [-t]) nil)))
(is (false? ((miu/-some-pred [-f]) nil)))
(is (true? ((miu/-some-pred t) nil)))
(is (true? ((miu/-some-pred t) nil)))
(is (false? ((miu/-some-pred f) nil)))
(is (true? ((miu/-some-pred t+f) nil)))
(is (true? ((miu/-some-pred f+t) nil)))
(is (true? ((miu/-some-pred tf) nil)))
(is (true? ((miu/-some-pred ft) nil)))
(is (true? ((miu/-some-pred t+f) nil)))
(is (true? ((miu/-some-pred f+t) nil)))
(is (true? ((miu/-some-pred tf) nil)))
(is (true? ((miu/-some-pred ft) nil)))
(is (false? ((miu/-some-pred ff) nil)))
(is (true? ((miu/-some-pred tt) nil)))))))
(is (true? ((miu/-some-pred tt) nil)))))))

(deftest explain-data-test
(let [schema (m/schema [:map [:a [:vector [:maybe :string]]]])
Expand Down Expand Up @@ -1074,3 +1074,13 @@
"schema" ["map" ["a" ["vector" ["maybe" "string"]]]]
"value" {"a" [true]}}
(from-json (to-json (mu/explain-data schema input-2)))))))))

(deftest test-874
(is (form= [:map {:closed true}
[:foo [:map {:closed true}
[:bar :int]
[:baz :int]]]]
(-> [:map]
(mu/assoc-in [:foo :bar] :int)
(mu/assoc-in [:foo :baz] :int)
(mu/closed-schema)))))

0 comments on commit 0395d5c

Please sign in to comment.