From 19e6508e796b5c2c2d979bc12650b358a66aa5c7 Mon Sep 17 00:00:00 2001 From: KGOH Date: Mon, 12 Sep 2022 09:42:25 +0200 Subject: [PATCH] Add zen.walk/sch-seq scalar value Co-authored-by: @islambegkatibov <79331750+islambegk@users.noreply.github.com> --- src/zen/changes.clj | 5 +++-- src/zen/walk.clj | 6 +++--- test/zen/walk_test.clj | 32 ++++++++++++++++---------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/zen/changes.clj b/src/zen/changes.clj index 1f2ddf7..824b0c0 100644 --- a/src/zen/changes.clj +++ b/src/zen/changes.clj @@ -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)) diff --git a/src/zen/walk.clj b/src/zen/walk.clj index d6466b9..a668580 100644 --- a/src/zen/walk.clj +++ b/src/zen/walk.clj @@ -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) diff --git a/test/zen/walk_test.clj b/test/zen/walk_test.clj index 946cccf..c000b18 100644 --- a/test/zen/walk_test.clj +++ b/test/zen/walk_test.clj @@ -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)) @@ -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} @@ -49,7 +49,7 @@ {:path [[:id] :GET nil], :value ['read nil]} nil]) - (matcho/match + #_(matcho/match (sut/zen-dsl-seq ztx '{:zen/tags #{rpc}