From 5be3369e1f67eb2f37a485872de4fe60a352e87a Mon Sep 17 00:00:00 2001
From: Ed Bowler <ed.bowler@gmail.com>
Date: Fri, 4 May 2012 17:48:29 +0100
Subject: [PATCH] fixed rename-keys to not delete entries when there is a
 collision

---
 src/clj/clojure/set.clj                   |    7 +++----
 test/clojure/test_clojure/clojure_set.clj |    5 +++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/clj/clojure/set.clj b/src/clj/clojure/set.clj
index 69233ad..5d43b5c 100644
--- a/src/clj/clojure/set.clj
+++ b/src/clj/clojure/set.clj
@@ -80,11 +80,10 @@
   [map kmap]
     (reduce 
      (fn [m [old new]]
-       (if (and (not= old new)
-                (contains? m old))
-         (-> m (assoc new (get m old)) (dissoc old))
+       (if (contains? map old)
+         (assoc m new (get map old))
          m)) 
-     map kmap))
+     (apply dissoc map (keys kmap)) kmap))
 
 (defn rename
   "Returns a rel of the maps in xrel with the keys in kmap renamed to the vals in kmap"
diff --git a/test/clojure/test_clojure/clojure_set.clj b/test/clojure/test_clojure/clojure_set.clj
index 8d511af..61a36b9 100644
--- a/test/clojure/test_clojure/clojure_set.clj
+++ b/test/clojure/test_clojure/clojure_set.clj
@@ -162,8 +162,9 @@
 
 (deftest test-rename-keys
   (are [x y] (= x y)
-    (set/rename-keys {:a "one" :b "two"} {:a :z}) {:z "one" :b "two"}
-    ))
+       (set/rename-keys {:a "one" :b "two"} {:a :z}) {:z "one" :b "two"}
+       (set/rename-keys {:a "one" :b "two"} {:a :z :c :y}) {:z "one" :b "two"}
+       (set/rename-keys {:a "one" :b "two" :c "three"} {:a :b :b :a}) {:a "two" :b "one" :c "three"}))
 
 (deftest test-index
   (are [x y] (= x y)
-- 
1.7.7.6

