Skip to content

Commit

Permalink
Add zen.walk/sch-seq scalar value
Browse files Browse the repository at this point in the history
Co-authored-by: @islambegkatibov <[email protected]>
  • Loading branch information
KGOH and katibov committed Sep 12, 2022
1 parent cf1fd4b commit 19e6508
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/zen/changes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@


(defn index-sch-seq [sch-seq]
(reduce (fn [acc {:keys [path], [attr value] :value}]
(assoc acc [path attr] {:path path, :attr attr :value value}))
(reduce (fn [acc {:keys [path], value :value}]
(let [attr (last path)]
(assoc acc [path attr] {:path path, :attr attr :value value})))
{}
sch-seq))

Expand Down
6 changes: 3 additions & 3 deletions src/zen/walk.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
(fn [node-map]
(->> (:node node-map)
(remove nested-schema-entry?)
(map (fn [entry]
{:path (:path node-map)
:value entry}))))]
(map (fn [[k v]]
{:path (conj (:path node-map) k)
:value v}))))]

(->> {:path [], :node sch}
(tree-seq contains-nested-schemas? get-nested-schemas)
Expand Down
32 changes: 16 additions & 16 deletions test/zen/walk_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[matcho.core :as matcho]))


(t/deftest ^:kaocha/pending sch-seq-test
(t/deftest sch-seq-test
(t/testing "any dsl traversing"
(def ztx (zen.core/new-context))

Expand All @@ -18,27 +18,27 @@
:zen/desc "2"
:keys {:a {:type zen/string
:zen/desc "3"}
:b {:type zen4/vector
:b {:type zen/vector
:zen/desc "4"
:every {:type zen/map
:zen/desc "5"
:keys {:c {:zen/desc "6"
:type zen/any}}}}}})
[{:path [nil], :value [:zen/tags #{'zen/schema}]} #_"NOTE: zen itself, not schema. move? Same for :zen/desc"
{:path [nil], :value [:type]}
{:path [nil], :value [:confirms]}
{:path [nil], :value [:zen/desc]}
{:path [:keys :a nil], :value [:type]}
{:path [:keys :a nil], :value [:zen/desc]}
{:path [:keys :b nil], :value [:type]}
{:path [:keys :b nil], :value [:zen/desc]}
{:path [:keys :b :every nil], :value [:type]}
{:path [:keys :b :every nil], :value [:zen/desc]}
{:path [:keys :b :every :keys :c nil], :value [:zen/desc]}
{:path [:keys :b :every :keys :c nil], :value [:type]}
[{:path [:zen/tags nil], :value #{'zen/schema}} #_"NOTE: zen itself, not schema. move? Same for :zen/desc"
{:path [:type nil], :value 'zen/map}
{:path [:confirms nil], :value #{'foo}}
{:path [:zen/desc nil], :value "2"}
{:path [:keys :a :type nil], :value 'zen/string}
{:path [:keys :a :zen/desc nil], :value "3"}
{:path [:keys :b :type nil], :value 'zen/vector}
{:path [:keys :b :zen/desc nil], :value "4"}
{:path [:keys :b :every :type nil], :value 'zen/map}
{:path [:keys :b :every :zen/desc nil], :value "5"}
{:path [:keys :b :every :keys :c :zen/desc nil], :value "6"}
{:path [:keys :b :every :keys :c :type nil], :value 'zen/any}
nil])

(matcho/match
#_(matcho/match
(sut/zen-dsl-seq
ztx
'{:zen/tags #{api}
Expand All @@ -49,7 +49,7 @@
{:path [[:id] :GET nil], :value ['read nil]}
nil])

(matcho/match
#_(matcho/match
(sut/zen-dsl-seq
ztx
'{:zen/tags #{rpc}
Expand Down

0 comments on commit 19e6508

Please sign in to comment.