File tree Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 872872 (let [unparsers (into {} (map (fn [[k _ c]] [k (-unparser c)])) (-children this))]
873873 (fn [x]
874874 (if (miu/-tagged? x)
875- (if-some [unparse (get unparsers (key x))]
876- (unparse (val x))
875+ (if-some [unparse (get unparsers (first x))]
876+ (unparse (second x))
877877 ::invalid )
878878 ::invalid ))))
879879 (-transformer [this transformer method options]
16501650 (fn [x] (if-some [parser (find (dispatch x))] (parser x) ::invalid ))))
16511651 (-unparser [_]
16521652 (let [unparsers (reduce-kv (fn [acc k s] (assoc acc k (-unparser s))) {} @dispatch-map)]
1653- (fn [x] (if (miu/-tagged? x) (if-some [f (unparsers (key x))] (f (val x)) ::invalid ) ::invalid ))))
1653+ (fn [x] (if (miu/-tagged? x) (if-some [f (unparsers (first x))] (f (second x)) ::invalid ) ::invalid ))))
16541654 (-transformer [this transformer method options]
16551655 ; ; FIXME: Probably should not use `dispatch`
16561656 ; ; Can't use `dispatch` as `x` might not be valid before it has been unparsed:
Original file line number Diff line number Diff line change 66(def ^:const +max-size+ #? (:clj Long/MAX_VALUE, :cljs (.-MAX_VALUE js/Number)))
77
88(defn -tagged [k v] #? (:clj (MapEntry. k v), :cljs (MapEntry. k v nil )))
9- (defn -tagged? [v] (instance? MapEntry v))
9+ (defn -tagged? [v] (or ( instance? MapEntry v) ( and ( vector? v) ( = 2 ( count v))) ))
1010
1111(defn -invalid? [x] #? (:clj (identical? x :malli.core/invalid ), :cljs (keyword-identical? x :malli.core/invalid )))
1212(defn -map-valid [f v] (if (-invalid? v) v (f v)))
Original file line number Diff line number Diff line change 257257 (is (= (miu/-tagged :pos 1 ) (m/parse schema* 1 )))
258258 (is (= ::m/invalid (m/parse schema* 0 )))
259259 (is (= 1 (m/unparse schema* (miu/-tagged :pos 1 ))))
260+ (is (= 1 (m/unparse schema* [:pos 1 ])))
260261 (is (= ::m/invalid (m/unparse schema* (miu/-tagged :pos 0 ))))
262+ (is (= ::m/invalid (m/unparse schema* [:pos 0 ])))
261263
262264 (doseq [schema [schema schema*]]
263265 (testing (m/form schema)
11511153 (is (= ::m/invalid (m/parse schema invalid5)))
11521154 (is (= ::m/invalid (m/parse schema invalid6)))
11531155 (is (= valid1 (m/unparse schema (m/parse schema valid1))))
1156+ (is (= valid1 (m/unparse schema [:sized valid1])))
11541157 (is (= valid2 (m/unparse schema (m/parse schema valid2))))
1158+ (is (= valid2 (m/unparse schema [:human valid2])))
11551159 (is (= valid3 (m/unparse schema (m/parse schema valid3))))
1160+ (is (= valid3 (m/unparse schema [:sized valid3])))
11561161 (is (= ::m/invalid (m/unparse schema invalid1)))
11571162 (is (= ::m/invalid (m/unparse schema invalid2)))
11581163 (is (= ::m/invalid (m/unparse schema invalid3)))
You can’t perform that action at this time.
0 commit comments