-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #566 from bhagany/nested-diff
Correctly diff nested data structures
- Loading branch information
Showing
3 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
(ns boot.tmpdir-test | ||
(:refer-clojure :exclude [hash time]) | ||
(:require | ||
[clojure.test :refer :all] | ||
[boot.tmpdir :as tmpd])) | ||
|
||
(defn has-path? [fs path] | ||
(contains? (:tree fs) path)) | ||
|
||
(deftest diff*-scalar-test | ||
(let [before (tmpd/map->TmpFileSet {:tree {}}) | ||
after (tmpd/map->TmpFileSet {:tree {"path" {:adding true}}}) | ||
diff (#'tmpd/diff* before after [:adding])] | ||
(testing "Added" | ||
(is (has-path? (:added diff) "path")) | ||
(is (not (has-path? (:removed diff) "path"))) | ||
(is (not (has-path? (:changed diff) "path"))))) | ||
(let [before (tmpd/map->TmpFileSet {:tree {"path" {:removing true}}}) | ||
after (tmpd/map->TmpFileSet {:tree {}}) | ||
diff (#'tmpd/diff* before after [:removing])] | ||
(testing "Removed" | ||
(is (has-path? (:removed diff) "path")) | ||
(is (not (has-path? (:added diff) "path"))) | ||
(is (not (has-path? (:changed diff) "path"))))) | ||
(let [before (tmpd/map->TmpFileSet {:tree {"path" {:changing true}}}) | ||
after (tmpd/map->TmpFileSet {:tree {"path" {:changing false}}}) | ||
diff (#'tmpd/diff* before after [:changing])] | ||
(testing "Changed" | ||
(is (has-path? (:changed diff) "path")) | ||
(is (not (has-path? (:added diff) "path"))) | ||
(is (not (has-path? (:removed diff) "path")))))) | ||
|
||
(deftest diff*-nested-test | ||
(let [before (tmpd/map->TmpFileSet {:tree {}}) | ||
after (tmpd/map->TmpFileSet {:tree {"path" {:nested {:adding true}}}}) | ||
diff (#'tmpd/diff* before after [:nested])] | ||
(testing "Added" | ||
(is (has-path? (:added diff) "path")) | ||
(is (not (has-path? (:removed diff) "path"))) | ||
(is (not (has-path? (:changed diff) "path"))))) | ||
(let [before (tmpd/map->TmpFileSet {:tree {"path" {:nested {:removing true}}}}) | ||
after (tmpd/map->TmpFileSet {:tree {}}) | ||
diff (#'tmpd/diff* before after [:nested])] | ||
(testing "Removed" | ||
(is (has-path? (:removed diff) "path")) | ||
(is (not (has-path? (:added diff) "path"))) | ||
(is (not (has-path? (:changed diff) "path"))))) | ||
(let [before (tmpd/map->TmpFileSet {:tree {"path" {:nested {:changing true}}}}) | ||
after (tmpd/map->TmpFileSet {:tree {"path" {:nested {:changing false}}}}) | ||
diff (#'tmpd/diff* before after [:nested])] | ||
(testing "Changed (simple)" | ||
(is (has-path? (:changed diff) "path")) | ||
(is (not (has-path? (:added diff) "path"))) | ||
(is (not (has-path? (:removed diff) "path"))))) | ||
(let [before (tmpd/map->TmpFileSet {:tree {"path" {:nested {:staying true :changing true}}}}) | ||
after (tmpd/map->TmpFileSet {:tree {"path" {:nested {:staying true :changing false}}}}) | ||
diff (#'tmpd/diff* before after [:nested])] | ||
(testing "Changed (complex)" | ||
(is (has-path? (:changed diff) "path")) | ||
(is (not (has-path? (:added diff) "path"))) | ||
(is (not (has-path? (:removed diff) "path")))))) | ||
|
||
(deftest diff*-edge-test | ||
(let [before {} | ||
after {} | ||
diff (#'tmpd/diff* before after [:hash :time]) | ||
empty-fs {:tree {}}] | ||
(testing "Empty dicts" | ||
(is (= empty-fs (:added diff))) | ||
(is (= empty-fs (:removed diff))) | ||
(is (= empty-fs (:changed diff))))) | ||
(let [before nil | ||
after nil | ||
diff (#'tmpd/diff* before after [:hash :time]) | ||
empty-fs {:tree {}}] | ||
(testing "Nil" | ||
(is (= empty-fs (:added diff))) | ||
(is (= empty-fs (:removed diff))) | ||
(is (= empty-fs (:changed diff)))))) |