From 08c196e39daa00ee22d100e43f722d183cc1e01a Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Fri, 9 Nov 2018 22:55:00 +0200 Subject: [PATCH] Fix records with inserts --- src/lambdaisland/deep_diff/diff.clj | 4 ++-- test/lambdaisland/deep_diff/diff_test.clj | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lambdaisland/deep_diff/diff.clj b/src/lambdaisland/deep_diff/diff.clj index 8e78a89..6ecda91 100644 --- a/src/lambdaisland/deep_diff/diff.clj +++ b/src/lambdaisland/deep_diff/diff.clj @@ -119,10 +119,10 @@ (assoc k (diff (get exp k) (get act k))) (contains? ins idx) - (into (map (juxt ->Insertion act)) (get ins idx))) + (into (map (juxt ->Insertion (partial get act))) (get ins idx))) (inc idx)]) [(if (contains? ins -1) - (into {} (map (juxt ->Insertion act)) (get ins -1)) + (into {} (map (juxt ->Insertion (partial get act))) (get ins -1)) {}) 0] exp-ks)))) diff --git a/test/lambdaisland/deep_diff/diff_test.clj b/test/lambdaisland/deep_diff/diff_test.clj index 4506f6e..aa7213c 100644 --- a/test/lambdaisland/deep_diff/diff_test.clj +++ b/test/lambdaisland/deep_diff/diff_test.clj @@ -14,7 +14,7 @@ #'diff/del+ins]] (alter-meta! v dissoc :private)) -(defrecord ARecord [a]) +(defrecord ARecord []) (deftest diff-test (testing "diffing atoms" @@ -102,7 +102,9 @@ (testing "records" (is (= {:a (diff/->Mismatch 1 2)} - (diff/diff (->ARecord 1) (->ARecord 2)))))) + (diff/diff (map->ARecord {:a 1}) (map->ARecord {:a 2})))) + (is (= {(diff/->Insertion :a) 1} + (diff/diff (map->ARecord {}) (map->ARecord {:a 1})))))) (is (= [{:x (diff/->Mismatch 1 2)}] (diff/diff [{:x 1}] [{:x 2}])))