Skip to content

Commit

Permalink
fix: rename descendants function
Browse files Browse the repository at this point in the history
  • Loading branch information
erdos committed Oct 5, 2021
1 parent 353eaa6 commit d375ee7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/stencil/postprocess/list_ref.clj
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
(cond-> (:p flags) (-> (some-> (str " ")) (str (render-list-position bookmark parsed-ref))))))

;; lazy seq of all zippers in the subtree walked by preorder DFS graph traversal
(defn- descendants [tree]
(defn- locs-seq [tree]
(assert (zipper? tree))
(cons tree
((fn f [tree depth]
Expand All @@ -156,8 +156,8 @@
(assert (zipper? tree))
(assert (keyword? a))
(case prop
:tag (find-first (comp #{a} :tag zip/node) (descendants tree))
:attr (find-first (comp #{b} a :attrs zip/node) (descendants tree))))
:tag (find-first (comp #{a} :tag zip/node) (locs-seq tree))
:attr (find-first (comp #{b} a :attrs zip/node) (locs-seq tree))))

(defn- parse-num-pr [node]
(assert (= ooxml/num-pr (:tag node)))
Expand Down
10 changes: 5 additions & 5 deletions test/stencil/postprocess/list_ref_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[stencil.integration :as integration]))


(declare -find-elem -descendants)
(declare -find-elem -locs-seq)


;; make all private maps public!
Expand All @@ -16,18 +16,18 @@
(eval `(defn ~(symbol (str "-" k)) [~'& args#] (apply (deref ~v) args#)))))


(deftest test-descendants
(deftest test-locs-seq
(let [tree (xml-zip {:tag :0
:content [{:tag :a :content [{:tag :b}
{:tag :c :content [{:tag :d}]}
{:tag :e}]}]})]
(testing "siblings are not returned"
(is (= [{:tag :b}]
(->> tree zip/down zip/down -descendants (map zip/node)))))
(->> tree zip/down zip/down -locs-seq (map zip/node)))))
(is (= [:a :b :c :d :e]
(map (comp :tag zip/node) (-descendants (zip/down tree)))))
(map (comp :tag zip/node) (-locs-seq (zip/down tree)))))
(is (= [1 2 3 4]
(map zip/node (next (-descendants (xml-zip {:tag :0 :content [1 2 3 4]}))))))))
(map zip/node (next (-locs-seq (xml-zip {:tag :0 :content [1 2 3 4]}))))))))


(deftest test-find-elem
Expand Down

0 comments on commit d375ee7

Please sign in to comment.