Skip to content

Commit

Permalink
Modify -form of pattern-map-schema (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
skydread1 authored Jul 17, 2023
1 parent e257f76 commit f9b9117
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/sg/flybot/pullable/schema.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
(try-val :int [:default :ok]) ;=>> (complement nil?)
(try-val [:=> [:cat :int] :string] [:with [3]]) ;=> nil
(try-val [:=> [:cat] :string] [:with []]) ;=> nil
(try-val [:=> [:cat [:map [:a :int]]] :string] [:with [{}]]) ;=>> (complement nil?)
)

(defn- mark-ptn
Expand All @@ -100,7 +101,7 @@
[schema path o in acc]
(if (seq o)
[(cond-> schema (= :=> (m/type schema)) (-> m/children second))
((m/-explainer (m/schema (options-of schema)) path) o in acc)]
((m/-explainer (m/schema (options-of (m/form schema))) path) o in acc)]
[schema acc]))

(defn- pattern-explainer
Expand Down Expand Up @@ -161,7 +162,7 @@
(-options [_] (m/-options map-schema))
(-children [_] (m/-entry-children entry-parser))
(-parent [_] parent)
(-form [_] [:pattern-map (m/-form map-schema)])
(-form [_] (m/-form map-schema))
m/EntrySchema
(-entries [_] (m/-entry-entries entry-parser))
(-entry-parser [_] entry-parser)
Expand Down Expand Up @@ -287,14 +288,19 @@
;;batch result testing
(m/explain ptn-schema5 '{(:a :batch [[3] [2]]) {(:b :not-found "ok") ?}}) ;=> nil

(def ptn-schema6
;;for with pattern, its input type will be checked
(def ptn-schema6 (pattern-schema-of [:map [:a [:=> [:cat [:map [:b1 :int]]] :string]]]))
(m/explain ptn-schema6 '{(:a :with [{}]) ?}) ;=>> {:errors #(= 1 (count %))}

(def ptn-schema7
(pattern-schema-of
[:sequential
[:map
[:name :string]
[:op [:=> [:cat :int] :int]]]]))
(m/explain ptn-schema6 '[{:name "squre" (:op :with [3]) ?}]) ;=> nil
)
(m/explain ptn-schema7 '[{:name "squre" (:op :with [3]) ?}])
) ;=> nil


(defn check-pattern!
"check `pattern` against `data-schema`, if not conform throwing an ExceptionInfo
Expand Down

0 comments on commit f9b9117

Please sign in to comment.