Skip to content

Commit ac55ec5

Browse files
author
Yannick Scherer
committed
fix assoc on empty map. (closes #16).
1 parent b064511 commit ac55ec5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/rewrite_clj/zip/edit.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
(defn append-child
4444
"Append item as child of the current location. Will insert a space if necessary."
4545
[zloc item]
46-
(let [r (-> zloc z/down z/rightmost)
46+
(let [r' (z/down zloc)
47+
r (when r' (z/rightmost r'))
4748
item (conv/->tree item)]
4849
(if (or (not r) (not (z/node r)) (zc/whitespace? r))
4950
(-> zloc (z/append-child item))

test/rewrite_clj/zip_test.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@
218218
(-> root (z/assoc 2 5) z/sexpr) => #{1 2 5}
219219
(-> root (z/assoc 5 8) z/sexpr) => (throws IndexOutOfBoundsException)
220220
(->> root (z/map #(z/edit % inc)) z/sexpr) => #{2 3 4})
221+
(let [root (z/of-string "{}")]
222+
root => z/seq?
223+
root => z/map?
224+
(z/sexpr root) => {}
225+
(-> root (z/assoc :a 5) z/sexpr) => {:a 5})
221226
(let [root (z/of-string "{:a 1 :b 2}")]
222227
root => z/seq?
223228
root => z/map?

0 commit comments

Comments
 (0)